sunhelly commented on a change in pull request #323: HBASE-22414 Interruption
of moving regions in RSGroup will cause regi…
URL: https://github.com/apache/hbase/pull/323#discussion_r301868062
##########
File path:
hbase-rsgroup/src/test/java/org/apache/hadoop/hbase/rsgroup/TestRSGroupsAdmin2.java
##########
@@ -459,4 +463,197 @@ public boolean evaluate() throws Exception {
Assert.assertEquals(null, rsGroupAdmin.getRSGroupInfo(fooGroup.getName()));
}
+ @Test
+ public void testFailedMoveWhenMoveServer() throws Exception {
+ final RSGroupInfo newGroup = addGroup(getGroupName(name.getMethodName()),
1);
+ final byte[] familyNameBytes = Bytes.toBytes("f");
+ final int tableRegionCount = 10;
+ // All the regions created below will be assigned to the default group.
+ TEST_UTIL.createMultiRegionTable(tableName, familyNameBytes,
tableRegionCount);
+ TEST_UTIL.waitFor(WAIT_TIMEOUT, new Waiter.Predicate<Exception>() {
+ @Override
+ public boolean evaluate() throws Exception {
+ List<String> regions = getTableRegionMap().get(tableName);
+ if (regions == null) {
+ return false;
+ }
+ return getTableRegionMap().get(tableName).size() >= tableRegionCount;
+ }
+ });
+
+ // get target server to move, which should has more than one regions
+ // randomly set a region state to SPLITTING
+ Map<ServerName, List<String>> assignMap =
getTableServerRegionMap().get(tableName);
+ String rregion = null;
+ ServerName toMoveServer = null;
+ for (ServerName server : assignMap.keySet()) {
+ rregion = assignMap.get(server).size() > 1 &&
!newGroup.containsServer(server.getAddress()) ?
+ assignMap.get(server).get(0) :
+ null;
+ if (rregion != null) {
+ toMoveServer = server;
+ break;
+ }
+ }
+ assert toMoveServer != null;
+ RegionInfo ri =
TEST_UTIL.getMiniHBaseCluster().getMaster().getAssignmentManager().
+ getRegionInfo(Bytes.toBytesBinary(rregion));
+ RegionStateNode rsn =
+
TEST_UTIL.getMiniHBaseCluster().getMaster().getAssignmentManager().getRegionStates()
+ .getRegionStateNode(ri);
+ rsn.setState(RegionState.State.SPLITTING);
+
+ // start thread to recover region state
+ final ServerName movedServer = toMoveServer;
+ final String sregion = rregion;
+ AtomicBoolean changed = new AtomicBoolean(false);
+ Thread t1 = new Thread(() -> {
+ LOG.debug("thread1 start running, will recover region state");
+ long current = System.currentTimeMillis();
+ while (System.currentTimeMillis() - current <= 50000) {
+ List<RegionInfo> regions =
master.getAssignmentManager().getRegionsOnServer(movedServer);
+ LOG.debug("server region size is:{}", regions.size());
+ assert regions.size() >= 1;
+ // when there is exactly one region left, we can determine the move
operation encountered
+ // exception caused by the strange region state.
+ if (regions.size() == 1) {
+ assertEquals(regions.get(0).getRegionNameAsString(), sregion);
+ rsn.setState(RegionState.State.OPEN);
+ LOG.info("set region {} state OPEN", sregion);
+ changed.set(true);
+ break;
+ }
+ sleep(5000);
+ }
+ });
+ t1.start();
+
+ // move target server to group
+ Thread t2 = new Thread(() -> {
+ LOG.info("thread2 start running, to move regions");
+ try {
+ rsGroupAdmin.moveServers(Sets.newHashSet(movedServer.getAddress()),
newGroup.getName());
+ } catch (IOException e) {
+ LOG.error("move server error", e);
+ }
+ });
+ t2.start();
+
+ t1.join();
+ t2.join();
+
+ TEST_UTIL.waitFor(WAIT_TIMEOUT, new Waiter.Predicate<Exception>() {
+ @Override
+ public boolean evaluate() {
+ if (changed.get()) {
+ return
master.getAssignmentManager().getRegionsOnServer(movedServer).size() == 0 &&
!rsn
+ .getRegionLocation().equals(movedServer);
+ }
+ return false;
+ }
+ });
+ }
+
+ @Test
+ public void testFailedMoveWhenMoveTable() throws Exception {
Review comment:
I make a function named setARegionState to randomly choosing a region and
set its state. The difference of the two UTs is at adding group and moving
operation. Is this OK?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services