From c0834e1823b3e6ea8bb3674a15fe9d46b1500a6a Mon Sep 17 00:00:00 2001 From: Nihal Jain Date: Mon, 28 Jan 2019 14:05:25 +0530 Subject: [PATCH] HBASE-21795 Client application may get stuck (time bound) if a table modify op is called immediately after split op Signed-off-by: zhangduo --- .../master/assignment/AssignmentManager.java | 4 +- .../hadoop/hbase/client/TestAdmin2.java | 61 +++++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/assignment/AssignmentManager.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/assignment/AssignmentManager.java index fecd003f5b5..6e3d58b84c7 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/assignment/AssignmentManager.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/assignment/AssignmentManager.java @@ -1370,7 +1370,9 @@ public class AssignmentManager implements ServerListener { final List states = regionStates.getTableRegionStates(tableName); int ritCount = 0; for (RegionState regionState: states) { - if (!regionState.isOpened()) ritCount++; + if (!regionState.isOpened() && !regionState.isSplit()) { + ritCount++; + } } return new Pair(ritCount, states.size()); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAdmin2.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAdmin2.java index 4ab1a8fbee0..ad562b2f1b2 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAdmin2.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAdmin2.java @@ -46,6 +46,7 @@ import org.apache.hadoop.hbase.TableNotDisabledException; import org.apache.hadoop.hbase.TableNotEnabledException; import org.apache.hadoop.hbase.TableNotFoundException; import org.apache.hadoop.hbase.UnknownRegionException; +import org.apache.hadoop.hbase.Waiter.Predicate; import org.apache.hadoop.hbase.ZooKeeperConnectionException; import org.apache.hadoop.hbase.constraint.ConstraintException; import org.apache.hadoop.hbase.ipc.HBaseRpcController; @@ -793,4 +794,64 @@ public class TestAdmin2 { Assert.assertEquals(expectedStoreFilesSize, store.getSize()); } } + + @Test + public void testTableSplitFollowedByModify() throws Exception { + final TableName tableName = TableName.valueOf(name.getMethodName()); + TEST_UTIL.createTable(tableName, Bytes.toBytes("f")); + + // get the original table region count + List regions = admin.getRegions(tableName); + int originalCount = regions.size(); + assertEquals(1, originalCount); + + // split the table and wait until region count increases + admin.split(tableName, Bytes.toBytes(3)); + TEST_UTIL.waitFor(30000, new Predicate() { + + @Override + public boolean evaluate() throws Exception { + return admin.getRegions(tableName).size() > originalCount; + } + }); + + // do some table modification + TableDescriptor tableDesc = TableDescriptorBuilder.newBuilder(admin.getDescriptor(tableName)) + .setMaxFileSize(11111111) + .build(); + admin.modifyTable(tableDesc); + assertEquals(11111111, admin.getDescriptor(tableName).getMaxFileSize()); + } + + @Test + public void testTableMergeFollowedByModify() throws Exception { + final TableName tableName = TableName.valueOf(name.getMethodName()); + TEST_UTIL.createTable(tableName, new byte[][] { Bytes.toBytes("f") }, + new byte[][] { Bytes.toBytes(3) }); + + // assert we have at least 2 regions in the table + List regions = admin.getRegions(tableName); + int originalCount = regions.size(); + assertTrue(originalCount >= 2); + + byte[] nameOfRegionA = regions.get(0).getEncodedNameAsBytes(); + byte[] nameOfRegionB = regions.get(1).getEncodedNameAsBytes(); + + // merge the table regions and wait until region count decreases + admin.mergeRegionsAsync(nameOfRegionA, nameOfRegionB, true); + TEST_UTIL.waitFor(30000, new Predicate() { + + @Override + public boolean evaluate() throws Exception { + return admin.getRegions(tableName).size() < originalCount; + } + }); + + // do some table modification + TableDescriptor tableDesc = TableDescriptorBuilder.newBuilder(admin.getDescriptor(tableName)) + .setMaxFileSize(11111111) + .build(); + admin.modifyTable(tableDesc); + assertEquals(11111111, admin.getDescriptor(tableName).getMaxFileSize()); + } }