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_r302401793
 
 

 ##########
 File path: 
hbase-rsgroup/src/test/java/org/apache/hadoop/hbase/rsgroup/TestRSGroupsAdmin2.java
 ##########
 @@ -459,4 +464,250 @@ public boolean evaluate() throws Exception {
     Assert.assertEquals(null, rsGroupAdmin.getRSGroupInfo(fooGroup.getName()));
   }
 
+  @Test
+  public void testFailedMoveBeforeRetryExhaustedWhenMoveServer() throws 
Exception {
+    String groupName = getGroupName(name.getMethodName());
+    rsGroupAdmin.addRSGroup(groupName);
+    final RSGroupInfo newGroup = rsGroupAdmin.getRSGroupInfo(groupName);
+    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;
+      }
+    });
+
+    Pair<ServerName, RegionStateNode> gotPair = setARegionState(newGroup);
+
+    // start thread to recover region state
+    final ServerName movedServer = gotPair.getFirst();
+    final RegionStateNode rsn = gotPair.getSecond();
+    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(),
+              rsn.getRegionInfo().getRegionNameAsString());
+          rsn.setState(RegionState.State.OPEN);
+          LOG.info("set region {} state OPEN", 
rsn.getRegionInfo().getRegionNameAsString());
+          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 testFailedMoveBeforeRetryExhaustedWhenMoveTable() throws 
Exception {
+    final RSGroupInfo newGroup = addGroup(getGroupName(name.getMethodName()), 
1);
+    final byte[] familyNameBytes = Bytes.toBytes("f");
+    final int tableRegionCount = 5;
+    // 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;
+      }
+    });
+
+    Pair<ServerName, RegionStateNode> gotPair = setARegionState(newGroup);
+
+    // move table to group
+    Thread t2 = new Thread(() -> {
+      LOG.info("thread2 start running, to move regions");
+      try {
+        rsGroupAdmin.moveTables(Sets.newHashSet(tableName), 
newGroup.getName());
+      } catch (IOException e) {
+        LOG.error("move server error", e);
+      }
+    });
+    t2.start();
+
+    // start thread to recover region state
+    final ServerName ss = gotPair.getFirst();
+    final RegionStateNode rsn = gotPair.getSecond();
+    AtomicBoolean changed = new AtomicBoolean(false);
+    Thread t1 = new Thread(() -> {
 
 Review comment:
   Replied at above conversation. 

----------------------------------------------------------------
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

Reply via email to