Repository: JDRaftKeeper/RaftKeeper (language: cpp)

Issue:
Reduce the default timeout value since we now support async snapshot
### Description
<!-- Describe the enhancement you want, including the motivation. -->
Reduce the default timeout value, since we now support async snapshot, 60 million nodes only block user request 3.5 seconds(when creating snapshot), down from the default 3 seconds (same with NuRaft default timeout).
### Are you willing to submit PR?



Discussion / hints:

Fix patch:
diff --git a/docs/how-to-monitor-and-manage.md b/docs/how-to-monitor-and-manage.md
index 6f9637ff8d..af6497d479 100644
--- a/docs/how-to-monitor-and-manage.md
+++ b/docs/how-to-monitor-and-manage.md
@@ -179,14 +179,14 @@ snapshot_create_interval=3600
 four_letter_word_white_list=conf,cons,crst,envi,ruok,srst,srvr,stat,wchs,dirs,mntr,isro,lgif,rqld,uptm,csnp
 log_dir=/data/jdolap/raft_service/raft_log
 snapshot_dir=/data/jdolap/raft_service/raft_snapshot
-max_session_timeout_ms=100000
-min_session_timeout_ms=10000
-operation_timeout_ms=10000
+max_session_timeout_ms=3600000
+min_session_timeout_ms=1000
+operation_timeout_ms=3000
 dead_session_check_period_ms=500
 heart_beat_interval_ms=500
-client_req_timeout_ms=10000
-election_timeout_lower_bound_ms=10000
-election_timeout_upper_bound_ms=20000
+client_req_timeout_ms=3000
+election_timeout_lower_bound_ms=3000
+election_timeout_upper_bound_ms=5000
 reserved_log_items=1000000
 snapshot_distance=3000000
 max_stored_snapshots=5
diff --git a/programs/server/config.xml b/programs/server/config.xml
index 7d372bd94b..ecbb3bf0e8 100644
--- a/programs/server/config.xml
+++ b/programs/server/config.xml
@@ -62,14 +62,14 @@
 
         <!-- NuRaft related settings -->
         <raft_settings>
-            <!-- User minimum session timeout in millisecond, default is 10000. -->
-            <!-- <min_session_timeout_ms>10000</min_session_timeout_ms> -->
+            <!-- User minimum session timeout in millisecond, default is 1000. -->
+            <!-- <min_session_timeout_ms>1000</min_session_timeout_ms> -->
 
-            <!-- User maximum session timeout in millisecond, default is 100000. -->
-            <!-- <max_session_timeout_ms>100000</max_session_timeout_ms> -->
+            <!-- User maximum session timeout in millisecond, default is 3600000. -->
+            <!-- <max_session_timeout_ms>3600000</max_session_timeout_ms> -->
 
-            <!-- User operation timeout in millisecond, default is 10000. -->
-            <!-- <operation_timeout_ms>10000</operation_timeout_ms> -->
+            <!-- User operation timeout in millisecond, default is 3000. -->
+            <!-- <operation_timeout_ms>3000</operation_timeout_ms> -->
 
             <!-- Leader will check whether session is dead in this period, default is 500. -->
             <!-- <dead_session_check_period_ms>500</dead_session_check_period_ms> -->
@@ -78,13 +78,13 @@
             <!-- <heart_beat_interval_ms>500</heart_beat_interval_ms> -->
 
             <!-- NuRaft log replication timeout in millisecond, default is same with operation_timeout_ms. -->
-            <!-- <client_req_timeout_ms>10000</client_req_timeout_ms> -->
+            <!-- <client_req_timeout_ms>3000</client_req_timeout_ms> -->
 
-            <!-- NuRaft election timeout lower bound, default is 10s. -->
-            <!-- <election_timeout_lower_bound_ms>10000</election_timeout_lower_bound_ms> -->
+            <!-- NuRaft election timeout lower bound, default is 3s. -->
+            <!-- <election_timeout_lower_bound_ms>3000/election_timeout_lower_bound_ms> -->
 
-            <!-- NuRaft election timeout upper bound, default is 20s. -->
-            <!-- <election_timeout_upper_bound_ms>20000</election_timeout_upper_bound_ms> -->
+            <!-- NuRaft election timeout upper bound, default is 5s. -->
+            <!-- <election_timeout_upper_bound_ms>5000</election_timeout_upper_bound_ms> -->
 
             <!-- Keeper will keep at least this log item, default 1_000_000. -->
             <!-- <reserved_log_items>1000000</reserved_log_items> -->
