You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@helix.apache.org by "junkaixue (via GitHub)" <gi...@apache.org> on 2023/09/19 04:31:13 UTC
[GitHub] [helix] junkaixue commented on a diff in pull request #2618: Add supporting APIs for evacuation
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: reviews-unsubscribe@helix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org