From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtpng3.m.smailru.net (smtpng3.m.smailru.net [94.100.177.149]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 330DB45C30B for ; Fri, 20 Nov 2020 02:46:25 +0300 (MSK) From: Vladislav Shpilevoy Date: Fri, 20 Nov 2020 00:46:06 +0100 Message-Id: <5a1915c39df4118bdeeed55bf9885556472ddd6c.1605829282.git.v.shpilevoy@tarantool.org> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH v2 03/16] raft: stop using replication_disconnect_timeout() List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: tarantool-patches@dev.tarantool.org, sergepetrenko@tarantool.org Raft is being moved to a separate library in src/lib. It means, it can't depend on anything from box/, including global replication parameters such as replication_timeout, and functions like replication_disconnect_timeout(). The patch makes raft stop using replication_disconnect_timeout(). Instead, it stores death timeout in struct raft. It is configured by box simultaneously with replication_timeout. Part of #5303 --- src/box/box.cc | 2 +- src/box/raftlib.c | 13 ++++++------- src/box/raftlib.h | 10 +++++++--- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/box/box.cc b/src/box/box.cc index 8dd92a5f5..25673ed42 100644 --- a/src/box/box.cc +++ b/src/box/box.cc @@ -890,7 +890,7 @@ void box_set_replication_timeout(void) { replication_timeout = box_check_replication_timeout(); - raft_cfg_death_timeout(box_raft()); + raft_cfg_death_timeout(box_raft(), replication_disconnect_timeout()); } void diff --git a/src/box/raftlib.c b/src/box/raftlib.c index 3867c63e0..c156d6f46 100644 --- a/src/box/raftlib.c +++ b/src/box/raftlib.c @@ -804,8 +804,7 @@ raft_sm_wait_leader_dead(struct raft *raft) assert(raft->is_candidate); assert(raft->state == RAFT_STATE_FOLLOWER); assert(raft->leader != 0); - double death_timeout = replication_disconnect_timeout(); - ev_timer_set(&raft->timer, death_timeout, death_timeout); + ev_timer_set(&raft->timer, raft->death_timeout, raft->death_timeout); ev_timer_start(loop(), &raft->timer); } @@ -817,8 +816,7 @@ raft_sm_wait_leader_found(struct raft *raft) assert(raft->is_candidate); assert(raft->state == RAFT_STATE_FOLLOWER); assert(raft->leader == 0); - double death_timeout = replication_disconnect_timeout(); - ev_timer_set(&raft->timer, death_timeout, death_timeout); + ev_timer_set(&raft->timer, raft->death_timeout, raft->death_timeout); ev_timer_start(loop(), &raft->timer); } @@ -1012,14 +1010,14 @@ raft_cfg_election_quorum(struct raft *raft) } void -raft_cfg_death_timeout(struct raft *raft) +raft_cfg_death_timeout(struct raft *raft, double death_timeout) { + raft->death_timeout = death_timeout; if (raft->state == RAFT_STATE_FOLLOWER && raft->is_candidate && raft->leader != 0) { assert(ev_is_active(&raft->timer)); - double death_timeout = replication_disconnect_timeout(); double timeout = ev_timer_remaining(loop(), &raft->timer) - - raft->timer.at + death_timeout; + raft->timer.at + raft->death_timeout; ev_timer_stop(loop(), &raft->timer); ev_timer_set(&raft->timer, timeout, timeout); ev_timer_start(loop(), &raft->timer); @@ -1080,6 +1078,7 @@ raft_create(struct raft *raft) .volatile_term = 1, .term = 1, .election_timeout = 5, + .death_timeout = 5, }; ev_timer_init(&raft->timer, raft_sm_schedule_new_election_cb, 0, 0); raft->timer.data = raft; diff --git a/src/box/raftlib.h b/src/box/raftlib.h index 805f69d64..b33a20326 100644 --- a/src/box/raftlib.h +++ b/src/box/raftlib.h @@ -156,6 +156,11 @@ struct raft { struct fiber *worker; /** Configured election timeout in seconds. */ double election_timeout; + /** + * Leader death timeout, after which it is considered dead and new + * elections can be started. + */ + double death_timeout; /** * Trigger invoked each time any of the Raft node visible attributes are * changed. @@ -229,11 +234,10 @@ raft_cfg_election_quorum(struct raft *raft); /** * Configure Raft leader death timeout. I.e. number of seconds without - * heartbeats from the leader to consider it dead. There is no a separate - * option. Raft uses replication timeout for that. + * heartbeats from the leader to consider it dead. */ void -raft_cfg_death_timeout(struct raft *raft); +raft_cfg_death_timeout(struct raft *raft, double death_timeout); /** * Bump the term. When it is persisted, the node checks if there is a leader, -- 2.24.3 (Apple Git-128)