[ovs-dev] [PATCH 1/3] raft.c: Election timer initial reset with value from log.

Han Zhou zhouhan at gmail.com
Thu Aug 22 21:08:21 UTC 2019

From: Han Zhou <hzhou8 at ebay.com>

After election timer is changed through cluster/change-election-timer
command, if a server restarts, it firstly initializes with the default
value and use it to reset the timer. Although it reads the latest
timer value later from the log, the first timeout may be much shorter
than expected by other servers that use latest timeout, and it would
start election before it receives the first heartbeat from the leader.

This patch fixes it by changing the order of reading log and resetting
timer so that the latest value is read from the log before the initial
resetting of the timer.

Fixes: commit 8e35461 ("ovsdb raft: Support leader election time change online.")
Signed-off-by: Han Zhou <hzhou8 at ebay.com>
 ovsdb/raft.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/ovsdb/raft.c b/ovsdb/raft.c
index 796790e..9eabe2c 100644
--- a/ovsdb/raft.c
+++ b/ovsdb/raft.c
@@ -404,8 +404,6 @@ raft_alloc(void)
     raft->election_timer = ELECTION_BASE_MSEC;
-    raft_reset_ping_timer(raft);
-    raft_reset_election_timer(raft);
     return raft;
@@ -970,6 +968,9 @@ raft_open(struct ovsdb_log *log, struct raft **raftp)
         raft->join_timeout = time_msec() + 1000;
+    raft_reset_ping_timer(raft);
+    raft_reset_election_timer(raft);
     *raftp = raft;
     hmap_insert(&all_rafts, &raft->hmap_node, hash_string(raft->name, 0));
     return NULL;

More information about the dev mailing list