sunhelly commented on a change in pull request #3001:
URL: https://github.com/apache/hbase/pull/3001#discussion_r595114912



##########
File path: 
hbase-server/src/main/java/org/apache/hadoop/hbase/master/assignment/AssignmentManagerUtil.java
##########
@@ -189,6 +190,67 @@ private static void unlock(List<RegionStateNode> 
regionNodes) {
     return ArrayUtils.addAll(primaryRegionProcs, replicaRegionAssignProcs);
   }
 
+  /**
+   * Create round robin assign procedures for the give regions,

Review comment:
       Thanks, I'll change it.

##########
File path: 
hbase-server/src/main/java/org/apache/hadoop/hbase/master/assignment/AssignmentManagerUtil.java
##########
@@ -189,6 +190,67 @@ private static void unlock(List<RegionStateNode> 
regionNodes) {
     return ArrayUtils.addAll(primaryRegionProcs, replicaRegionAssignProcs);
   }
 
+  /**
+   * Create round robin assign procedures for the give regions,
+   * according to the {@code regionReplication}.
+   * <p/>
+   * For rolling back, we will submit procedures directly to the {@code 
ProcedureExecutor}, so it is
+   * possible that we persist the newly scheduled procedures, and then crash 
before persisting the
+   * rollback state, so when we arrive here the second time, it is possible 
that some regions have
+   * already been associated with a TRSP.
+   * @param ignoreIfInTransition if true, will skip creating TRSP for the 
given region if it is
+   *          already in transition, otherwise we will add an assert that it 
should not in
+   *          transition.
+   */
+  private static TransitRegionStateProcedure[] 
createRoundRobinAssignProcedures(
+    MasterProcedureEnv env, List<RegionInfo> regions, int regionReplication,
+    List<ServerName> serversToExclude, boolean ignoreIfInTransition) {
+    List<RegionInfo> regionsAndReplicas = new ArrayList<>(regions);
+    if (regionReplication != DEFAULT_REGION_REPLICA) {
+
+      // collect the replica region infos
+      List<RegionInfo> replicaRegionInfos =
+        new ArrayList<RegionInfo>(regions.size() * (regionReplication - 1));
+      for (RegionInfo hri : regions) {
+        // start the index from 1
+        for (int i = 1; i < regionReplication; i++) {
+          
replicaRegionInfos.add(RegionReplicaUtil.getRegionInfoForReplica(hri, i));
+        }
+      }
+      regionsAndReplicas.addAll(replicaRegionInfos);
+    }
+    if (ignoreIfInTransition) {
+      for (RegionInfo region : regionsAndReplicas) {
+        if 
(env.getAssignmentManager().getRegionStates().getOrCreateRegionStateNode(region)
+          .isInTransition()) {
+          return null;
+        }
+      }
+    }
+    // create round robin procs. Note that we exclude the primary region's 
target server
+    return env.getAssignmentManager()
+      .createRoundRobinAssignProcedures(regionsAndReplicas, serversToExclude);
+  }
+
+  static TransitRegionStateProcedure[] createAssignProceduresForSplitDaughters(
+    MasterProcedureEnv env, List<RegionInfo> daughters, int regionReplication,
+    ServerName parentServer) {
+    
if(env.getMasterConfiguration().getBoolean(HConstants.HBASE_ENABLE_SEPARATE_CHILD_REGIONS,
+      false)){
+      // keep daughter one on the parent RS

Review comment:
       Thanks, I'll change it.

##########
File path: 
hbase-server/src/test/java/org/apache/hadoop/hbase/master/assignment/TestRegionSplit.java
##########
@@ -146,8 +152,70 @@ public void testSplitTableRegion() throws Exception {
     UTIL.getAdmin().enableTable(tableName);
     Thread.sleep(500);
 
-    assertEquals("Table region not correct.", 2,
-        UTIL.getHBaseCluster().getRegions(tableName).size());
+    List<HRegion> tableRegions = UTIL.getHBaseCluster().getRegions(tableName);
+    assertEquals("Table region not correct.", 2, tableRegions.size());
+    Map<RegionInfo, ServerName> regionInfoMap = 
UTIL.getHBaseCluster().getMaster().getAssignmentManager()
+      .getRegionStates().getRegionAssignments();
+    assertEquals(regionInfoMap.get(tableRegions.get(0).getRegionInfo()),
+      regionInfoMap.get(tableRegions.get(1).getRegionInfo()));
+  }
+
+  @Test
+  public void testSplitTableRegionAndSeparateChildRegions() throws Exception {
+    cleanupTest();
+    //restart master
+    
UTIL.getConfiguration().setBoolean(HConstants.HBASE_ENABLE_SEPARATE_CHILD_REGIONS,
 true);
+    setupCluster();
+
+    final TableName tableName = TableName.valueOf(name.getMethodName());
+    final ProcedureExecutor<MasterProcedureEnv> procExec = 
getMasterProcedureExecutor();
+
+    RegionInfo[] regions =
+      MasterProcedureTestingUtility.createTable(procExec, tableName, null, 
ColumnFamilyName);
+    insertData(tableName);
+    int splitRowNum = startRowNum + rowCount / 2;
+    byte[] splitKey = Bytes.toBytes("" + splitRowNum);
+
+    assertTrue("not able to find a splittable region", regions != null);
+    assertTrue("not able to find a splittable region", regions.length == 1);
+
+    // Split region of the table
+    long procId = procExec.submitProcedure(
+      new SplitTableRegionProcedure(procExec.getEnvironment(), regions[0], 
splitKey));
+    // Wait the completion
+    ProcedureTestingUtility.waitProcedure(procExec, procId);
+    ProcedureTestingUtility.assertProcNotFailed(procExec, procId);
+
+    assertTrue("not able to split table", 
UTIL.getHBaseCluster().getRegions(tableName).size() == 2);
+
+    //disable table
+    UTIL.getAdmin().disableTable(tableName);
+    Thread.sleep(500);
+
+    //stop master
+    UTIL.getHBaseCluster().stopMaster(0);
+    UTIL.getHBaseCluster().waitOnMaster(0);
+    Thread.sleep(500);
+
+    //restart master
+    JVMClusterUtil.MasterThread t = UTIL.getHBaseCluster().startMaster();
+    Thread.sleep(500);
+
+    UTIL.invalidateConnection();
+    // enable table
+    UTIL.getAdmin().enableTable(tableName);
+    Thread.sleep(500);
+
+    List<HRegion> tableRegions = UTIL.getHBaseCluster().getRegions(tableName);
+    assertEquals("Table region not correct.", 2, tableRegions.size());
+    Map<RegionInfo, ServerName> regionInfoMap = 
UTIL.getHBaseCluster().getMaster().getAssignmentManager()
+      .getRegionStates().getRegionAssignments();
+    assertNotEquals(regionInfoMap.get(tableRegions.get(0).getRegionInfo()),

Review comment:
       Because the test cluster has three region servers, and before the round 
robin assignment, one daughter will be kept on the parent server, which will be 
excluded from the round robin servers set. At last, the other daughter ant its 
replicas will be assigned to the other two servers. More than one servers in 
the destination server set will make round robin work well.

##########
File path: 
hbase-server/src/test/java/org/apache/hadoop/hbase/master/assignment/TestRegionSplit.java
##########
@@ -146,8 +152,70 @@ public void testSplitTableRegion() throws Exception {
     UTIL.getAdmin().enableTable(tableName);
     Thread.sleep(500);
 
-    assertEquals("Table region not correct.", 2,
-        UTIL.getHBaseCluster().getRegions(tableName).size());
+    List<HRegion> tableRegions = UTIL.getHBaseCluster().getRegions(tableName);
+    assertEquals("Table region not correct.", 2, tableRegions.size());
+    Map<RegionInfo, ServerName> regionInfoMap = 
UTIL.getHBaseCluster().getMaster().getAssignmentManager()
+      .getRegionStates().getRegionAssignments();
+    assertEquals(regionInfoMap.get(tableRegions.get(0).getRegionInfo()),
+      regionInfoMap.get(tableRegions.get(1).getRegionInfo()));
+  }
+
+  @Test
+  public void testSplitTableRegionAndSeparateChildRegions() throws Exception {
+    cleanupTest();

Review comment:
       Thanks, I'll change it.




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


Reply via email to