zpinto commented on code in PR #2661:
URL: https://github.com/apache/helix/pull/2661#discussion_r1367174009
##########
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:
I don't think this will work in every case because the ideal state is not
persisted in ZK without PERSIST_BEST_POSSIBLE_STATE set to true. I think that
only checking current state and no pending messages is sufficient because if
the replica from the ideal state is not already being bootstrapped on SWAP_OUT
node then it will be sent directly to SWAP_IN node right after the swap
completes.
If load balance is causing the new replica to be assigned to SWAP_OUT node
then if the ST message never gets to the SWAP_OUT node before completing the
SWAP it is okay because once we switch to the SWAP_IN node we have not dropped
the replica from its old location yet.
This means that it will still be N -> N+1 -> N for the newly assigned
replica.
--
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]