junkaixue commented on code in PR #2618:
URL: https://github.com/apache/helix/pull/2618#discussion_r1329563673


##########
helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixAdmin.java:
##########
@@ -407,10 +409,60 @@ public ZNRecord update(ZNRecord currentData) {
   }
 
   @Override
-  public void enableResource(final String clusterName, final String 
resourceName,
-      final boolean enabled) {
-    logger.info("{} resource {} in cluster {}.", enabled ? "Enable" : 
"Disable", resourceName,
-        clusterName);
+  public boolean isEvacuateFinished(String clusterName, String instanceName) {
+    return !instanceHasCurrentSateOrMessage(clusterName, instanceName);
+  }
+
+  @Override
+  public boolean isReadyForPreparingJoiningCluster(String clusterName, String 
instanceName) {
+    return !instanceHasCurrentSateOrMessage(clusterName, instanceName)
+        && 
DelayedAutoRebalancer.INSTANCE_OPERATION_TO_EXCLUDE_FROM_ASSIGNMENT.contains(
+        getInstanceConfig(clusterName, instanceName).getInstanceOperation());
+  }
+
+  /**
+   * Return true if Instance has any current state or pending message. 
Otherwise, return false if instance is offline,
+   * instance has no active session, or if instance is online but has no 
current state or pending message.
+   * @param clusterName
+   * @param instanceName
+   * @return
+   */
+  private boolean instanceHasCurrentSateOrMessage(String clusterName, String 
instanceName) {
+    HelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new 
ZkBaseDataAccessor<ZNRecord>(_zkClient));
+    PropertyKey.Builder keyBuilder = accessor.keyBuilder();
+
+    // check the instance is alive
+    LiveInstance liveInstance = 
accessor.getProperty(keyBuilder.liveInstance(instanceName));
+    if (liveInstance == null) {
+      logger.warn("Instance {} in cluster {} is not alive. The instance can be 
removed anyway.", instanceName,
+          clusterName);
+      return false;
+    }
+
+    BaseDataAccessor<ZNRecord> baseAccessor = new 
ZkBaseDataAccessor<ZNRecord>(_zkClient);
+    String sessionId = liveInstance.getEphemeralOwner();
+
+    String path = PropertyPathBuilder.instanceCurrentState(clusterName, 
instanceName, sessionId);
+    List<String> currentStates = baseAccessor.getChildNames(path, 0);
+    if (currentStates == null) {
+      logger.warn("Instance {} in cluster {} does not have live session.  The 
instance can be removed anyway.",
+          instanceName, clusterName);
+      return false;
+    }

Review Comment:
   Race condition can happen if the instance is carrying over from old session 
current state. New session current state is empty.



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to