|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | +package org.apache.hadoop.hbase; |
| 19 | + |
| 20 | +import static org.junit.Assert.assertEquals; |
| 21 | + |
| 22 | +import java.util.List; |
| 23 | +import java.util.Map; |
| 24 | +import java.util.concurrent.TimeUnit; |
| 25 | +import org.apache.hadoop.conf.Configuration; |
| 26 | +import org.apache.hadoop.hbase.client.AsyncAdmin; |
| 27 | +import org.apache.hadoop.hbase.client.RegionInfo; |
| 28 | +import org.apache.hadoop.hbase.quotas.QuotaTableUtil; |
| 29 | +import org.apache.hadoop.hbase.quotas.QuotaUtil; |
| 30 | +import org.apache.hadoop.hbase.testclassification.LargeTests; |
| 31 | +import org.apache.hadoop.hbase.testclassification.MiscTests; |
| 32 | +import org.apache.hadoop.hbase.util.Bytes; |
| 33 | +import org.junit.ClassRule; |
| 34 | +import org.junit.Rule; |
| 35 | +import org.junit.Test; |
| 36 | +import org.junit.experimental.categories.Category; |
| 37 | +import org.junit.runner.RunWith; |
| 38 | +import org.junit.runners.Parameterized; |
| 39 | +import org.slf4j.Logger; |
| 40 | +import org.slf4j.LoggerFactory; |
| 41 | + |
| 42 | +/** |
| 43 | + * Test that we can split and merge select system tables given the presence of various configuration |
| 44 | + * settings. |
| 45 | + */ |
| 46 | +@Category({ MiscTests.class, LargeTests.class }) |
| 47 | +@RunWith(Parameterized.class) |
| 48 | +public class TestSplitMergeSystemTables { |
| 49 | + |
| 50 | + private static final Logger LOG = LoggerFactory.getLogger(TestSplitMergeSystemTables.class); |
| 51 | + |
| 52 | + @ClassRule |
| 53 | + public static final HBaseClassTestRule CLASS_RULE = |
| 54 | + HBaseClassTestRule.forClass(TestSplitMergeSystemTables.class); |
| 55 | + |
| 56 | + @Parameterized.Parameters(name = "{0}: {1}") |
| 57 | + public static Object[][] params() { |
| 58 | + return new Object[][] { |
| 59 | + // quotas table is only created when the quota system is enabled. |
| 60 | + { QuotaTableUtil.QUOTA_TABLE_NAME, Map.of(QuotaUtil.QUOTA_CONF_KEY, "true") }, }; |
| 61 | + } |
| 62 | + |
| 63 | + private final TableName tableName; |
| 64 | + |
| 65 | + @Rule |
| 66 | + public final MiniClusterRule miniClusterRule; |
| 67 | + |
| 68 | + public TestSplitMergeSystemTables(TableName tableName, Map<String, String> configMap) { |
| 69 | + this.tableName = tableName; |
| 70 | + this.miniClusterRule = MiniClusterRule.newBuilder().setConfiguration(() -> { |
| 71 | + Configuration conf = HBaseConfiguration.create(); |
| 72 | + conf.setInt(HConstants.HBASE_CLIENT_META_OPERATION_TIMEOUT, 1000); |
| 73 | + conf.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 2); |
| 74 | + configMap.forEach(conf::set); |
| 75 | + return conf; |
| 76 | + }).build(); |
| 77 | + |
| 78 | + } |
| 79 | + |
| 80 | + @Test |
| 81 | + public void testSplitMergeSystemTable() throws Exception { |
| 82 | + HBaseTestingUtil util = miniClusterRule.getTestingUtility(); |
| 83 | + util.waitTableAvailable(tableName, 30_000); |
| 84 | + AsyncAdmin admin = util.getAsyncConnection().getAdmin(); |
| 85 | + admin.split(tableName, Bytes.toBytes(0x10)).get(30, TimeUnit.SECONDS); |
| 86 | + util.waitFor(30_000, new Waiter.ExplainingPredicate<Exception>() { |
| 87 | + |
| 88 | + @Override |
| 89 | + public boolean evaluate() throws Exception { |
| 90 | + // can potentially observe the parent and both children via this interface. |
| 91 | + return admin.getRegions(tableName) |
| 92 | + .thenApply(val -> val.stream() |
| 93 | + .filter(info -> info.getReplicaId() == RegionInfo.DEFAULT_REPLICA_ID).toList()) |
| 94 | + .get(30, TimeUnit.SECONDS).size() > 1; |
| 95 | + } |
| 96 | + |
| 97 | + @Override |
| 98 | + public String explainFailure() { |
| 99 | + return "Split has not finished yet"; |
| 100 | + } |
| 101 | + }); |
| 102 | + util.waitUntilNoRegionsInTransition(); |
| 103 | + List<RegionInfo> regionInfos = admin.getRegions(tableName) |
| 104 | + .thenApply(val -> val.stream() |
| 105 | + .filter(info -> info.getReplicaId() == RegionInfo.DEFAULT_REPLICA_ID).toList()) |
| 106 | + .get(30, TimeUnit.SECONDS); |
| 107 | + assertEquals(2, regionInfos.size()); |
| 108 | + LOG.info("{}", regionInfos); |
| 109 | + admin.mergeRegions(regionInfos.stream().map(RegionInfo::getRegionName).toList(), false).get(30, |
| 110 | + TimeUnit.SECONDS); |
| 111 | + util.waitFor(30000, new Waiter.ExplainingPredicate<Exception>() { |
| 112 | + |
| 113 | + @Override |
| 114 | + public boolean evaluate() throws Exception { |
| 115 | + // can potentially observe the parent and both children via this interface. |
| 116 | + return admin.getRegions(tableName) |
| 117 | + .thenApply(val -> val.stream() |
| 118 | + .filter(info -> info.getReplicaId() == RegionInfo.DEFAULT_REPLICA_ID).toList()) |
| 119 | + .get(30, TimeUnit.SECONDS).size() == 1; |
| 120 | + } |
| 121 | + |
| 122 | + @Override |
| 123 | + public String explainFailure() { |
| 124 | + return "Merge has not finished yet"; |
| 125 | + } |
| 126 | + }); |
| 127 | + assertEquals(1, admin.getRegions(tableName).get(30, TimeUnit.SECONDS).size()); |
| 128 | + } |
| 129 | +} |
0 commit comments