xyuanlu commented on code in PR #2661:
URL: https://github.com/apache/helix/pull/2661#discussion_r1366200079


##########
helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixAdmin.java:
##########
@@ -410,13 +472,260 @@ public ZNRecord update(ZNRecord currentData) {
 
   @Override
   public boolean isEvacuateFinished(String clusterName, String instanceName) {
-    return !instanceHasCurrentSateOrMessage(clusterName, instanceName) && 
(getInstanceConfig(clusterName,
+    return !instanceHasCurrentStateOrMessage(clusterName, instanceName) && 
(getInstanceConfig(
+        clusterName,
         
instanceName).getInstanceOperation().equals(InstanceConstants.InstanceOperation.EVACUATE.name()));
   }
 
+  /**
+   * Find the instance that this passed instance is swapping with. If the 
passed instance has
+   * SWAP_OUT instanceOperation, then find the corresponding instance that has 
SWAP_IN
+   * instanceOperation. If the passed instance has SWAP_IN instanceOperation, 
then find the
+   * corresponding instance that has SWAP_OUT instanceOperation.
+   *
+   * @param clusterName    The cluster name
+   * @param instanceConfig The instance to find the swap instance for
+   * @return The swap instance if found, null otherwise.
+   */
+  @Nullable
+  private InstanceConfig findMatchingSwapInstance(String clusterName,
+      InstanceConfig instanceConfig) {
+    String logicalIdKey =
+        
ClusterTopologyConfig.createFromClusterConfig(_configAccessor.getClusterConfig(clusterName))
+            .getEndNodeType();
+
+    for (String potentialSwappingInstance : getConfigKeys(
+        new 
HelixConfigScopeBuilder(HelixConfigScope.ConfigScopeProperty.PARTICIPANT,
+            clusterName).build())) {
+      InstanceConfig potentialSwappingInstanceConfig =
+          getInstanceConfig(clusterName, potentialSwappingInstance);
+
+      // Return if there is a matching Instance with the same logicalId and 
opposite InstanceOperation swap operation.
+      if (potentialSwappingInstanceConfig.getLogicalId(logicalIdKey)
+          .equals(instanceConfig.getLogicalId(logicalIdKey)) && (
+          instanceConfig.getInstanceOperation()
+              .equals(InstanceConstants.InstanceOperation.SWAP_IN.name())
+              && potentialSwappingInstanceConfig.getInstanceOperation()
+              .equals(InstanceConstants.InstanceOperation.SWAP_OUT.name())) || 
(
+          instanceConfig.getInstanceOperation()
+              .equals(InstanceConstants.InstanceOperation.SWAP_OUT.name())
+              && potentialSwappingInstanceConfig.getInstanceOperation()
+              .equals(InstanceConstants.InstanceOperation.SWAP_IN.name()))) {
+        return potentialSwappingInstanceConfig;
+      }
+    }
+
+    return null;
+  }
+
+  /**
+   * Check to see if swapping between two instances is ready to be completed. 
Checks: 1. Both
+   * instances must be alive. 2. Both instances must only have one session and 
not be carrying over
+   * from a previous session. 3. Both instances must have no pending messages. 
4. Both instances
+   * cannot have partitions in the ERROR state 4. SwapIn instance must have 
correct state for all
+   * partitions that are currently assigned to the SwapOut instance.
+   * TODO: We may want to make this a public API in the future.

Review Comment:
   Add check ideal state and CS as well. Possible that when no pending msg, 
there will be partition assigned in the future. 



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