diff --git a/src/Service/Settings.cpp b/src/Service/Settings.cpp
index 93bb8939e6..614a8649cd 100644
--- a/src/Service/Settings.cpp
+++ b/src/Service/Settings.cpp
@@ -73,8 +73,8 @@ void RaftSettings::loadFromConfig(const String & config_elem, const Poco::Util::
         dead_session_check_period_ms = config.getUInt(get_key("dead_session_check_period_ms"), 500);
         heart_beat_interval_ms = config.getUInt(get_key("heart_beat_interval_ms"), 500);
         client_req_timeout_ms = config.getUInt(get_key("client_req_timeout_ms"), operation_timeout_ms);
-        election_timeout_lower_bound_ms = config.getUInt(get_key("election_timeout_lower_bound_ms"), 10000);
-        election_timeout_upper_bound_ms = config.getUInt(get_key("election_timeout_upper_bound_ms"), 20000);
+        election_timeout_lower_bound_ms = config.getUInt(get_key("election_timeout_lower_bound_ms"), Coordination::ELECTION_TIMEOUT_LOWER_BOUND_MS);
+        election_timeout_upper_bound_ms = config.getUInt(get_key("election_timeout_upper_bound_ms"), Coordination::ELECTION_TIMEOUT_UPPER_BOUND_MS);
         reserved_log_items = config.getUInt(get_key("reserved_log_items"), 1000000);
         snapshot_distance = config.getUInt(get_key("snapshot_distance"), 3000000);
         max_stored_snapshots = config.getUInt(get_key("max_stored_snapshots"), 5);
@@ -109,8 +109,8 @@ RaftSettingsPtr RaftSettings::getDefault()
     settings->dead_session_check_period_ms = 500;
     settings->heart_beat_interval_ms = 500;
     settings->client_req_timeout_ms = settings->operation_timeout_ms;
-    settings->election_timeout_lower_bound_ms = 10000;
-    settings->election_timeout_upper_bound_ms = 20000;
+    settings->election_timeout_lower_bound_ms = Coordination::ELECTION_TIMEOUT_LOWER_BOUND_MS;
+    settings->election_timeout_upper_bound_ms = Coordination::ELECTION_TIMEOUT_UPPER_BOUND_MS;
     settings->reserved_log_items = 10000000;
     settings->snapshot_distance = 3000000;
     settings->max_stored_snapshots = 5;
diff --git a/src/ZooKeeper/ZooKeeperConstants.h b/src/ZooKeeper/ZooKeeperConstants.h
index 681c63a8cd..d3266b72f2 100644
--- a/src/ZooKeeper/ZooKeeperConstants.h
+++ b/src/ZooKeeper/ZooKeeperConstants.h
@@ -59,8 +59,10 @@ static constexpr int32_t PASSWORD_LENGTH = 16;
 /// but it can be raised up, so we have a slightly larger limit on our side.
 static constexpr int32_t MAX_STRING_OR_ARRAY_SIZE = 1 << 28; /// 256 MiB
 static constexpr int32_t DEFAULT_SESSION_TIMEOUT_MS = 30000;
-static constexpr int32_t DEFAULT_MIN_SESSION_TIMEOUT_MS = 10000;
-static constexpr int32_t DEFAULT_MAX_SESSION_TIMEOUT_MS = 100000;
-static constexpr int32_t DEFAULT_OPERATION_TIMEOUT_MS = 10000;
+static constexpr int32_t DEFAULT_MIN_SESSION_TIMEOUT_MS = 1000;
+static constexpr int32_t DEFAULT_MAX_SESSION_TIMEOUT_MS = 3600000;
+static constexpr int32_t DEFAULT_OPERATION_TIMEOUT_MS = 3000;
+static constexpr int32_t ELECTION_TIMEOUT_LOWER_BOUND_MS = 3000;
+static constexpr int32_t ELECTION_TIMEOUT_UPPER_BOUND_MS = 5000;
 
 }


Test patch:
diff --git a/tests/integration/helpers/0_common_instance_config.xml b/tests/integration/helpers/0_common_instance_config.xml
index aba23b8a0f..24d043a4bc 100644
--- a/tests/integration/helpers/0_common_instance_config.xml
+++ b/tests/integration/helpers/0_common_instance_config.xml
@@ -1,8 +1,8 @@
 <raftkeeper>
     <keeper>
         <raft_settings>
-            <election_timeout_lower_bound_ms>5000</election_timeout_lower_bound_ms>
-            <election_timeout_upper_bound_ms>10000</election_timeout_upper_bound_ms>
+            <election_timeout_lower_bound_ms>3000</election_timeout_lower_bound_ms>
+            <election_timeout_upper_bound_ms>5000</election_timeout_upper_bound_ms>
         </raft_settings>
     </keeper>
 </raftkeeper>
diff --git a/tests/integration/test_four_word_command/test.py b/tests/integration/test_four_word_command/test.py
index 54c56a5011..51bbb2d041 100644
--- a/tests/integration/test_four_word_command/test.py
+++ b/tests/integration/test_four_word_command/test.py
@@ -295,8 +295,8 @@ def test_cmd_conf(started_cluster):
         assert result["operation_timeout_ms"] == "1000"
         assert result["dead_session_check_period_ms"] == "500"
         assert result["heart_beat_interval_ms"] == "500"
-        assert result["election_timeout_lower_bound_ms"] == "5000"
-        assert result["election_timeout_upper_bound_ms"] == "10000"
+        assert result["election_timeout_lower_bound_ms"] == "3000"
+        assert result["election_timeout_upper_bound_ms"] == "5000"
 
         assert result["reserved_log_items"] == "1000000"
         assert result["snapshot_distance"] == "3000000"
diff --git a/tests/integration/test_session_fake_client/test.py b/tests/integration/test_session_fake_client/test.py
index cf60d6e5ed..00fff557e8 100644
--- a/tests/integration/test_session_fake_client/test.py
+++ b/tests/integration/test_session_fake_client/test.py
@@ -230,8 +230,8 @@ def test_invalid_timeout_setting(started_cluster):
             result[row[0]] = row[1]
 
     assert result['operation_timeout_ms'] == '1000'
-    assert result['min_session_timeout_ms'] == '10000'
-    assert result['max_session_timeout_ms'] == '100000'
+    assert result['min_session_timeout_ms'] == '1000'
+    assert result['max_session_timeout_ms'] == '3600000'
 
     node1.stop_raftkeeper()
     time.sleep(3)