This is an automated email from the ASF dual-hosted git repository.

jxue pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/helix.git

commit 9d896ece612a390a0df17c6b4a0c097f8224c085
Author: narendly <[email protected]>
AuthorDate: Mon Feb 25 18:04:32 2019 -0800

    HELIX: Add maintenance recovery threshold field to ClusterConfig
    
    This new field will serve as the threshold against which the Controller 
will decide whether a cluster has recovered sufficiently for it to auto-exit 
maintenance mode.
    Changelist:
    1. Add the field
    2. Add getters and setters with sanity checks (Maintenance recovery 
threshold <= max. offline/disabled instances)
---
 .../java/org/apache/helix/model/ClusterConfig.java | 35 ++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/helix-core/src/main/java/org/apache/helix/model/ClusterConfig.java 
b/helix-core/src/main/java/org/apache/helix/model/ClusterConfig.java
index b996007..920bd6a 100644
--- a/helix-core/src/main/java/org/apache/helix/model/ClusterConfig.java
+++ b/helix-core/src/main/java/org/apache/helix/model/ClusterConfig.java
@@ -25,6 +25,7 @@ import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import org.apache.helix.HelixException;
 import org.apache.helix.HelixProperty;
 import org.apache.helix.ZNRecord;
 import org.apache.helix.api.config.HelixConfigProperty;
@@ -59,8 +60,13 @@ public class ClusterConfig extends HelixProperty {
     RESOURCE_PRIORITY_FIELD,
     REBALANCE_TIMER_PERIOD,
     MAX_CONCURRENT_TASK_PER_INSTANCE,
+
+    // The following concerns maintenance mode
     MAX_PARTITIONS_PER_INSTANCE,
+    // The following two include offline AND disabled instances
     MAX_OFFLINE_INSTANCES_ALLOWED,
+    NUM_OFFLINE_INSTANCES_FOR_AUTO_EXIT, // For auto-exiting maintenance mode
+
     TARGET_EXTERNALVIEW_ENABLED,
     @Deprecated // ERROR_OR_RECOVERY_PARTITION_THRESHOLD_FOR_LOAD_BALANCE will 
take
         // precedence if it is set
@@ -409,6 +415,35 @@ public class ClusterConfig extends HelixProperty {
   }
 
   /**
+   * Sets Maintenance recovery threshold so that the cluster could auto-exit 
maintenance mode.
+   * Values less than 0 will disable auto-exit.
+   * @param maintenanceRecoveryThreshold
+   */
+  public void setMaintenanceRecoveryThreshold(int maintenanceRecoveryThreshold)
+      throws HelixException {
+    int maxOfflineInstancesAllowed = getMaxOfflineInstancesAllowed();
+    if (maxOfflineInstancesAllowed >= 0) {
+      // MaintenanceRecoveryThreshold must be more strict than 
maxOfflineInstancesAllowed
+      if (maintenanceRecoveryThreshold > maxOfflineInstancesAllowed) {
+        throw new HelixException(
+            "Maintenance recovery threshold must be less than equal to maximum 
offline instances allowed!");
+      }
+    }
+    
_record.setIntField(ClusterConfigProperty.NUM_OFFLINE_INSTANCES_FOR_AUTO_EXIT.name(),
+        maintenanceRecoveryThreshold);
+  }
+
+  /**
+   * Returns Maintenance recovery threshold. In order for the cluster to 
auto-exit maintenance mode,
+   * the number of offline/disabled instances must be less than or equal to 
this threshold.
+   * -1 indicates that there will be no auto-exit.
+   * @return
+   */
+  public int getMaintenanceRecoveryThreshold() {
+    return 
_record.getIntField(ClusterConfigProperty.NUM_OFFLINE_INSTANCES_FOR_AUTO_EXIT.name(),
 -1);
+  }
+
+  /**
    * Set the resource prioritization field. It should be Integer field and 
sortable.
    *
    * IMPORTANT: The sorting order is DESCENDING order, which means the larger 
number will have

Reply via email to