You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ea...@apache.org on 2019/04/08 12:01:38 UTC

[incubator-iotdb] branch cluster updated: add config for raft election timeout

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

east pushed a commit to branch cluster
in repository https://gitbox.apache.org/repos/asf/incubator-iotdb.git


The following commit(s) were added to refs/heads/cluster by this push:
     new 3591574  add config for raft election timeout
3591574 is described below

commit 3591574e67703dea97ae29a90034872934ec827f
Author: mdf369 <95...@qq.com>
AuthorDate: Mon Apr 8 20:01:17 2019 +0800

    add config for raft election timeout
---
 .../org/apache/iotdb/cluster/config/ClusterConfig.java    | 15 +++++++++++++++
 .../apache/iotdb/cluster/config/ClusterDescriptor.java    |  4 ++++
 .../org/apache/iotdb/cluster/entity/raft/RaftService.java |  1 +
 iotdb/iotdb/conf/iotdb-cluster.properties                 |  5 +++++
 4 files changed, 25 insertions(+)

diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/config/ClusterConfig.java b/cluster/src/main/java/org/apache/iotdb/cluster/config/ClusterConfig.java
index baf55b7..40a20ef 100644
--- a/cluster/src/main/java/org/apache/iotdb/cluster/config/ClusterConfig.java
+++ b/cluster/src/main/java/org/apache/iotdb/cluster/config/ClusterConfig.java
@@ -70,6 +70,13 @@ public class ClusterConfig {
   private String raftMetadataPath;
 
   /**
+   * A follower would become a candidate if it doesn't receive any message
+   * from the leader in {@code electionTimeoutMs} milliseconds
+   * Default: 1000 (1s)
+   */
+  private int electionTimeoutMs = 1000;
+
+  /**
    * When the number of the difference between leader and follower log is less than this value, it
    * is considered as 'catch-up'
    */
@@ -211,6 +218,14 @@ public class ClusterConfig {
     this.raftMetadataPath = raftMetadataPath;
   }
 
+  public int getElectionTimeoutMs() {
+    return electionTimeoutMs;
+  }
+
+  public void setElectionTimeoutMs(int electionTimeoutMs) {
+    this.electionTimeoutMs = electionTimeoutMs;
+  }
+
   public int getMaxCatchUpLogNum() {
     return maxCatchUpLogNum;
   }
diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/config/ClusterDescriptor.java b/cluster/src/main/java/org/apache/iotdb/cluster/config/ClusterDescriptor.java
index 6ee00f4..ba7d4a1 100644
--- a/cluster/src/main/java/org/apache/iotdb/cluster/config/ClusterDescriptor.java
+++ b/cluster/src/main/java/org/apache/iotdb/cluster/config/ClusterDescriptor.java
@@ -109,6 +109,10 @@ public class ClusterDescriptor {
       conf.setRaftMetadataPath(properties.getProperty("raft_metadata_path", conf.getRaftMetadataPath()));
 
       conf.setMaxCatchUpLogNum(Integer
+          .parseInt(properties.getProperty("election_timeout_ms",
+              Integer.toString(conf.getElectionTimeoutMs()))));
+
+      conf.setMaxCatchUpLogNum(Integer
           .parseInt(properties.getProperty("max_catch_up_log_num",
               Integer.toString(conf.getMaxCatchUpLogNum()))));
 
diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/entity/raft/RaftService.java b/cluster/src/main/java/org/apache/iotdb/cluster/entity/raft/RaftService.java
index d05725f..8e8dc4e 100644
--- a/cluster/src/main/java/org/apache/iotdb/cluster/entity/raft/RaftService.java
+++ b/cluster/src/main/java/org/apache/iotdb/cluster/entity/raft/RaftService.java
@@ -60,6 +60,7 @@ public class RaftService implements IService {
     nodeOptions.setLogUri(FilePathUtils.regularizePath(config.getRaftLogPath()) + groupId);
     nodeOptions.setRaftMetaUri(FilePathUtils.regularizePath(config.getRaftMetadataPath()) + groupId);
     nodeOptions.setSnapshotUri(FilePathUtils.regularizePath(config.getRaftSnapshotPath()) + groupId);
+    nodeOptions.setElectionTimeoutMs(config.getElectionTimeoutMs());
     final Configuration initConf = new Configuration();
     initConf.setPeers(peerIdList);
     nodeOptions.setInitialConf(initConf);
diff --git a/iotdb/iotdb/conf/iotdb-cluster.properties b/iotdb/iotdb/conf/iotdb-cluster.properties
index fe6e83e..dab4c7c 100644
--- a/iotdb/iotdb/conf/iotdb-cluster.properties
+++ b/iotdb/iotdb/conf/iotdb-cluster.properties
@@ -35,6 +35,11 @@ port = 8888
 
 #raft_metadata_path = /tmp/raft/metadata/
 
+
+# A follower would become a candidate if it doesn't receive any message
+# from the leader in election_timeout_ms milliseconds
+election_timeout_ms = 1000
+
 # When the number of the difference between leader and follower log is less than this value, it
 # is considered as 'catch-up'
 max_catch_up_log_num = 100000