diff mbox series

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

Message ID 1566508103-22962-1-git-send-email-hzhou8@ebay.com
State Accepted
Commit ac3ba8c64830e20fc65ece025f2812edb75c58f2
Headers show
Series [ovs-dev,1/3] raft.c: Election timer initial reset with value from log. | expand

Commit Message

Han Zhou Aug. 22, 2019, 9:08 p.m. UTC
From: Han Zhou <hzhou8@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@ebay.com>
---
 ovsdb/raft.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Comments

Ben Pfaff Aug. 23, 2019, 9:43 p.m. UTC | #1
On Thu, Aug 22, 2019 at 02:08:21PM -0700, Han Zhou wrote:
> From: Han Zhou <hzhou8@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@ebay.com>

Thanks for the fixes.

I applied these to master and branch-2.12.
diff mbox series

Patch

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)
     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;