Umeshkumar9414 commented on code in PR #7375:
URL: https://github.com/apache/hbase/pull/7375#discussion_r2466634945


##########
hbase-server/src/main/java/org/apache/hadoop/hbase/master/assignment/RegionInTransitionTracker.java:
##########
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase.master.assignment;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.ConcurrentSkipListMap;
+import org.apache.hadoop.hbase.client.RegionInfo;
+import org.apache.hadoop.hbase.client.TableState;
+import org.apache.hadoop.hbase.master.RegionState;
+import org.apache.hadoop.hbase.master.TableStateManager;
+import org.apache.yetus.audience.InterfaceAudience;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
[email protected]
+public class RegionInTransitionTracker {
+  private static final Logger LOG = 
LoggerFactory.getLogger(RegionInTransitionTracker.class);
+
+  private final List<RegionState.State> DISABLE_TABLE_REGION_STATE =
+    List.of(RegionState.State.OFFLINE, RegionState.State.CLOSED);
+
+  private final List<RegionState.State> ENABLE_TABLE_REGION_STATE = 
List.of(RegionState.State.OPEN);
+
+  private final ConcurrentSkipListMap<RegionInfo, RegionStateNode> 
regionInTransition =
+    new ConcurrentSkipListMap<>(RegionInfo.COMPARATOR);
+
+  private final TableStateManager tableStateManager;
+
+  public RegionInTransitionTracker(TableStateManager tableStateManager) {
+    this.tableStateManager = tableStateManager;
+  }
+
+  public boolean isRegionInTransition(final RegionInfo regionInfo) {
+    return regionInTransition.containsKey(regionInfo);
+  }
+
+  public void handleRegionStateNodeOperation(RegionStateNode regionStateNode) {
+    RegionState.State currentState = regionStateNode.getState();
+    // only consider default replica for availability
+    if (regionStateNode.getRegionInfo().getReplicaId() != 
RegionInfo.DEFAULT_REPLICA_ID) {
+      return;
+    }
+    // if region is merged or split it should not be in RIT list
+    if (
+      currentState == RegionState.State.SPLIT || currentState == 
RegionState.State.MERGED
+        || regionStateNode.getRegionInfo().isSplit()
+    ) {
+      removeRegionInTransition(regionStateNode.getRegionInfo());
+    } else if 
(!getExceptedRegionStates(regionStateNode).contains(currentState)) {
+      addRegionInTransition(regionStateNode);
+    } else {
+      removeRegionInTransition(regionStateNode.getRegionInfo());
+    }
+  }
+
+  public void handleRegionDelete(RegionInfo regionInfo) {
+    removeRegionInTransition(regionInfo);
+  }
+
+  private List<RegionState.State> getExceptedRegionStates(RegionStateNode 
regionStateNode) {
+    if (
+      tableStateManager.isTableState(regionStateNode.getTable(), 
TableState.State.ENABLED,
+        TableState.State.ENABLING)
+    ) {
+      return ENABLE_TABLE_REGION_STATE;
+    } else {
+      return DISABLE_TABLE_REGION_STATE;
+    }
+  }
+
+  public void addRegionInTransition(final RegionStateNode regionStateNode) {
+    if (regionInTransition.putIfAbsent(regionStateNode.getRegionInfo(), 
regionStateNode) == null) {
+      LOG.info("Added to RIT list " + 
regionStateNode.getRegionInfo().getEncodedName());
+    }
+  }
+
+  public void removeRegionInTransition(final RegionInfo regionInfo) {
+    if (regionInTransition.remove(regionInfo) != null) {
+      LOG.info("Removed from RIT list " + regionInfo.getEncodedName());

Review Comment:
   done



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