From 5645d48eaccee8339d578053a98ddec60fc87e12 Mon Sep 17 00:00:00 2001 From: Michael Stack Date: Mon, 20 Jan 2014 21:58:00 +0000 Subject: [PATCH] HBASE-10377 Add test for HBASE-10370 Compaction in out-of-date Store causes region split failure git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1559838 13f79535-47bb-0310-9956-ffa450edef68 --- .../TestSplitTransactionOnCluster.java | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestSplitTransactionOnCluster.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestSplitTransactionOnCluster.java index 6af48b93515..e013f49cb7f 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestSplitTransactionOnCluster.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestSplitTransactionOnCluster.java @@ -75,6 +75,8 @@ import org.apache.hadoop.hbase.master.RegionState; import org.apache.hadoop.hbase.master.RegionStates; import org.apache.hadoop.hbase.master.RegionState.State; import org.apache.hadoop.hbase.protobuf.ProtobufUtil; +import org.apache.hadoop.hbase.regionserver.compactions.CompactionContext; +import org.apache.hadoop.hbase.regionserver.compactions.CompactionRequest; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; import org.apache.hadoop.hbase.util.FSUtils; @@ -298,7 +300,54 @@ public class TestSplitTransactionOnCluster { TESTING_UTIL.deleteTable(tableName); } } + @Test + public void testSplitFailedCompactionAndSplit() throws Exception { + final byte[] tableName = Bytes.toBytes("testSplitFailedCompactionAndSplit"); + Configuration conf = TESTING_UTIL.getConfiguration(); + HBaseAdmin admin = new HBaseAdmin(conf); + // Create table then get the single region for our new table. + HTableDescriptor htd = new HTableDescriptor(tableName); + byte[] cf = Bytes.toBytes("cf"); + htd.addFamily(new HColumnDescriptor(cf)); + admin.createTable(htd); + + for (int i = 0; cluster.getRegions(tableName).size() == 0 && i < 100; i++) { + Thread.sleep(100); + } + assertEquals(1, cluster.getRegions(tableName).size()); + + HRegion region = cluster.getRegions(tableName).get(0); + Store store = region.getStore(cf); + int regionServerIndex = cluster.getServerWith(region.getRegionName()); + HRegionServer regionServer = cluster.getRegionServer(regionServerIndex); + + HTable t = new HTable(conf, tableName); + // insert data + insertData(tableName, admin, t); + insertData(tableName, admin, t); + + int fileNum = store.getStorefiles().size(); + // 0, Compaction Request + store.triggerMajorCompaction(); + CompactionContext cc = store.requestCompaction(); + assertNotNull(cc); + // 1, A timeout split + // 1.1 close region + assertEquals(2, region.close(false).get(cf).size()); + // 1.2 rollback and Region initialize again + region.initialize(); + + // 2, Run Compaction cc + assertFalse(region.compact(cc, store)); + assertTrue(fileNum > store.getStorefiles().size()); + // 3, Split + SplitTransaction st = new SplitTransaction(region, Bytes.toBytes("row3")); + assertTrue(st.prepare()); + st.execute(regionServer, regionServer); + assertEquals(2, cluster.getRegions(tableName).size()); + } + public static class FailingSplitRegionObserver extends BaseRegionObserver { static volatile CountDownLatch latch = new CountDownLatch(1); @Override