junkaixue commented on code in PR #2598:
URL: https://github.com/apache/helix/pull/2598#discussion_r1296456009


##########
helix-core/src/main/java/org/apache/helix/model/InstanceConfig.java:
##########
@@ -331,10 +344,17 @@ public long getInstanceEnabledTime() {
   }
 
   public void setInstanceOperation(InstanceConstants.InstanceOperation 
operation) {
-    // TODO: also setInstanceEnabled after sanity check.
+    if (operation != InstanceConstants.InstanceOperation.DISABLE
+        && operation != InstanceConstants.InstanceOperation.ENABLE) {
+      if (!getInstanceEnabled()) {
+        throw new HelixException(
+            "setting non enable/disable operation (e.g. evacuate, swap) to 
helix disabled instance is not allowed");
+      }
+    } else {
+      setInstanceEnabledHelper(operation == 
InstanceConstants.InstanceOperation.ENABLE);
+    }

Review Comment:
   can be simplified as:
   
   if (operation != InstanceConstants.InstanceOperation.DISABLE
            && operation != InstanceConstants.InstanceOperation.ENABLE && 
!getInstanceEnabled()) {
            throw new HelixException(
               XXX);
        }
   
   setInstanceEnabledHelper(operation == 
InstanceConstants.InstanceOperation.ENABLE);
   



##########
helix-core/src/main/java/org/apache/helix/model/InstanceConfig.java:
##########
@@ -264,9 +264,22 @@ public boolean getInstanceEnabled() {
    * @param enabled true to enable, false to disable
    */
   public void setInstanceEnabled(boolean enabled) {
+    // set instance operation only when we need to change InstanceEnabled 
value.
+    // When enabling an instance where HELIX_ENABLED is false, we update 
INSTANCE_OPERATION to 'ENABLE'
+    // When disabling and instance where HELIX_ENABLED is false, we overwrite 
what current operation and
+    // update INSTANCE_OPERATION to 'DISABLE'.
+    String instanceOperationKey = 
InstanceConfigProperty.INSTANCE_OPERATION.toString();
+    if (enabled != getInstanceEnabled() && 
_record.getSimpleField(instanceOperationKey) != null) {

Review Comment:
   !getInstanceEnabled()



##########
helix-core/src/main/java/org/apache/helix/model/InstanceConfig.java:
##########
@@ -264,9 +264,22 @@ public boolean getInstanceEnabled() {
    * @param enabled true to enable, false to disable
    */
   public void setInstanceEnabled(boolean enabled) {
+    // set instance operation only when we need to change InstanceEnabled 
value.
+    // When enabling an instance where HELIX_ENABLED is false, we update 
INSTANCE_OPERATION to 'ENABLE'
+    // When disabling and instance where HELIX_ENABLED is false, we overwrite 
what current operation and
+    // update INSTANCE_OPERATION to 'DISABLE'.
+    String instanceOperationKey = 
InstanceConfigProperty.INSTANCE_OPERATION.toString();
+    if (enabled != getInstanceEnabled() && 
_record.getSimpleField(instanceOperationKey) != null) {
+      _record.setSimpleField(instanceOperationKey,

Review Comment:
   I would suggest not set but use the record get with DEFAULT value as 
ENABLED. Because you may write back the enable. This is usual pattern Helix is 
trying to avoid.



##########
helix-core/src/main/java/org/apache/helix/model/InstanceConfig.java:
##########
@@ -264,9 +264,22 @@ public boolean getInstanceEnabled() {
    * @param enabled true to enable, false to disable
    */
   public void setInstanceEnabled(boolean enabled) {
+    // set instance operation only when we need to change InstanceEnabled 
value.
+    // When enabling an instance where HELIX_ENABLED is false, we update 
INSTANCE_OPERATION to 'ENABLE'
+    // When disabling and instance where HELIX_ENABLED is false, we overwrite 
what current operation and
+    // update INSTANCE_OPERATION to 'DISABLE'.
+    String instanceOperationKey = 
InstanceConfigProperty.INSTANCE_OPERATION.toString();
+    if (enabled != getInstanceEnabled() && 
_record.getSimpleField(instanceOperationKey) != null) {
+      _record.setSimpleField(instanceOperationKey,
+          enabled ? InstanceConstants.InstanceOperation.ENABLE.toString()

Review Comment:
   name() instead of toString() for Enum types



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