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


##########
helix-core/src/main/java/org/apache/helix/HelixAdmin.java:
##########
@@ -747,6 +756,26 @@ Map<String, Boolean> 
validateInstancesForWagedRebalance(String clusterName,
    */
   boolean isEvacuateFinished(String clusterName, String instancesNames);
 
+  /**
+   * Check to see if swapping between two instances is ready to be completed. 
Either the swapOut or
+   * swapIn instance can be passed in.
+   * @param clusterName  The cluster name
+   * @param instanceName The instance that is being swapped out or swapped in
+   * @return True if the swap is ready to be completed, false otherwise.
+   */
+  boolean isSwapReadyToComplete(String clusterName, String instanceName);
+
+  /**
+   * Check to see if swapping between two instances is ready to be completed 
and completed it if
+   * ready. Either the swapOut or swapIn instance can be passed in.
+   *
+   * @param clusterName  The cluster name
+   * @param instanceName The instance that is being swapped out or swapped in
+   * @return True if the swap is ready to be completed and was completed 
successfully, false
+   * otherwise.
+   */
+  boolean completeSwapIfReady(String clusterName, String instanceName);

Review Comment:
   Naming



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

Review Comment:
   Typo: 5



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