From 2abacfa265b738e56dbf059fe86fde21f8eb4485 Mon Sep 17 00:00:00 2001 From: Elliott Clark Date: Fri, 9 Oct 2015 10:55:15 -0700 Subject: [PATCH] HBASE-14585 Clean up TestSnapshotCloneIndependence --- .../client/TestSnapshotCloneIndependence.java | 52 +++++++++++++++++----- 1 file changed, 41 insertions(+), 11 deletions(-) diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestSnapshotCloneIndependence.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestSnapshotCloneIndependence.java index 4ea8ff0..55213e6 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestSnapshotCloneIndependence.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestSnapshotCloneIndependence.java @@ -18,6 +18,7 @@ package org.apache.hadoop.hbase.client; +import java.io.IOException; import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -53,7 +54,7 @@ public class TestSnapshotCloneIndependence { protected static final HBaseTestingUtility UTIL = new HBaseTestingUtility(); - protected static final int NUM_RS = 2; + protected static final int NUM_RS = 1; private static final String STRING_TABLE_NAME = "test"; private static final String TEST_FAM_STR = "fam"; protected static final byte[] TEST_FAM = Bytes.toBytes(TEST_FAM_STR); @@ -72,11 +73,12 @@ public class TestSnapshotCloneIndependence { static void setupConf(Configuration conf) { // Up the handlers; this test needs more than usual. - conf.setInt(HConstants.REGION_SERVER_HIGH_PRIORITY_HANDLER_COUNT, 10); + conf.setInt(HConstants.REGION_SERVER_HIGH_PRIORITY_HANDLER_COUNT, 15); // enable snapshot support conf.setBoolean(SnapshotManager.HBASE_SNAPSHOT_ENABLED, true); // disable the ui conf.setInt("hbase.regionsever.info.port", -1); + conf.setInt("hbase.master.info.port", -1); // change the flush size to a small amount, regulating number of store files conf.setInt("hbase.hregion.memstore.flush.size", 25000); // so make sure we get a compaction when doing a load, but keep around @@ -89,7 +91,7 @@ public class TestSnapshotCloneIndependence { conf.setBoolean("hbase.master.enabletable.roundrobin", true); // Avoid potentially aggressive splitting which would cause snapshot to fail conf.set(HConstants.HBASE_REGION_SPLIT_POLICY_KEY, - ConstantSizeRegionSplitPolicy.class.getName()); + ConstantSizeRegionSplitPolicy.class.getName()); // Execute cleaner frequently to induce failures conf.setInt("hbase.master.cleaner.interval", CLEANER_INTERVAL); conf.setInt("hbase.master.hfilecleaner.plugins.snapshot.period", CLEANER_INTERVAL); @@ -187,7 +189,7 @@ public class TestSnapshotCloneIndependence { private static void waitOnSplit(Connection c, final Table t, int originalCount) throws Exception { for (int i = 0; i < 200; i++) { try { - Thread.sleep(50); + Thread.sleep(500); } catch (InterruptedException e) { // Restore the interrupted status Thread.currentThread().interrupt(); @@ -227,12 +229,17 @@ public class TestSnapshotCloneIndependence { snapshotNameAsString, rootDir, fs, online); if (!online) { - admin.enableTable(localTableName); + tryDisable(admin, localTableName); } TableName cloneTableName = TableName.valueOf("test-clone-" + localTableName); admin.cloneSnapshot(snapshotName, cloneTableName); try (Table clonedTable = UTIL.getConnection().getTable(cloneTableName)) { + + // Make sure that all the regions are available before starting + UTIL.waitTableAvailable(cloneTableName); + UTIL.waitUntilAllRegionsAssigned(cloneTableName); + final int clonedTableRowCount = countRows(clonedTable); Assert.assertEquals( @@ -292,7 +299,7 @@ public class TestSnapshotCloneIndependence { snapshotNameAsString, rootDir, fs, online); if (!online) { - admin.enableTable(localTableName); + tryDisable(admin, localTableName); } TableName cloneTableName = TableName.valueOf("test-clone-" + localTableName); @@ -346,8 +353,9 @@ public class TestSnapshotCloneIndependence { snapshotNameAsString, rootDir, fs, online); if (!online) { - admin.enableTable(localTableName); + tryDisable(admin, localTableName); } + TableName cloneTableName = TableName.valueOf("test-clone-" + localTableName); // Clone the snapshot @@ -358,11 +366,12 @@ public class TestSnapshotCloneIndependence { byte[] TEST_FAM_2 = Bytes.toBytes("fam2"); HColumnDescriptor hcd = new HColumnDescriptor(TEST_FAM_2); - admin.disableTable(localTableName); + tryDisable(admin, localTableName); admin.addColumnFamily(localTableName, hcd); // Verify that it is not in the snapshot admin.enableTable(localTableName); + UTIL.waitTableAvailable(localTableName); // get a description of the cloned table // get a list of its families @@ -381,6 +390,18 @@ public class TestSnapshotCloneIndependence { !clonedTableDescriptor.hasFamily(TEST_FAM_2)); } + private void tryDisable(Admin admin, TableName localTableName) throws IOException { + int offlineRetry = 0; + while ( offlineRetry < 5 && admin.isTableEnabled(localTableName)) { + try { + admin.disableTable(localTableName); + } catch (IOException ioe) { + LOG.warn("Error disabling the table", ioe); + } + offlineRetry ++; + } + } + /* * Take a snapshot of a table, add data, and verify that deleting the snapshot does not affect * either table. @@ -407,8 +428,9 @@ public class TestSnapshotCloneIndependence { snapshotNameAsString, rootDir, fs, online); if (!online) { - admin.enableTable(localTableName); + tryDisable(admin, localTableName); } + TableName cloneTableName = TableName.valueOf("test-clone-" + localTableName); admin.cloneSnapshot(snapshotName, cloneTableName); @@ -419,7 +441,9 @@ public class TestSnapshotCloneIndependence { admin.deleteSnapshot(snapshotName); // Wait for cleaner run and DFS heartbeats so that anything that is deletable is fully deleted - Thread.sleep(10000); + do { + Thread.sleep(5000); + } while (admin.listSnapshots(snapshotNameAsString).isEmpty()); try (Table original = UTIL.getConnection().getTable(localTableName)) { try (Table clonedTable = UTIL.getConnection().getTable(cloneTableName)) { @@ -432,7 +456,13 @@ public class TestSnapshotCloneIndependence { } protected Table createTable(final TableName table, byte[] family) throws Exception { - return UTIL.createTable(table, family); + Table t = UTIL.createTable(table, family); + // Wait for everything to be ready with the table + UTIL.waitTableAvailable(table); + UTIL.waitUntilAllRegionsAssigned(table); + + // At this point the table should be good to go. + return t; } protected void loadData(final Table table, byte[]... families) throws Exception { -- 2.6.0