From 8b64c3bd4df6af532577edb1f4989712c700b85f Mon Sep 17 00:00:00 2001 From: Jurriaan Mous Date: Mon, 22 Dec 2014 17:07:40 +0100 Subject: [PATCH] HBASE-12740 --- .../apache/hadoop/hbase/util/TestHBaseFsck.java | 322 ++++++++++----------- 1 file changed, 159 insertions(+), 163 deletions(-) diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestHBaseFsck.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestHBaseFsck.java index 30600c2..40f44a7 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestHBaseFsck.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestHBaseFsck.java @@ -77,7 +77,6 @@ import org.apache.hadoop.hbase.client.Durability; import org.apache.hadoop.hbase.client.Get; import org.apache.hadoop.hbase.client.HBaseAdmin; import org.apache.hadoop.hbase.client.HConnection; -import org.apache.hadoop.hbase.client.HConnectionManager; import org.apache.hadoop.hbase.client.HTable; import org.apache.hadoop.hbase.client.MetaScanner; import org.apache.hadoop.hbase.client.Put; @@ -131,7 +130,10 @@ public class TestHBaseFsck { private final static byte[] FAM = Bytes.toBytes(FAM_STR); private final static int REGION_ONLINE_TIMEOUT = 800; private static RegionStates regionStates; - private static ExecutorService executorService; + private static ExecutorService tableExecutorService; + private static ScheduledThreadPoolExecutor hbfsckExecutorService; + private static Connection connection; + private static Admin admin; // for the instance, reset every test run private HTable tbl; @@ -144,21 +146,33 @@ public class TestHBaseFsck { @BeforeClass public static void setUpBeforeClass() throws Exception { - TEST_UTIL.getConfiguration().setInt("hbase.regionserver.handler.count", 2); - TEST_UTIL.getConfiguration().setInt("hbase.regionserver.metahandler.count", 2); + conf.setInt("hbase.regionserver.handler.count", 2); + conf.setInt("hbase.regionserver.metahandler.count", 2); + conf.setInt("hbase.htable.threads.max", 7); + conf.setInt("hbase.hconnection.threads.max", 14); + conf.setInt("hbase.hconnection.threads.core", 7); TEST_UTIL.startMiniCluster(3); - executorService = new ThreadPoolExecutor(1, Integer.MAX_VALUE, 60, TimeUnit.SECONDS, + tableExecutorService = new ThreadPoolExecutor(1, 7, 60, TimeUnit.SECONDS, new SynchronousQueue(), Threads.newDaemonThreadFactory("testhbck")); + hbfsckExecutorService = new ScheduledThreadPoolExecutor(7); + AssignmentManager assignmentManager = TEST_UTIL.getHBaseCluster().getMaster().getAssignmentManager(); regionStates = assignmentManager.getRegionStates(); - TEST_UTIL.getHBaseAdmin().setBalancerRunning(false, true); + + connection = TEST_UTIL.getConnection(); + + admin = connection.getAdmin(); + admin.setBalancerRunning(false, true); } @AfterClass public static void tearDownAfterClass() throws Exception { + tableExecutorService.shutdown(); + hbfsckExecutorService.shutdown(); + admin.close(); TEST_UTIL.shutdownMiniCluster(); } @@ -173,8 +187,7 @@ public class TestHBaseFsck { // Now let's mess it up and change the assignment in hbase:meta to // point to a different region server - Table meta = new HTable(conf, TableName.META_TABLE_NAME, - executorService); + Table meta = connection.getTable(TableName.META_TABLE_NAME, tableExecutorService); Scan scan = new Scan(); scan.setStartRow(Bytes.toBytes(table+",,")); ResultScanner scanner = meta.getScanner(scan); @@ -218,7 +231,7 @@ public class TestHBaseFsck { assertNoErrors(doFsck(conf, false)); // comment needed - what is the purpose of this line - Table t = new HTable(conf, table, executorService); + Table t = connection.getTable(table, tableExecutorService); ResultScanner s = t.getScanner(new Scan()); s.close(); t.close(); @@ -230,11 +243,7 @@ public class TestHBaseFsck { @Test(timeout=180000) public void testFixAssignmentsWhenMETAinTransition() throws Exception { MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster(); - try (Connection connection = ConnectionFactory.createConnection(TEST_UTIL.getConfiguration())) { - try (Admin admin = connection.getAdmin()) { - admin.closeRegion(cluster.getServerHoldingMeta(), HRegionInfo.FIRST_META_REGIONINFO); - } - } + admin.closeRegion(cluster.getServerHoldingMeta(), HRegionInfo.FIRST_META_REGIONINFO); regionStates.regionOffline(HRegionInfo.FIRST_META_REGIONINFO); new MetaTableLocator().deleteMetaLocation(cluster.getMaster().getZooKeeper()); assertFalse(regionStates.isRegionOnline(HRegionInfo.FIRST_META_REGIONINFO)); @@ -247,10 +256,10 @@ public class TestHBaseFsck { /** * Create a new region in META. */ - private HRegionInfo createRegion(Configuration conf, final HTableDescriptor + private HRegionInfo createRegion(final HTableDescriptor htd, byte[] startKey, byte[] endKey) throws IOException { - Table meta = new HTable(conf, TableName.META_TABLE_NAME, executorService); + Table meta = connection.getTable(TableName.META_TABLE_NAME, tableExecutorService); HRegionInfo hri = new HRegionInfo(htd.getTableName(), startKey, endKey); MetaTableAccessor.addRegionToMeta(meta, hri); meta.close(); @@ -271,12 +280,12 @@ public class TestHBaseFsck { * This method is used to undeploy a region -- close it and attempt to * remove its state from the Master. */ - private void undeployRegion(HConnection conn, ServerName sn, + private void undeployRegion(Connection conn, ServerName sn, HRegionInfo hri) throws IOException, InterruptedException { try { - HBaseFsckRepair.closeRegionSilentlyAndWait(conn, sn, hri); + HBaseFsckRepair.closeRegionSilentlyAndWait((HConnection) conn, sn, hri); if (!hri.isMetaTable()) { - conn.getAdmin().offline(hri.getRegionName()); + admin.offline(hri.getRegionName()); } } catch (IOException ioe) { LOG.warn("Got exception when attempting to offline region " @@ -311,7 +320,6 @@ public class TestHBaseFsck { dumpMeta(htd.getTableName()); Map hris = tbl.getRegionLocations(); - HConnection conn = (HConnection) ConnectionFactory.createConnection(conf); for (Entry e: hris.entrySet()) { HRegionInfo hri = e.getKey(); ServerName hsa = e.getValue(); @@ -324,7 +332,7 @@ public class TestHBaseFsck { if (unassign) { LOG.info("Undeploying region " + hri + " from server " + hsa); - undeployRegion(conn, hsa, hri); + undeployRegion((HConnection) connection, hsa, hri); } if (regionInfoOnly) { @@ -350,7 +358,7 @@ public class TestHBaseFsck { } if (metaRow) { - try (Table meta = conn.getTable(TableName.META_TABLE_NAME, executorService)) { + try (Table meta = connection.getTable(TableName.META_TABLE_NAME, tableExecutorService)) { Delete delete = new Delete(deleteRow); meta.delete(delete); } @@ -362,7 +370,6 @@ public class TestHBaseFsck { TEST_UTIL.getMetaTableRows(htd.getTableName()); LOG.info("*** After delete:"); dumpMeta(htd.getTableName()); - conn.close(); } /** @@ -372,7 +379,7 @@ public class TestHBaseFsck { * @throws InterruptedException * @throws KeeperException */ - Table setupTable(TableName tablename) throws Exception { + HTable setupTable(TableName tablename) throws Exception { return setupTableWithRegionReplica(tablename, 1); } @@ -383,13 +390,13 @@ public class TestHBaseFsck { * @return * @throws Exception */ - Table setupTableWithRegionReplica(TableName tablename, int replicaCount) throws Exception { + HTable setupTableWithRegionReplica(TableName tablename, int replicaCount) throws Exception { HTableDescriptor desc = new HTableDescriptor(tablename); desc.setRegionReplication(replicaCount); HColumnDescriptor hcd = new HColumnDescriptor(Bytes.toString(FAM)); desc.addFamily(hcd); // If a table has no CF's it doesn't get checked - TEST_UTIL.getHBaseAdmin().createTable(desc, SPLITS); - tbl = (HTable)TEST_UTIL.getConnection().getTable(tablename, executorService); + admin.createTable(desc, SPLITS); + tbl = (HTable) connection.getTable(tablename, tableExecutorService); List puts = new ArrayList(); for (byte[] row : ROWKEYS) { Put p = new Put(row); @@ -421,9 +428,12 @@ public class TestHBaseFsck { * @throws IOException */ void deleteTable(TableName tablename) throws IOException { - HConnection conn = (HConnection) ConnectionFactory.createConnection(conf); - Admin admin = conn.getAdmin(); - conn.clearRegionCache(); + if (tbl != null) { + tbl.close(); + tbl = null; + } + + ((HConnection) connection).clearRegionCache(); if (admin.isTableEnabled(tablename)) { admin.disableTableAsync(tablename); } @@ -443,8 +453,6 @@ public class TestHBaseFsck { } } admin.deleteTable(tablename); - admin.close(); - conn.close(); } /** @@ -500,7 +508,6 @@ public class TestHBaseFsck { Path tableinfo = null; try { setupTable(table); - Admin admin = TEST_UTIL.getHBaseAdmin(); Path hbaseTableDir = FSUtils.getTableDir( FSUtils.getRootDir(conf), table); @@ -600,8 +607,8 @@ public class TestHBaseFsck { assertEquals(ROWKEYS.length, countRows()); // Now let's mess it up, by adding a region with a duplicate startkey - HRegionInfo hriDupe = createRegion(conf, tbl.getTableDescriptor(), - Bytes.toBytes("A"), Bytes.toBytes("A2")); + HRegionInfo hriDupe = + createRegion(tbl.getTableDescriptor(), Bytes.toBytes("A"), Bytes.toBytes("A2")); TEST_UTIL.getHBaseCluster().getMaster().assignRegion(hriDupe); TEST_UTIL.getHBaseCluster().getMaster().getAssignmentManager() .waitForAssignment(hriDupe); @@ -637,7 +644,7 @@ public class TestHBaseFsck { TableName.valueOf("testHbckWithRegionReplica"); try { setupTableWithRegionReplica(table, 2); - TEST_UTIL.getHBaseAdmin().flush(table); + admin.flush(table); assertNoErrors(doFsck(conf, false)); } finally { deleteTable(table); @@ -650,7 +657,7 @@ public class TestHBaseFsck { TableName.valueOf("testHbckWithFewerReplica"); try { setupTableWithRegionReplica(table, 2); - TEST_UTIL.getHBaseAdmin().flush(table); + admin.flush(table); assertNoErrors(doFsck(conf, false)); assertEquals(ROWKEYS.length, countRows()); deleteRegion(conf, tbl.getTableDescriptor(), Bytes.toBytes("B"), @@ -674,15 +681,15 @@ public class TestHBaseFsck { TableName.valueOf("testHbckWithExcessReplica"); try { setupTableWithRegionReplica(table, 2); - TEST_UTIL.getHBaseAdmin().flush(table); + admin.flush(table); assertNoErrors(doFsck(conf, false)); assertEquals(ROWKEYS.length, countRows()); // the next few lines inject a location in meta for a replica, and then // asks the master to assign the replica (the meta needs to be injected // for the master to treat the request for assignment as valid; the master // checks the region is valid either from its memory or meta) - Table meta = new HTable(conf, TableName.META_TABLE_NAME); - List regions = TEST_UTIL.getHBaseAdmin().getTableRegions(table); + Table meta = connection.getTable(TableName.META_TABLE_NAME, tableExecutorService); + List regions = admin.getTableRegions(table); byte[] startKey = Bytes.toBytes("B"); byte[] endKey = Bytes.toBytes("C"); byte[] metaKey = null; @@ -698,15 +705,15 @@ public class TestHBaseFsck { } } Put put = new Put(metaKey); - Collection var = TEST_UTIL.getHBaseAdmin().getClusterStatus().getServers(); + Collection var = admin.getClusterStatus().getServers(); ServerName sn = var.toArray(new ServerName[var.size()])[0]; //add a location with replicaId as 2 (since we already have replicas with replicaid 0 and 1) MetaTableAccessor.addLocation(put, sn, sn.getStartcode(), 2); meta.put(put); meta.flushCommits(); // assign the new replica - HBaseFsckRepair.fixUnassigned(TEST_UTIL.getHBaseAdmin(), newHri); - HBaseFsckRepair.waitUntilAssigned(TEST_UTIL.getHBaseAdmin(), newHri); + HBaseFsckRepair.fixUnassigned(admin, newHri); + HBaseFsckRepair.waitUntilAssigned(admin, newHri); // now reset the meta row to its original value Delete delete = new Delete(metaKey); delete.deleteColumns(HConstants.CATALOG_FAMILY, MetaTableAccessor.getServerColumn(2)); @@ -735,9 +742,8 @@ public class TestHBaseFsck { Collection regionServers = status.getServers(); Map> mm = new HashMap>(); - HConnection connection = admin.getConnection(); for (ServerName hsi : regionServers) { - AdminProtos.AdminService.BlockingInterface server = connection.getAdmin(hsi); + AdminProtos.AdminService.BlockingInterface server = ((HConnection) connection).getAdmin(hsi); // list all online regions from this region server List regions = ProtobufUtil.getOnlineRegions(server); @@ -776,8 +782,8 @@ public class TestHBaseFsck { assertEquals(ROWKEYS.length, countRows()); // Now let's mess it up, by adding a region with a duplicate startkey - HRegionInfo hriDupe = createRegion(conf, tbl.getTableDescriptor(), - Bytes.toBytes("A"), Bytes.toBytes("B")); + HRegionInfo hriDupe = + createRegion(tbl.getTableDescriptor(), Bytes.toBytes("A"), Bytes.toBytes("B")); TEST_UTIL.getHBaseCluster().getMaster().assignRegion(hriDupe); TEST_UTIL.getHBaseCluster().getMaster().getAssignmentManager() @@ -789,8 +795,7 @@ public class TestHBaseFsck { // different regions with the same start/endkeys since it doesn't // differentiate on ts/regionId! We actually need to recheck // deployments! - HBaseAdmin admin = TEST_UTIL.getHBaseAdmin(); - while (findDeployedHSI(getDeployedHRIs(admin), hriDupe) == null) { + while (findDeployedHSI(getDeployedHRIs((HBaseAdmin) admin), hriDupe) == null) { Thread.sleep(250); } @@ -828,8 +833,8 @@ public class TestHBaseFsck { assertEquals(ROWKEYS.length, countRows()); // Now let's mess it up, by adding a region with a duplicate startkey - HRegionInfo hriDupe = createRegion(conf, tbl.getTableDescriptor(), - Bytes.toBytes("B"), Bytes.toBytes("B")); + HRegionInfo hriDupe = + createRegion(tbl.getTableDescriptor(), Bytes.toBytes("B"), Bytes.toBytes("B")); TEST_UTIL.getHBaseCluster().getMaster().assignRegion(hriDupe); TEST_UTIL.getHBaseCluster().getMaster().getAssignmentManager() .waitForAssignment(hriDupe); @@ -868,8 +873,8 @@ public class TestHBaseFsck { assertEquals(ROWKEYS.length, countRows()); // Mess it up by creating an overlap in the metadata - HRegionInfo hriOverlap = createRegion(conf, tbl.getTableDescriptor(), - Bytes.toBytes("A2"), Bytes.toBytes("B")); + HRegionInfo hriOverlap = + createRegion(tbl.getTableDescriptor(), Bytes.toBytes("A2"), Bytes.toBytes("B")); TEST_UTIL.getHBaseCluster().getMaster().assignRegion(hriOverlap); TEST_UTIL.getHBaseCluster().getMaster().getAssignmentManager() .waitForAssignment(hriOverlap); @@ -905,19 +910,19 @@ public class TestHBaseFsck { public void testSidelineOverlapRegion() throws Exception { TableName table = TableName.valueOf("testSidelineOverlapRegion"); - try (HConnection conn = (HConnection) ConnectionFactory.createConnection(conf)){ + try { setupTable(table); assertEquals(ROWKEYS.length, countRows()); // Mess it up by creating an overlap MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster(); HMaster master = cluster.getMaster(); - HRegionInfo hriOverlap1 = createRegion(conf, tbl.getTableDescriptor(), - Bytes.toBytes("A"), Bytes.toBytes("AB")); + HRegionInfo hriOverlap1 = + createRegion(tbl.getTableDescriptor(), Bytes.toBytes("A"), Bytes.toBytes("AB")); master.assignRegion(hriOverlap1); master.getAssignmentManager().waitForAssignment(hriOverlap1); - HRegionInfo hriOverlap2 = createRegion(conf, tbl.getTableDescriptor(), - Bytes.toBytes("AB"), Bytes.toBytes("B")); + HRegionInfo hriOverlap2 = + createRegion(tbl.getTableDescriptor(), Bytes.toBytes("AB"), Bytes.toBytes("B")); master.assignRegion(hriOverlap2); master.getAssignmentManager().waitForAssignment(hriOverlap2); @@ -946,9 +951,8 @@ public class TestHBaseFsck { } } - HBaseAdmin admin = TEST_UTIL.getHBaseAdmin(); - HBaseFsckRepair.closeRegionSilentlyAndWait(conn, - cluster.getRegionServer(k).getServerName(), hbi.getHdfsHRI()); + HBaseFsckRepair.closeRegionSilentlyAndWait((HConnection) connection, + cluster.getRegionServer(k).getServerName(), hbi.getHdfsHRI()); admin.offline(regionName); break; } @@ -956,14 +960,15 @@ public class TestHBaseFsck { assertNotNull(regionName); assertNotNull(serverName); - Table meta = conn.getTable(TableName.META_TABLE_NAME, executorService); - Put put = new Put(regionName); - put.add(HConstants.CATALOG_FAMILY, HConstants.SERVER_QUALIFIER, - Bytes.toBytes(serverName.getHostAndPort())); - meta.put(put); + try (Table meta = connection.getTable(TableName.META_TABLE_NAME, tableExecutorService)) { + Put put = new Put(regionName); + put.add(HConstants.CATALOG_FAMILY, HConstants.SERVER_QUALIFIER, + Bytes.toBytes(serverName.getHostAndPort())); + meta.put(put); + } // fix the problem. - HBaseFsck fsck = new HBaseFsck(conf); + HBaseFsck fsck = new HBaseFsck(conf, hbfsckExecutorService); fsck.connect(); fsck.setDisplayFullReport(); // i.e. -details fsck.setTimeLag(0); @@ -1001,13 +1006,13 @@ public class TestHBaseFsck { assertEquals(ROWKEYS.length, countRows()); // Mess it up by creating an overlap in the metadata - TEST_UTIL.getHBaseAdmin().disableTable(table); + admin.disableTable(table); deleteRegion(conf, tbl.getTableDescriptor(), Bytes.toBytes("A"), Bytes.toBytes("B"), true, true, false, true, HRegionInfo.DEFAULT_REPLICA_ID); - TEST_UTIL.getHBaseAdmin().enableTable(table); + admin.enableTable(table); - HRegionInfo hriOverlap = createRegion(conf, tbl.getTableDescriptor(), - Bytes.toBytes("A2"), Bytes.toBytes("B")); + HRegionInfo hriOverlap = + createRegion(tbl.getTableDescriptor(), Bytes.toBytes("A2"), Bytes.toBytes("B")); TEST_UTIL.getHBaseCluster().getMaster().assignRegion(hriOverlap); TEST_UTIL.getHBaseCluster().getMaster().getAssignmentManager() .waitForAssignment(hriOverlap); @@ -1046,8 +1051,8 @@ public class TestHBaseFsck { assertEquals(ROWKEYS.length, countRows()); // Mess it up by creating an overlap in the metadata - HRegionInfo hriOverlap = createRegion(conf, tbl.getTableDescriptor(), - Bytes.toBytes("A2"), Bytes.toBytes("B2")); + HRegionInfo hriOverlap = + createRegion(tbl.getTableDescriptor(), Bytes.toBytes("A2"), Bytes.toBytes("B2")); TEST_UTIL.getHBaseCluster().getMaster().assignRegion(hriOverlap); TEST_UTIL.getHBaseCluster().getMaster().getAssignmentManager() .waitForAssignment(hriOverlap); @@ -1087,10 +1092,10 @@ public class TestHBaseFsck { assertEquals(ROWKEYS.length, countRows()); // Mess it up by leaving a hole in the assignment, meta, and hdfs data - TEST_UTIL.getHBaseAdmin().disableTable(table); + admin.disableTable(table); deleteRegion(conf, tbl.getTableDescriptor(), Bytes.toBytes("B"), Bytes.toBytes("C"), true, true, true); - TEST_UTIL.getHBaseAdmin().enableTable(table); + admin.enableTable(table); HBaseFsck hbck = doFsck(conf, false); assertErrors(hbck, new ERROR_CODE[] { @@ -1122,10 +1127,10 @@ public class TestHBaseFsck { assertEquals(ROWKEYS.length, countRows()); // Mess it up by leaving a hole in the meta data - TEST_UTIL.getHBaseAdmin().disableTable(table); + admin.disableTable(table); deleteRegion(conf, tbl.getTableDescriptor(), Bytes.toBytes("B"), Bytes.toBytes("C"), true, true, false, true, HRegionInfo.DEFAULT_REPLICA_ID); - TEST_UTIL.getHBaseAdmin().enableTable(table); + admin.enableTable(table); HBaseFsck hbck = doFsck(conf, false); assertErrors(hbck, new ERROR_CODE[] { @@ -1159,10 +1164,10 @@ public class TestHBaseFsck { assertEquals(ROWKEYS.length, countRows()); // Mess it up by leaving a hole in the meta data - TEST_UTIL.getHBaseAdmin().disableTable(table); + admin.disableTable(table); deleteRegion(conf, tbl.getTableDescriptor(), Bytes.toBytes("B"), Bytes.toBytes("C"), true, true, false); // don't rm from fs - TEST_UTIL.getHBaseAdmin().enableTable(table); + admin.enableTable(table); HBaseFsck hbck = doFsck(conf, false); assertErrors(hbck, new ERROR_CODE[] { @@ -1194,10 +1199,10 @@ public class TestHBaseFsck { assertEquals(ROWKEYS.length, countRows()); // Mess it up by leaving a hole in the meta data - TEST_UTIL.getHBaseAdmin().disableTable(table); + admin.disableTable(table); deleteRegion(conf, tbl.getTableDescriptor(), Bytes.toBytes("B"), Bytes.toBytes("C"), false, true, false); // don't rm from fs - TEST_UTIL.getHBaseAdmin().enableTable(table); + admin.enableTable(table); HBaseFsck hbck = doFsck(conf, false); assertErrors(hbck, new ERROR_CODE[] { @@ -1230,7 +1235,7 @@ public class TestHBaseFsck { assertEquals(ROWKEYS.length, countRows()); // make sure data in regions, if in wal only there is no data loss - TEST_UTIL.getHBaseAdmin().flush(table); + admin.flush(table); // Mess it up by leaving a hole in the hdfs data deleteRegion(conf, tbl.getTableDescriptor(), Bytes.toBytes("B"), @@ -1260,7 +1265,6 @@ public class TestHBaseFsck { public void testNotInHdfsWithReplicas() throws Exception { TableName table = TableName.valueOf("tableNotInHdfs"); - Admin admin = new HBaseAdmin(conf); try { HRegionInfo[] oldHris = new HRegionInfo[2]; setupTableWithRegionReplica(table, 2); @@ -1277,7 +1281,7 @@ public class TestHBaseFsck { } } // make sure data in regions - TEST_UTIL.getHBaseAdmin().flush(table); + admin.flush(table); // Mess it up by leaving a hole in the hdfs data deleteRegion(conf, tbl.getTableDescriptor(), Bytes.toBytes("B"), @@ -1336,7 +1340,7 @@ public class TestHBaseFsck { assertEquals(ROWKEYS.length, countRows()); // make sure data in regions, if in wal only there is no data loss - TEST_UTIL.getHBaseAdmin().flush(table); + admin.flush(table); // Mess it up by deleting hdfs dirs deleteRegion(conf, tbl.getTableDescriptor(), Bytes.toBytes(""), @@ -1363,8 +1367,7 @@ public class TestHBaseFsck { // check that hole fixed assertNoErrors(doFsck(conf,false)); - assertFalse("Table "+ table + " should have been deleted", - TEST_UTIL.getHBaseAdmin().tableExists(table)); + assertFalse("Table " + table + " should have been deleted", admin.tableExists(table)); } public void deleteTableDir(TableName table) throws IOException { @@ -1418,18 +1421,18 @@ public class TestHBaseFsck { // Write the .tableinfo FSTableDescriptors fstd = new FSTableDescriptors(conf); fstd.createTableDescriptor(htdDisabled); - List disabledRegions = TEST_UTIL.createMultiRegionsInMeta( - TEST_UTIL.getConfiguration(), htdDisabled, SPLIT_KEYS); + List disabledRegions = + TEST_UTIL.createMultiRegionsInMeta(conf, htdDisabled, SPLIT_KEYS); // Let's just assign everything to first RS HRegionServer hrs = cluster.getRegionServer(0); // Create region files. - TEST_UTIL.getHBaseAdmin().disableTable(table); - TEST_UTIL.getHBaseAdmin().enableTable(table); + admin.disableTable(table); + admin.enableTable(table); // Disable the table and close its regions - TEST_UTIL.getHBaseAdmin().disableTable(table); + admin.disableTable(table); HRegionInfo region = disabledRegions.remove(0); byte[] regionName = region.getRegionName(); @@ -1453,7 +1456,7 @@ public class TestHBaseFsck { // check result assertNoErrors(doFsck(conf, false)); } finally { - TEST_UTIL.getHBaseAdmin().enableTable(table); + admin.enableTable(table); deleteTable(table); } } @@ -1470,14 +1473,14 @@ public class TestHBaseFsck { try { setupTable(table1); // make sure data in regions, if in wal only there is no data loss - TEST_UTIL.getHBaseAdmin().flush(table1); + admin.flush(table1); // Mess them up by leaving a hole in the hdfs data deleteRegion(conf, tbl.getTableDescriptor(), Bytes.toBytes("B"), Bytes.toBytes("C"), false, false, true); // don't rm meta setupTable(table2); // make sure data in regions, if in wal only there is no data loss - TEST_UTIL.getHBaseAdmin().flush(table2); + admin.flush(table2); // Mess them up by leaving a hole in the hdfs data deleteRegion(conf, tbl.getTableDescriptor(), Bytes.toBytes("B"), Bytes.toBytes("C"), false, false, true); // don't rm meta @@ -1517,7 +1520,7 @@ public class TestHBaseFsck { assertEquals(ROWKEYS.length, countRows()); // make sure data in regions, if in wal only there is no data loss - TEST_UTIL.getHBaseAdmin().flush(table); + admin.flush(table); HRegionLocation location = tbl.getRegionLocation("B"); // Delete one region from meta, but not hdfs, unassign it. @@ -1525,8 +1528,7 @@ public class TestHBaseFsck { Bytes.toBytes("C"), true, true, false); // Create a new meta entry to fake it as a split parent. - meta = new HTable(conf, TableName.META_TABLE_NAME, - executorService); + meta = connection.getTable(TableName.META_TABLE_NAME, tableExecutorService); HRegionInfo hri = location.getRegionInfo(); HRegionInfo a = new HRegionInfo(tbl.getName(), @@ -1539,7 +1541,8 @@ public class TestHBaseFsck { MetaTableAccessor.addRegionToMeta(meta, hri, a, b); meta.flushCommits(); - TEST_UTIL.getHBaseAdmin().flush(TableName.META_TABLE_NAME); + meta.close(); + admin.flush(TableName.META_TABLE_NAME); HBaseFsck hbck = doFsck(conf, false); assertErrors(hbck, new ERROR_CODE[] { @@ -1555,7 +1558,7 @@ public class TestHBaseFsck { ERROR_CODE.LINGERING_SPLIT_PARENT, ERROR_CODE.HOLE_IN_REGION_CHAIN}); // fix lingering split parent - hbck = new HBaseFsck(conf); + hbck = new HBaseFsck(conf, hbfsckExecutorService); hbck.connect(); hbck.setDisplayFullReport(); // i.e. -details hbck.setTimeLag(0); @@ -1569,7 +1572,7 @@ public class TestHBaseFsck { HConstants.SPLITA_QUALIFIER).isEmpty()); assertTrue(result.getColumnCells(HConstants.CATALOG_FAMILY, HConstants.SPLITB_QUALIFIER).isEmpty()); - TEST_UTIL.getHBaseAdmin().flush(TableName.META_TABLE_NAME); + admin.flush(TableName.META_TABLE_NAME); // fix other issues doFsck(conf, true); @@ -1597,18 +1600,16 @@ public class TestHBaseFsck { assertEquals(ROWKEYS.length, countRows()); // make sure data in regions, if in wal only there is no data loss - TEST_UTIL.getHBaseAdmin().flush(table); + admin.flush(table); HRegionLocation location = tbl.getRegionLocation("B"); - meta = new HTable(conf, TableName.META_TABLE_NAME); + meta = connection.getTable(TableName.META_TABLE_NAME, tableExecutorService); HRegionInfo hri = location.getRegionInfo(); // do a regular split - Admin admin = TEST_UTIL.getHBaseAdmin(); byte[] regionName = location.getRegionInfo().getRegionName(); admin.splitRegion(location.getRegionInfo().getRegionName(), Bytes.toBytes("BM")); - TestEndToEndSplitTransaction.blockUntilRegionSplit( - TEST_UTIL.getConfiguration(), 60000, regionName, true); + TestEndToEndSplitTransaction.blockUntilRegionSplit(conf, 60000, regionName, true); // TODO: fixHdfsHoles does not work against splits, since the parent dir lingers on // for some time until children references are deleted. HBCK erroneously sees this as @@ -1627,6 +1628,8 @@ public class TestHBaseFsck { // assert that we still have the split regions assertEquals(tbl.getStartKeys().length, SPLITS.length + 1 + 1); //SPLITS + 1 is # regions pre-split. assertNoErrors(doFsck(conf, false)); + + meta.close(); } finally { deleteTable(table); IOUtils.closeQuietly(meta); @@ -1639,31 +1642,29 @@ public class TestHBaseFsck { */ @Test(timeout=75000) public void testSplitDaughtersNotInMeta() throws Exception { - TableName table = - TableName.valueOf("testSplitdaughtersNotInMeta"); - try (HConnection conn = (HConnection) ConnectionFactory.createConnection(conf); - Table meta = conn.getTable(TableName.META_TABLE_NAME)){ + TableName table = TableName.valueOf("testSplitdaughtersNotInMeta"); + Table meta = connection.getTable(TableName.META_TABLE_NAME, tableExecutorService); + try { setupTable(table); assertEquals(ROWKEYS.length, countRows()); // make sure data in regions, if in wal only there is no data loss - TEST_UTIL.getHBaseAdmin().flush(table); + admin.flush(table); HRegionLocation location = tbl.getRegionLocation("B"); HRegionInfo hri = location.getRegionInfo(); // do a regular split byte[] regionName = location.getRegionInfo().getRegionName(); - conn.getAdmin().splitRegion(location.getRegionInfo().getRegionName(), Bytes.toBytes("BM")); - TestEndToEndSplitTransaction.blockUntilRegionSplit( - TEST_UTIL.getConfiguration(), 60000, regionName, true); + admin.splitRegion(location.getRegionInfo().getRegionName(), Bytes.toBytes("BM")); + TestEndToEndSplitTransaction.blockUntilRegionSplit(conf, 60000, regionName, true); PairOfSameType daughters = HRegionInfo.getDaughterRegions(meta.get(new Get(regionName))); // Delete daughter regions from meta, but not hdfs, unassign it. Map hris = tbl.getRegionLocations(); - undeployRegion(conn, hris.get(daughters.getFirst()), daughters.getFirst()); - undeployRegion(conn, hris.get(daughters.getSecond()), daughters.getSecond()); + undeployRegion(connection, hris.get(daughters.getFirst()), daughters.getFirst()); + undeployRegion(connection, hris.get(daughters.getSecond()), daughters.getSecond()); meta.delete(new Delete(daughters.getFirst().getRegionName())); meta.delete(new Delete(daughters.getSecond().getRegionName())); @@ -1671,18 +1672,20 @@ public class TestHBaseFsck { // Remove daughters from regionStates RegionStates regionStates = TEST_UTIL.getMiniHBaseCluster().getMaster(). - getAssignmentManager().getRegionStates(); + getAssignmentManager().getRegionStates(); regionStates.deleteRegion(daughters.getFirst()); regionStates.deleteRegion(daughters.getSecond()); HBaseFsck hbck = doFsck(conf, false); - assertErrors(hbck, new ERROR_CODE[] {ERROR_CODE.NOT_IN_META_OR_DEPLOYED, - ERROR_CODE.NOT_IN_META_OR_DEPLOYED, ERROR_CODE.HOLE_IN_REGION_CHAIN}); //no LINGERING_SPLIT_PARENT + assertErrors(hbck, + new ERROR_CODE[] { ERROR_CODE.NOT_IN_META_OR_DEPLOYED, ERROR_CODE.NOT_IN_META_OR_DEPLOYED, + ERROR_CODE.HOLE_IN_REGION_CHAIN }); //no LINGERING_SPLIT_PARENT // now fix it. The fix should not revert the region split, but add daughters to META hbck = doFsck(conf, true, true, false, false, false, false, false, false, false, false, null); - assertErrors(hbck, new ERROR_CODE[] {ERROR_CODE.NOT_IN_META_OR_DEPLOYED, - ERROR_CODE.NOT_IN_META_OR_DEPLOYED, ERROR_CODE.HOLE_IN_REGION_CHAIN}); + assertErrors(hbck, + new ERROR_CODE[] { ERROR_CODE.NOT_IN_META_OR_DEPLOYED, ERROR_CODE.NOT_IN_META_OR_DEPLOYED, + ERROR_CODE.HOLE_IN_REGION_CHAIN }); // assert that the split hbase:meta entry is still there. Get get = new Get(hri.getRegionName()); @@ -1696,6 +1699,7 @@ public class TestHBaseFsck { assertEquals(tbl.getStartKeys().length, SPLITS.length + 1 + 1); //SPLITS + 1 is # regions pre-split. assertNoErrors(doFsck(conf, false)); //should be fixed by now } finally { + meta.close(); deleteTable(table); } } @@ -1712,10 +1716,10 @@ public class TestHBaseFsck { assertEquals(ROWKEYS.length, countRows()); // Mess it up by leaving a hole in the assignment, meta, and hdfs data - TEST_UTIL.getHBaseAdmin().disableTable(table); + admin.disableTable(table); deleteRegion(conf, tbl.getTableDescriptor(), Bytes.toBytes(""), Bytes.toBytes("A"), true, true, true); - TEST_UTIL.getHBaseAdmin().enableTable(table); + admin.enableTable(table); HBaseFsck hbck = doFsck(conf, false); assertErrors(hbck, new ERROR_CODE[] { ERROR_CODE.FIRST_REGION_STARTKEY_NOT_EMPTY }); @@ -1738,7 +1742,7 @@ public class TestHBaseFsck { TableName.valueOf("testSingleRegionDeployedNotInHdfs"); try { setupTable(table); - TEST_UTIL.getHBaseAdmin().flush(table); + admin.flush(table); // Mess it up by deleting region dir deleteRegion(conf, tbl.getTableDescriptor(), @@ -1769,10 +1773,10 @@ public class TestHBaseFsck { assertEquals(ROWKEYS.length, countRows()); // Mess it up by leaving a hole in the assignment, meta, and hdfs data - TEST_UTIL.getHBaseAdmin().disableTable(table); + admin.disableTable(table); deleteRegion(conf, tbl.getTableDescriptor(), Bytes.toBytes("C"), Bytes.toBytes(""), true, true, true); - TEST_UTIL.getHBaseAdmin().enableTable(table); + admin.enableTable(table); HBaseFsck hbck = doFsck(conf, false); assertErrors(hbck, new ERROR_CODE[] { ERROR_CODE.LAST_REGION_ENDKEY_NOT_EMPTY }); @@ -1806,7 +1810,7 @@ public class TestHBaseFsck { ERROR_CODE.NOT_DEPLOYED, ERROR_CODE.HOLE_IN_REGION_CHAIN}); // verify that noHdfsChecking report the same errors - HBaseFsck fsck = new HBaseFsck(conf); + HBaseFsck fsck = new HBaseFsck(conf, hbfsckExecutorService); fsck.connect(); fsck.setDisplayFullReport(); // i.e. -details fsck.setTimeLag(0); @@ -1816,7 +1820,7 @@ public class TestHBaseFsck { ERROR_CODE.NOT_DEPLOYED, ERROR_CODE.HOLE_IN_REGION_CHAIN}); // verify that fixAssignments works fine with noHdfsChecking - fsck = new HBaseFsck(conf); + fsck = new HBaseFsck(conf, hbfsckExecutorService); fsck.connect(); fsck.setDisplayFullReport(); // i.e. -details fsck.setTimeLag(0); @@ -1856,7 +1860,7 @@ public class TestHBaseFsck { ERROR_CODE.NOT_IN_META, ERROR_CODE.HOLE_IN_REGION_CHAIN}); // verify that noHdfsChecking report the same errors - HBaseFsck fsck = new HBaseFsck(conf); + HBaseFsck fsck = new HBaseFsck(conf, hbfsckExecutorService); fsck.connect(); fsck.setDisplayFullReport(); // i.e. -details fsck.setTimeLag(0); @@ -1866,7 +1870,7 @@ public class TestHBaseFsck { ERROR_CODE.NOT_IN_META, ERROR_CODE.HOLE_IN_REGION_CHAIN}); // verify that fixMeta doesn't work with noHdfsChecking - fsck = new HBaseFsck(conf); + fsck = new HBaseFsck(conf, hbfsckExecutorService); fsck.connect(); fsck.setDisplayFullReport(); // i.e. -details fsck.setTimeLag(0); @@ -1901,13 +1905,13 @@ public class TestHBaseFsck { assertEquals(ROWKEYS.length, countRows()); // Mess it up by creating an overlap in the metadata - TEST_UTIL.getHBaseAdmin().disableTable(table); + admin.disableTable(table); deleteRegion(conf, tbl.getTableDescriptor(), Bytes.toBytes("A"), Bytes.toBytes("B"), true, true, false, true, HRegionInfo.DEFAULT_REPLICA_ID); - TEST_UTIL.getHBaseAdmin().enableTable(table); + admin.enableTable(table); - HRegionInfo hriOverlap = createRegion(conf, tbl.getTableDescriptor(), - Bytes.toBytes("A2"), Bytes.toBytes("B")); + HRegionInfo hriOverlap = + createRegion(tbl.getTableDescriptor(), Bytes.toBytes("A2"), Bytes.toBytes("B")); TEST_UTIL.getHBaseCluster().getMaster().assignRegion(hriOverlap); TEST_UTIL.getHBaseCluster().getMaster().getAssignmentManager() .waitForAssignment(hriOverlap); @@ -1920,7 +1924,7 @@ public class TestHBaseFsck { ERROR_CODE.HOLE_IN_REGION_CHAIN}); // verify that noHdfsChecking can't detect ORPHAN_HDFS_REGION - HBaseFsck fsck = new HBaseFsck(conf); + HBaseFsck fsck = new HBaseFsck(conf, hbfsckExecutorService); fsck.connect(); fsck.setDisplayFullReport(); // i.e. -details fsck.setTimeLag(0); @@ -1930,7 +1934,7 @@ public class TestHBaseFsck { ERROR_CODE.HOLE_IN_REGION_CHAIN}); // verify that fixHdfsHoles doesn't work with noHdfsChecking - fsck = new HBaseFsck(conf); + fsck = new HBaseFsck(conf, hbfsckExecutorService); fsck.connect(); fsck.setDisplayFullReport(); // i.e. -details fsck.setTimeLag(0); @@ -1943,8 +1947,8 @@ public class TestHBaseFsck { assertErrors(fsck, new ERROR_CODE[] { ERROR_CODE.HOLE_IN_REGION_CHAIN}); } finally { - if (TEST_UTIL.getHBaseAdmin().isTableDisabled(table)) { - TEST_UTIL.getHBaseAdmin().enableTable(table); + if (admin.isTableDisabled(table)) { + admin.enableTable(table); } deleteTable(table); } @@ -1986,13 +1990,13 @@ public class TestHBaseFsck { try { setupTable(table); assertEquals(ROWKEYS.length, countRows()); - TEST_UTIL.getHBaseAdmin().flush(table); // flush is async. + admin.flush(table); // flush is async. FileSystem fs = FileSystem.get(conf); Path hfile = getFlushedHFile(fs, table); // Mess it up by leaving a hole in the assignment, meta, and hdfs data - TEST_UTIL.getHBaseAdmin().disableTable(table); + admin.disableTable(table); // create new corrupt file called deadbeef (valid hfile name) Path corrupt = new Path(hfile.getParent(), "deadbeef"); @@ -2011,7 +2015,7 @@ public class TestHBaseFsck { assertEquals(hfcc.getMissing().size(), 0); // Its been fixed, verify that we can enable. - TEST_UTIL.getHBaseAdmin().enableTable(table); + admin.enableTable(table); } finally { deleteTable(table); } @@ -2025,15 +2029,14 @@ public class TestHBaseFsck { try { setupTable(table); assertEquals(ROWKEYS.length, countRows()); - TEST_UTIL.getHBaseAdmin().flush(table); // flush is async. + admin.flush(table); // flush is async. // Mess it up by leaving a hole in the assignment, meta, and hdfs data - TEST_UTIL.getHBaseAdmin().disableTable(table); + admin.disableTable(table); String[] args = {"-sidelineCorruptHFiles", "-repairHoles", "-ignorePreCheckPermission", table.getNameAsString()}; - ExecutorService exec = new ScheduledThreadPoolExecutor(10); - HBaseFsck res = hbck.exec(exec, args); + HBaseFsck res = hbck.exec(hbfsckExecutorService, args); HFileCorruptionChecker hfcc = res.getHFilecorruptionChecker(); assertEquals(hfcc.getHFilesChecked(), check); @@ -2043,7 +2046,6 @@ public class TestHBaseFsck { assertEquals(hfcc.getMissing().size(), missing); // its been fixed, verify that we can enable - Admin admin = TEST_UTIL.getHBaseAdmin(); admin.enableTableAsync(table); while (!admin.isTableEnabled(table)) { try { @@ -2065,10 +2067,10 @@ public class TestHBaseFsck { @Test(timeout=180000) public void testQuarantineMissingHFile() throws Exception { TableName table = TableName.valueOf(name.getMethodName()); - ExecutorService exec = new ScheduledThreadPoolExecutor(10); + // inject a fault in the hfcc created. final FileSystem fs = FileSystem.get(conf); - HBaseFsck hbck = new HBaseFsck(conf, exec) { + HBaseFsck hbck = new HBaseFsck(conf, hbfsckExecutorService) { @Override public HFileCorruptionChecker createHFileCorruptionChecker(boolean sidelineCorruptHFiles) throws IOException { return new HFileCorruptionChecker(conf, executor, sidelineCorruptHFiles) { @@ -2095,10 +2097,9 @@ public class TestHBaseFsck { @Ignore @Test(timeout=180000) public void testQuarantineMissingFamdir() throws Exception { TableName table = TableName.valueOf(name.getMethodName()); - ExecutorService exec = new ScheduledThreadPoolExecutor(10); // inject a fault in the hfcc created. final FileSystem fs = FileSystem.get(conf); - HBaseFsck hbck = new HBaseFsck(conf, exec) { + HBaseFsck hbck = new HBaseFsck(conf, hbfsckExecutorService) { @Override public HFileCorruptionChecker createHFileCorruptionChecker(boolean sidelineCorruptHFiles) throws IOException { return new HFileCorruptionChecker(conf, executor, sidelineCorruptHFiles) { @@ -2123,10 +2124,9 @@ public class TestHBaseFsck { @Test(timeout=180000) public void testQuarantineMissingRegionDir() throws Exception { TableName table = TableName.valueOf(name.getMethodName()); - ExecutorService exec = new ScheduledThreadPoolExecutor(10); // inject a fault in the hfcc created. final FileSystem fs = FileSystem.get(conf); - HBaseFsck hbck = new HBaseFsck(conf, exec) { + HBaseFsck hbck = new HBaseFsck(conf, hbfsckExecutorService) { @Override public HFileCorruptionChecker createHFileCorruptionChecker(boolean sidelineCorruptHFiles) throws IOException { @@ -2180,14 +2180,13 @@ public class TestHBaseFsck { */ @Test (timeout=180000) public void testMissingRegionInfoQualifier() throws Exception { - TableName table = - TableName.valueOf("testMissingRegionInfoQualifier"); + TableName table = TableName.valueOf("testMissingRegionInfoQualifier"); try { setupTable(table); // Mess it up by removing the RegionInfo for one region. final List deletes = new LinkedList(); - Table meta = new HTable(conf, TableName.META_TABLE_NAME); + Table meta = connection.getTable(TableName.META_TABLE_NAME, tableExecutorService); MetaScanner.metaScan(conf, new MetaScanner.MetaScannerVisitor() { @Override @@ -2227,7 +2226,6 @@ public class TestHBaseFsck { } } - /** * Test pluggable error reporter. It can be plugged in * from system property or configuration. @@ -2414,9 +2412,8 @@ public class TestHBaseFsck { private void deleteMetaRegion(Configuration conf, boolean unassign, boolean hdfs, boolean regionInfoOnly) throws IOException, InterruptedException { - HConnection connection = HConnectionManager.getConnection(conf); - HRegionLocation metaLocation = connection.locateRegion(TableName.META_TABLE_NAME, - HConstants.EMPTY_START_ROW); + HRegionLocation metaLocation = connection.getRegionLocator(TableName.META_TABLE_NAME) + .getRegionLocation(HConstants.EMPTY_START_ROW); ServerName hsa = metaLocation.getServerName(); HRegionInfo hri = metaLocation.getRegionInfo(); if (unassign) { @@ -2461,8 +2458,8 @@ public class TestHBaseFsck { HTableDescriptor desc = new HTableDescriptor(table); HColumnDescriptor hcd = new HColumnDescriptor(Bytes.toString(FAM)); desc.addFamily(hcd); // If a table has no CF's it doesn't get checked - TEST_UTIL.getHBaseAdmin().createTable(desc); - tbl = new HTable(TEST_UTIL.getConfiguration(), table, executorService); + admin.createTable(desc); + tbl = (HTable) connection.getTable(table, tableExecutorService); // Mess it up by leaving a hole in the assignment, meta, and hdfs data deleteRegion(conf, tbl.getTableDescriptor(), HConstants.EMPTY_START_ROW, HConstants.EMPTY_END_ROW, false, @@ -2495,7 +2492,7 @@ public class TestHBaseFsck { assertEquals(ROWKEYS.length, countRows()); // make sure data in regions, if in wal only there is no data loss - TEST_UTIL.getHBaseAdmin().flush(table); + admin.flush(table); HRegionInfo region1 = tbl.getRegionLocation("A").getRegionInfo(); HRegionInfo region2 = tbl.getRegionLocation("B").getRegionInfo(); @@ -2504,7 +2501,6 @@ public class TestHBaseFsck { assertNotEquals(region1, region2); // do a region merge - Admin admin = TEST_UTIL.getHBaseAdmin(); admin.mergeRegions(region1.getEncodedNameAsBytes(), region2.getEncodedNameAsBytes(), false); -- 1.9.3 (Apple Git-50)