]> git.proxmox.com Git - mirror_ovs.git/commitdiff
raft.c: Election timer initial reset with value from log.
authorHan Zhou <hzhou8@ebay.com>
Thu, 22 Aug 2019 21:08:21 +0000 (14:08 -0700)
committerBen Pfaff <blp@ovn.org>
Fri, 23 Aug 2019 21:42:57 +0000 (14:42 -0700)
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@ebay.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
ovsdb/raft.c

index 796790e18ee2b8299364cdaa4e5176531e92c77f..9eabe2cfeecd7068ac73360b8c55a0f92efc0866 100644 (file)
@@ -404,8 +404,6 @@ raft_alloc(void)
     hmap_init(&raft->commands);
 
     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;