Skip to content
Permalink
Browse files
Revert and disable batch enable/disable functionality (#2134)
Revert and disable batch enable/disable functionality
Disable batch mode and remove related methods to fix backward compatibility issues introduced in 1.0.3
  • Loading branch information
qqu0127 committed Jun 3, 2022
1 parent 0f7c90b commit e84a4a7369d97212d56d4617e03147f5f18c2a8a
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 331 deletions.
@@ -302,20 +302,6 @@ void enableInstance(String clusterName, String instanceName, boolean enabled,
*/
void enableInstance(String clusterName, List<String> instances, boolean enabled);

/**
* Batch enable/disable instances in a cluster
* By default, all the instances are enabled
* @param clusterName
* @param instances
* @param enabled
* @param disabledType disabledType for disable operation. It is ignored when enabled is true.
* Existing disabledType will be over write if instance is in disabled state.
* @param reason human readable string explaining disabled reason. Ignored when enabled is true.
* Existing disabled reason will be over write if instance is in disabled state.
*/
void enableInstance(String clusterName, List<String> instances, boolean enabled,
InstanceConstants.InstanceDisabledType disabledType, String reason);

/**
* Disable or enable a resource
* @param clusterName
@@ -19,33 +19,22 @@
* under the License.
*/

import java.util.List;

import org.apache.helix.HelixDataAccessor;
import org.apache.helix.HelixManager;
import org.apache.helix.util.InstanceValidationUtil;
import sun.reflect.generics.reflectiveObjects.NotImplementedException;

/**
* A default callback implementation class to be used in {@link HelixCloudEventListener}
*/
public class DefaultCloudEventCallbackImpl {
private final String _reason =
"Cloud event callback %s in class %s triggered in listener HelixManager %s, at time %s .";
protected final String _className = this.getClass().getSimpleName();

/**
* Disable the instance
* @param manager The helix manager associated with the listener
* @param eventInfo Detailed information about the event
*/
public void disableInstance(HelixManager manager, Object eventInfo) {
if (InstanceValidationUtil
.isEnabled(manager.getHelixDataAccessor(), manager.getInstanceName())) {
HelixEventHandlingUtil
.enableInstanceForCloudEvent(manager.getClusterName(), manager.getInstanceName(), String
.format(_reason, "disableInstance", _className, manager, System.currentTimeMillis()),
false, manager.getHelixDataAccessor().getBaseDataAccessor());
}
// To be implemented
throw new NotImplementedException();
}

/**
@@ -54,49 +43,27 @@ public void disableInstance(HelixManager manager, Object eventInfo) {
* @param eventInfo Detailed information about the event
*/
public void enableInstance(HelixManager manager, Object eventInfo) {
String instanceName = manager.getInstanceName();
HelixDataAccessor accessor = manager.getHelixDataAccessor();
if (HelixEventHandlingUtil
.IsInstanceDisabledForCloudEvent(manager.getClusterName(), instanceName, accessor.getBaseDataAccessor())) {
HelixEventHandlingUtil
.enableInstanceForCloudEvent(manager.getClusterName(), manager.getInstanceName(), String
.format(_reason, "disableInstance", _className, manager, System.currentTimeMillis()),
true, manager.getHelixDataAccessor().getBaseDataAccessor());
}
// To be implemented
throw new NotImplementedException();
}

/**
* Put cluster into maintenance mode if the cluster is not currently in maintenance mode
*
* @param manager The helix manager associated with the listener
* @param eventInfo Detailed information about the event
*/
public void enterMaintenanceMode(HelixManager manager, Object eventInfo) {
if (!manager.getClusterManagmentTool().isInMaintenanceMode(manager.getClusterName())) {
manager.getClusterManagmentTool()
.manuallyEnableMaintenanceMode(manager.getClusterName(), true, String
.format(_reason, "enterMaintenanceMode", _className, manager,
System.currentTimeMillis()), null);
}
// To be implemented
throw new NotImplementedException();
}

/**
* Exit maintenance mode for the cluster, if there is no more live instances disabled for cloud event
*
* @param manager The helix manager associated with the listener
* @param eventInfo Detailed information about the event
*/
public void exitMaintenanceMode(HelixManager manager, Object eventInfo) {
List<String> instances =
manager.getClusterManagmentTool().getInstancesInCluster(manager.getClusterName());
// Check if there is any disabled live instance that was disabled due to cloud event,
// if none left, exit maintenance mode
HelixDataAccessor accessor = manager.getHelixDataAccessor();
if (instances.stream().noneMatch(instance -> HelixEventHandlingUtil
.IsInstanceDisabledForCloudEvent(manager.getClusterName(), instance, accessor.getBaseDataAccessor())
&& InstanceValidationUtil.isAlive(accessor, instance))) {
manager.getClusterManagmentTool()
.manuallyEnableMaintenanceMode(manager.getClusterName(), false, String
.format(_reason, "exitMaintenanceMode", _className, manager,
System.currentTimeMillis()), null);
}
// To be implemented
throw new NotImplementedException();
}
}
@@ -359,30 +359,19 @@ public void enableInstance(final String clusterName, final String instanceName,
// Eventually we will have all instances' enable/disable information in clusterConfig. Now we
// update both instanceConfig and clusterConfig in transition period.
enableSingleInstance(clusterName, instanceName, enabled, baseAccessor, disabledType, reason);
enableBatchInstances(clusterName, Collections.singletonList(instanceName), enabled,
baseAccessor, disabledType, reason);
// enableBatchInstances(clusterName, Collections.singletonList(instanceName), enabled,
// baseAccessor, disabledType, reason);

}

@Override
public void enableInstance(String clusterName, List<String> instances, boolean enabled,
InstanceConstants.InstanceDisabledType disabledType, String reason) {
logger.info("Batch {} instances {} in cluster {}.", enabled ? "enable" : "disable",
HelixUtil.serializeByComma(instances), clusterName);
BaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<>(_zkClient);
// Eventually we will have all instances' enable/disable information in clusterConfig. Now we
// update both instanceConfig and clusterConfig in transition period.
if (enabled) {
for (String instance : instances) {
enableSingleInstance(clusterName, instance, enabled, baseAccessor, disabledType, reason);
}
}
enableBatchInstances(clusterName, instances, enabled, baseAccessor, disabledType, reason);
}

@Override
public void enableInstance(String clusterName, List<String> instances, boolean enabled) {
enableInstance(clusterName, instances, enabled, null, null);
// TODO: batch enable/disable is breaking backward compatibility on instance enable with older library
// re-enable once batch enable/disable is ready
if (true) {
throw new HelixException("Batch enable/disable is not supported");
}
//enableInstance(clusterName, instances, enabled, null, null);
}

@Override
@@ -1918,6 +1907,11 @@ private void enableBatchInstances(final String clusterName, final List<String> i
final boolean enabled, BaseDataAccessor<ZNRecord> baseAccessor,
InstanceConstants.InstanceDisabledType disabledType, String reason) {

// TODO: batch enable/disable is breaking backward compatibility on instance enable with older library
// re-enable once batch enable/disable is ready
if (true) {
throw new HelixException("enableBatchInstances is not supported.");
}
String path = PropertyPathBuilder.clusterConfig(clusterName);

if (!baseAccessor.exists(path, 0)) {
@@ -31,7 +31,6 @@
import org.apache.helix.HelixDefinedState;
import org.apache.helix.HelixException;
import org.apache.helix.PropertyKey;
import org.apache.helix.constants.InstanceConstants;
import org.apache.helix.model.ClusterConfig;
import org.apache.helix.model.CurrentState;
import org.apache.helix.model.ExternalView;
@@ -83,37 +82,6 @@ public static boolean isEnabled(HelixDataAccessor dataAccessor, String instanceN

}

public static String getInstanceHelixDisabledType(HelixDataAccessor dataAccessor,
String instanceName) {
PropertyKey.Builder propertyKeyBuilder = dataAccessor.keyBuilder();
ClusterConfig clusterConfig = dataAccessor.getProperty(propertyKeyBuilder.clusterConfig());
if (clusterConfig == null) {
throw new HelixException("ClusterConfig is NULL");
}

String instanceDisabledTypeBatchedMode =
clusterConfig.getPlainInstanceHelixDisabledType(instanceName);
if (instanceDisabledTypeBatchedMode != null) {
return InstanceConstants.InstanceDisabledType.valueOf(instanceDisabledTypeBatchedMode)
.toString();
}
// TODO deprecate reading instance level config once migrated the enable status to cluster config only
InstanceConfig instanceConfig =
dataAccessor.getProperty(propertyKeyBuilder.instanceConfig(instanceName));
if (instanceConfig == null) {
throw new HelixException("InstanceConfig is NULL");
}

if (isInstanceEnabled(instanceConfig, clusterConfig)) {
return InstanceConstants.INSTANCE_NOT_DISABLED;
}
// It is possible that an instance is set disabled in cluster config but not in instance config.
// This instance is considered disabled. We should return a default disabled type.
return instanceConfig.getInstanceEnabled()
? InstanceConstants.InstanceDisabledType.DEFAULT_INSTANCE_DISABLE_TYPE.toString()
: instanceConfig.getInstanceDisabledType();
}

/**
* Check if the instance is enabled by configuration
* @param instanceConfig
@@ -125,12 +93,13 @@ public static boolean isInstanceEnabled(InstanceConfig instanceConfig, ClusterCo
throw new HelixException("InstanceConfig is NULL");
}
boolean enabledInInstanceConfig = instanceConfig.getInstanceEnabled();
if (clusterConfig == null) {
// TODO: batch enable/disable in cluster config is breaking backward compatibility with older library
// re-enable once batch enable/disable is ready
if (true || clusterConfig == null) {
return enabledInInstanceConfig;
}
boolean enabledInClusterConfig =
!clusterConfig.getDisabledInstances().containsKey(instanceConfig.getInstanceName())
&& !clusterConfig.getDisabledInstancesWithInfo().containsKey(instanceConfig.getInstanceName());
!clusterConfig.getDisabledInstances().containsKey(instanceConfig.getInstanceName());
return enabledInClusterConfig && enabledInInstanceConfig;
}

This file was deleted.

0 comments on commit e84a4a7

Please sign in to comment.