From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org> To: tarantool-patches@dev.tarantool.org, sergepetrenko@tarantool.org Subject: [Tarantool-patches] [PATCH v2 07/16] raft: stop using replicaset.vclock Date: Fri, 20 Nov 2020 00:46:10 +0100 [thread overview] Message-ID: <9d1d5336080ed8ce1ab264bbec071ae0cacebabe.1605829282.git.v.shpilevoy@tarantool.org> (raw) In-Reply-To: <cover.1605829282.git.v.shpilevoy@tarantool.org> Raft is being moved to a separate library in src/lib. It means, it can't depend on anything from box/. The patch makes raft stop using replicaset.vclock. Instead, it has a new option 'vclock'. It is stored inside struct raft by pointer and should be configured using raft_cfg_vclock(). Box configures it to point at replicaset.vclock like before. But now raftlib code does not depend on it explicitly. Vclock is stored in Raft by pointer instead of by value so as not to update it for each transaction. It would be too high price to pay for Raft independence from box. Part of #5303 --- src/box/box.cc | 1 + src/box/raftlib.c | 15 +++++++++++---- src/box/raftlib.h | 16 ++++++++++++++++ 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/box/box.cc b/src/box/box.cc index 043a37658..837fbd2e5 100644 --- a/src/box/box.cc +++ b/src/box/box.cc @@ -2768,6 +2768,7 @@ box_cfg_xc(void) */ if (!replication_anon) raft_cfg_instance_id(box_raft(), instance_id); + raft_cfg_vclock(box_raft(), &replicaset.vclock); if (box_set_election_timeout() != 0) diag_raise(); diff --git a/src/box/raftlib.c b/src/box/raftlib.c index 78164bf91..ab2e27fd8 100644 --- a/src/box/raftlib.c +++ b/src/box/raftlib.c @@ -125,8 +125,7 @@ raft_new_random_election_shift(const struct raft *raft) static inline bool raft_can_vote_for(const struct raft *raft, const struct vclock *v) { - (void)raft; - int cmp = vclock_compare_ignore0(v, &replicaset.vclock); + int cmp = vclock_compare_ignore0(v, raft->vclock); return cmp == 0 || cmp == 1; } @@ -597,7 +596,7 @@ raft_worker_handle_broadcast(struct raft *raft) req.state = raft->state; if (req.state == RAFT_STATE_CANDIDATE) { assert(raft->vote == raft->self); - req.vclock = &replicaset.vclock; + req.vclock = raft->vclock; } replicaset_foreach(replica) relay_push_raft(replica->relay, &req); @@ -865,7 +864,7 @@ raft_serialize_for_network(const struct raft *raft, struct raft_request *req) * Vclock is sent out only by candidate instances. */ if (req->state == RAFT_STATE_CANDIDATE) - req->vclock = &replicaset.vclock; + req->vclock = raft->vclock; } void @@ -984,6 +983,14 @@ raft_cfg_instance_id(struct raft *raft, uint32_t instance_id) raft->self = instance_id; } +void +raft_cfg_vclock(struct raft *raft, const struct vclock *vclock) +{ + assert(raft->vclock == NULL); + assert(vclock != NULL); + raft->vclock = vclock; +} + void raft_new_term(struct raft *raft) { diff --git a/src/box/raftlib.h b/src/box/raftlib.h index 2da3cec86..8d0d03da0 100644 --- a/src/box/raftlib.h +++ b/src/box/raftlib.h @@ -154,6 +154,15 @@ struct raft { int vote_count; /** Number of votes necessary for successful election. */ int election_quorum; + /** + * Vclock of the Raft node owner. Raft never changes it, only watches, + * and makes decisions based on it. The value is not stored by copy so + * as to avoid frequent updates. If every transaction would need to + * update several vclocks in different places, it would be too + * expensive. So they update only one vclock, which is shared between + * subsystems, such as Raft. + */ + const struct vclock *vclock; /** State machine timed event trigger. */ struct ev_timer timer; /** Worker fiber to execute blocking tasks like IO. */ @@ -250,6 +259,13 @@ raft_cfg_death_timeout(struct raft *raft, double death_timeout); void raft_cfg_instance_id(struct raft *raft, uint32_t instance_id); +/** + * Configure vclock of the given Raft instance. The vclock is not copied, so the + * caller must keep it valid. + */ +void +raft_cfg_vclock(struct raft *raft, const struct vclock *vclock); + /** * Bump the term. When it is persisted, the node checks if there is a leader, * and if there is not, a new election is started. That said, this function can -- 2.24.3 (Apple Git-128)
next prev parent reply other threads:[~2020-11-19 23:46 UTC|newest] Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-11-19 23:45 [Tarantool-patches] [PATCH v2 00/16] Raft module, part 2 - relocation to src/lib/raft Vladislav Shpilevoy 2020-11-19 23:45 ` [Tarantool-patches] [PATCH v2 01/16] raft: move sources to raftlib.h/.c Vladislav Shpilevoy 2020-11-19 23:45 ` [Tarantool-patches] [PATCH v2 10/16] raft: make worker non-cancellable during WAL write Vladislav Shpilevoy 2020-11-20 8:33 ` Serge Petrenko 2020-11-19 23:45 ` [Tarantool-patches] [PATCH v2 11/16] raft: move worker fiber from Raft library to box Vladislav Shpilevoy 2020-11-20 9:06 ` Serge Petrenko 2020-11-19 23:46 ` [Tarantool-patches] [PATCH v2 12/16] raft: move synchro queue clear to the worker fiber Vladislav Shpilevoy 2020-11-20 9:07 ` Serge Petrenko 2020-11-19 23:46 ` [Tarantool-patches] [PATCH v2 13/16] raft: invoke update triggers within state machine Vladislav Shpilevoy 2020-11-20 9:10 ` Serge Petrenko 2020-11-19 23:46 ` [Tarantool-patches] [PATCH v2 14/16] raft: move RO summary update to box-Raft Vladislav Shpilevoy 2020-11-20 9:13 ` Serge Petrenko 2020-11-19 23:46 ` [Tarantool-patches] [PATCH v2 15/16] raft: introduce RaftError Vladislav Shpilevoy 2020-11-19 23:46 ` [Tarantool-patches] [PATCH v2 16/16] raft: move algorithm code to src/lib/raft Vladislav Shpilevoy 2020-11-19 23:46 ` [Tarantool-patches] [PATCH v2 02/16] raft: move box_raft_* to src/box/raft.h and .c Vladislav Shpilevoy 2020-11-19 23:46 ` [Tarantool-patches] [PATCH v2 03/16] raft: stop using replication_disconnect_timeout() Vladislav Shpilevoy 2020-11-19 23:46 ` [Tarantool-patches] [PATCH v2 04/16] raft: stop using replication_synchro_quorum Vladislav Shpilevoy 2020-11-19 23:46 ` [Tarantool-patches] [PATCH v2 05/16] raft: stop using instance_id Vladislav Shpilevoy 2020-11-19 23:46 ` [Tarantool-patches] [PATCH v2 06/16] raft: make raft_request.vclock constant Vladislav Shpilevoy 2020-11-19 23:46 ` Vladislav Shpilevoy [this message] 2020-11-19 23:46 ` [Tarantool-patches] [PATCH v2 08/16] raft: introduce vtab for disk and network Vladislav Shpilevoy 2020-11-19 23:46 ` [Tarantool-patches] [PATCH v2 09/16] raft: introduce raft_msg, drop xrow dependency Vladislav Shpilevoy 2020-11-20 9:14 ` [Tarantool-patches] [PATCH v2 00/16] Raft module, part 2 - relocation to src/lib/raft Serge Petrenko 2020-11-20 19:42 ` Vladislav Shpilevoy 2020-11-23 5:30 ` Alexander V. Tikhonov 2020-11-23 23:26 ` Vladislav Shpilevoy
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=9d1d5336080ed8ce1ab264bbec071ae0cacebabe.1605829282.git.v.shpilevoy@tarantool.org \ --to=v.shpilevoy@tarantool.org \ --cc=sergepetrenko@tarantool.org \ --cc=tarantool-patches@dev.tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH v2 07/16] raft: stop using replicaset.vclock' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox