virajjasani commented on code in PR #5903:
URL: https://github.com/apache/hbase/pull/5903#discussion_r1617606384


##########
hbase-server/src/main/java/org/apache/hadoop/hbase/master/assignment/AssignmentManager.java:
##########
@@ -1084,14 +1085,55 @@ public TransitRegionStateProcedure[] 
createUnassignProceduresForDisabling(TableN
   }
 
   /**
-   * Called by ModifyTableProcedures to unassign all the excess region 
replicas for a table.
+   * Called by ModifyTableProcedure to unassign all the excess region replicas 
for a table. Will
+   * skip submit unassign procedure if the region is in transition, so you may 
need to call this
+   * method multiple times.
+   * @param tableName       the table for closing excess region replicas
+   * @param newReplicaCount the new replica count, should be less than current 
replica count
+   * @param submit          for submitting procedure
+   * @return the number of regions in transition that we can not schedule 
unassign procedures
    */
-  public TransitRegionStateProcedure[] 
createUnassignProceduresForClosingExcessRegionReplicas(
-    TableName tableName, int newReplicaCount) {
-    return regionStates.getTableRegionStateNodes(tableName).stream()
-      .filter(regionNode -> regionNode.getRegionInfo().getReplicaId() >= 
newReplicaCount)
-      .map(this::forceCreateUnssignProcedure).filter(p -> p != null)
-      .toArray(TransitRegionStateProcedure[]::new);
+  public int submitUnassignProcedureForClosingExcessRegionReplicas(TableName 
tableName,
+    int newReplicaCount, Consumer<TransitRegionStateProcedure> submit) {
+    int inTransitionCount = 0;
+    for (RegionStateNode regionNode : 
regionStates.getTableRegionStateNodes(tableName)) {
+      regionNode.lock();
+      try {
+        if (regionNode.getRegionInfo().getReplicaId() >= newReplicaCount) {
+          if (regionNode.isInTransition()) {
+            LOG.debug("skip scheduling unassign procedure for {} when closing 
excess region "
+              + "replicas since it is in transition", regionNode);
+            inTransitionCount++;
+            continue;
+          }
+          if (regionNode.isInState(State.OFFLINE, State.CLOSED, State.SPLIT)) {
+            continue;
+          }
+          submit.accept(regionNode.setProcedure(TransitRegionStateProcedure
+            .unassign(getProcedureEnvironment(), regionNode.getRegionInfo())));
+        }
+      } finally {
+        regionNode.unlock();
+      }
+    }
+    return inTransitionCount;
+  }
+
+  public int numberOfUnclosedExcessRegionReplicas(TableName tableName, int 
newReplicaCount) {

Review Comment:
   Makes sense



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

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to