This is an automated email from the ASF dual-hosted git repository.
hzlu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/helix.git
The following commit(s) were added to refs/heads/master by this push:
new e391119 Add offline node purge timeout in cluster config (#1485)
e391119 is described below
commit e391119f82b1fe4e182c753fc48782224389bebc
Author: Meng Zhang <[email protected]>
AuthorDate: Tue Oct 27 14:02:07 2020 -0700
Add offline node purge timeout in cluster config (#1485)
Add offline node purge timeout in cluster config
---
.../java/org/apache/helix/model/ClusterConfig.java | 33 ++++++++++++++++++++--
.../org/apache/helix/model/TestClusterConfig.java | 23 +++++++++++++++
2 files changed, 53 insertions(+), 3 deletions(-)
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 66b1a98..ef87542 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
@@ -128,7 +128,13 @@ public class ClusterConfig extends HelixProperty {
// offline for more than this specified time period, it's treated as
offline for the rest of
// the maintenance mode's duration even when it comes online.
// The unit is milliseconds.
- OFFLINE_NODE_TIME_OUT_FOR_MAINTENANCE_MODE
+ OFFLINE_NODE_TIME_OUT_FOR_MAINTENANCE_MODE,
+
+ // The time out window for offline nodes to be purged; if an offline node
has been
+ // offline for more than this specified time period, and users call purge
participant API,
+ // then the node will be removed.
+ // The unit is milliseconds.
+ OFFLINE_NODE_TIME_OUT_FOR_PURGE
}
public enum GlobalRebalancePreferenceKey {
@@ -157,7 +163,7 @@ public class ClusterConfig extends HelixProperty {
private final static int MIN_REBALANCE_PREFERENCE = 0;
public final static boolean DEFAULT_GLOBAL_REBALANCE_ASYNC_MODE_ENABLED =
true;
private static final int GLOBAL_TARGET_TASK_THREAD_POOL_SIZE_NOT_SET = -1;
- private static final long OFFLINE_NODE_TIME_OUT_FOR_MAINTENANCE_MODE_NOT_SET
= -1;
+ private static final long VALUE_NOT_SET = -1;
/**
* Instantiate for a specific cluster
@@ -934,7 +940,28 @@ public class ClusterConfig extends HelixProperty {
public long getOfflineNodeTimeOutForMaintenanceMode() {
return _record
.getLongField(ClusterConfigProperty.OFFLINE_NODE_TIME_OUT_FOR_MAINTENANCE_MODE.name(),
- OFFLINE_NODE_TIME_OUT_FOR_MAINTENANCE_MODE_NOT_SET);
+ VALUE_NOT_SET);
+ }
+
+ /**
+ * Set the default time out window for offline nodes to be purged. If an
offline node has been
+ * offline for more than this specified time period, when users call purge
participants API,
+ * the node will be dropped.
+ * @param timeOut timeout window in milliseconds.
+ */
+ public void setOfflineNodeTimeOutForPurge(long timeOut) {
+
_record.setLongField(ClusterConfigProperty.OFFLINE_NODE_TIME_OUT_FOR_PURGE.name(),
+ timeOut);
+ }
+
+ /**
+ * Get the default time out window for offline nodes to be purged.
+ * @return timeout window in milliseconds
+ */
+ public long getOfflineNodeTimeOutForPurge() {
+ return _record
+
.getLongField(ClusterConfigProperty.OFFLINE_NODE_TIME_OUT_FOR_PURGE.name(),
+ VALUE_NOT_SET);
}
/**
diff --git
a/helix-core/src/test/java/org/apache/helix/model/TestClusterConfig.java
b/helix-core/src/test/java/org/apache/helix/model/TestClusterConfig.java
index 7ef1fa2..a9c26bf 100644
--- a/helix-core/src/test/java/org/apache/helix/model/TestClusterConfig.java
+++ b/helix-core/src/test/java/org/apache/helix/model/TestClusterConfig.java
@@ -320,6 +320,29 @@ public class TestClusterConfig {
-1), 10000L);
}
+
+ @Test
+ public void testGetOfflineNodeTimeOutForPurge() {
+ ClusterConfig testConfig = new ClusterConfig("testId");
+ Assert.assertEquals(testConfig.getOfflineNodeTimeOutForPurge(), -1);
+
+ testConfig.getRecord()
+
.setLongField(ClusterConfig.ClusterConfigProperty.OFFLINE_NODE_TIME_OUT_FOR_PURGE
+ .name(),
+ 10000L);
+ Assert.assertEquals(testConfig.getOfflineNodeTimeOutForPurge(), 10000L);
+ }
+
+ @Test
+ public void testSetOfflineNodeTimeOutForPurge() {
+ ClusterConfig testConfig = new ClusterConfig("testId");
+ testConfig.setOfflineNodeTimeOutForPurge(10000L);
+ Assert.assertEquals(testConfig.getRecord()
+
.getLongField(ClusterConfig.ClusterConfigProperty.OFFLINE_NODE_TIME_OUT_FOR_PURGE
+ .name(),
+ -1), 10000L);
+ }
+
@Test
public void testAbnormalStatesResolverConfig() {
ClusterConfig testConfig = new ClusterConfig("testConfig");