From: Serge Petrenko <sergepetrenko@tarantool.org> To: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>, tarantool-patches@dev.tarantool.org, gorcunov@gmail.com Subject: Re: [Tarantool-patches] [PATCH 08/12] raft: introduce vtab for disk and network Date: Tue, 17 Nov 2020 12:35:58 +0300 [thread overview] Message-ID: <697d34e7-c630-37b7-de39-21865b69bb33@tarantool.org> (raw) In-Reply-To: <0f6505cf411bd9e7e11f42b5b6a8526b6b291ce1.1605570907.git.v.shpilevoy@tarantool.org> 17.11.2020 03:02, Vladislav Shpilevoy пишет: > 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 and journal objects. > They were used to broadcast messages to all the other nodes, and > to persist updates. > > Now Raft does the same through vtab, which is configured by box. > Broadcast still sends messages via relays, and disk write still > uses the journal. But Raft does not depend on any specific journal > or network API. > > Part of #5303 > --- > src/box/raft.c | 63 ++++++++++++++++++++++++++++++++++++++- > src/box/raftlib.c | 75 ++++++++++------------------------------------- > src/box/raftlib.h | 24 ++++++++++++++- > 3 files changed, 100 insertions(+), 62 deletions(-) > > > /* Dump Raft state to WAL in a blocking way. */ > static void > raft_worker_handle_io(struct raft *raft) > @@ -567,8 +513,17 @@ end_dump: > assert(raft->volatile_term >= raft->term); > req.term = raft->volatile_term; > req.vote = raft->volatile_vote; > - > - raft_write_request(&req); > + /* > + * Skip vclock. It is used only to be sent to network when vote > + * for self. It is a job of the vclock owner to persist it > + * anyhow. > + * > + * Skip state. That would be strictly against Raft protocol. The > + * reason is that it does not make much sense - even if the node > + * is a leader now, after the node is restarted, there will be > + * another leader elected by that time likely. > + */ > + raft->vtab->write(raft, &req); > say_info("RAFT: persisted state %s", > raft_request_to_string(&req)); > > @@ -598,8 +553,7 @@ raft_worker_handle_broadcast(struct raft *raft) > assert(raft->vote == raft->self); > req.vclock = raft->vclock; > } > - replicaset_foreach(replica) > - relay_push_raft(replica->relay, &req); > + raft->vtab->broadcast(raft, &req); I'd introduce helpers, like raft_write() and raft_broadcast(), to hide raft->vtab->... calls. Up to you, though. Other than that LGTM. > trigger_run(&raft->on_update, raft); > raft->is_broadcast_scheduled = false; > } > @@ -1038,7 +992,7 @@ raft_schedule_broadcast(struct raft *raft) > } > > void > -raft_create(struct raft *raft) > +raft_create(struct raft *raft, const struct raft_vtab *vtab) > { > *raft = (struct raft) { > .state = RAFT_STATE_FOLLOWER, > @@ -1047,6 +1001,7 @@ raft_create(struct raft *raft) > .election_quorum = 1, > .election_timeout = 5, > .death_timeout = 5, > + .vtab = vtab, > }; > 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 8d0d03da0..6181d9d49 100644 > --- a/src/box/raftlib.h > +++ b/src/box/raftlib.h > @@ -295,8 +313,12 @@ raft_serialize_for_disk(const struct raft *raft, struct raft_request *req); > void > raft_on_update(struct raft *raft, struct trigger *trigger); > > +/** > + * Create a Raft node. The vtab is not copied. Its memory should stay valid even > + * after the creation. > + */ > void > -raft_create(struct raft *raft); > +raft_create(struct raft *raft, const struct raft_vtab *vtab); > > void > raft_destroy(struct raft *raft); -- Serge Petrenko
next prev parent reply other threads:[~2020-11-17 9:35 UTC|newest] Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-11-17 0:02 [Tarantool-patches] [PATCH 00/12] Raft module, part 2 - relocation to src/lib/raft Vladislav Shpilevoy 2020-11-17 0:02 ` [Tarantool-patches] [PATCH 01/12] raft: move sources to raftlib.h/.c Vladislav Shpilevoy 2020-11-17 8:14 ` Serge Petrenko 2020-11-17 0:02 ` [Tarantool-patches] [PATCH 10/12] raft: move box_update_ro_summary to update trigger Vladislav Shpilevoy 2020-11-17 12:42 ` Serge Petrenko 2020-11-17 15:17 ` Serge Petrenko 2020-11-18 23:21 ` Vladislav Shpilevoy 2020-11-19 10:08 ` Serge Petrenko 2020-11-17 0:02 ` [Tarantool-patches] [PATCH 11/12] raft: introduce RaftError Vladislav Shpilevoy 2020-11-17 15:13 ` Serge Petrenko 2020-11-17 0:02 ` [Tarantool-patches] [PATCH 12/12] raft: move algorithm code to src/lib/raft Vladislav Shpilevoy 2020-11-17 15:13 ` Serge Petrenko 2020-11-17 0:02 ` [Tarantool-patches] [PATCH 02/12] raft: move box_raft_* to src/box/raft.h and .c Vladislav Shpilevoy 2020-11-17 8:14 ` Serge Petrenko 2020-11-17 0:02 ` [Tarantool-patches] [PATCH 03/12] raft: stop using replication_disconnect_timeout() Vladislav Shpilevoy 2020-11-17 8:15 ` Serge Petrenko 2020-11-17 0:02 ` [Tarantool-patches] [PATCH 04/12] raft: stop using replication_synchro_quorum Vladislav Shpilevoy 2020-11-17 8:17 ` Serge Petrenko 2020-11-19 23:42 ` Vladislav Shpilevoy 2020-11-17 0:02 ` [Tarantool-patches] [PATCH 05/12] raft: stop using instance_id Vladislav Shpilevoy 2020-11-17 8:59 ` Serge Petrenko 2020-11-17 0:02 ` [Tarantool-patches] [PATCH 06/12] raft: make raft_request.vclock constant Vladislav Shpilevoy 2020-11-17 9:17 ` Serge Petrenko 2020-11-17 0:02 ` [Tarantool-patches] [PATCH 07/12] raft: stop using replicaset.vclock Vladislav Shpilevoy 2020-11-17 9:23 ` Serge Petrenko 2020-11-17 0:02 ` [Tarantool-patches] [PATCH 08/12] raft: introduce vtab for disk and network Vladislav Shpilevoy 2020-11-17 9:35 ` Serge Petrenko [this message] 2020-11-19 23:43 ` Vladislav Shpilevoy 2020-11-17 10:00 ` Serge Petrenko 2020-11-19 23:43 ` Vladislav Shpilevoy 2020-11-20 7:56 ` Serge Petrenko 2020-11-20 19:40 ` Vladislav Shpilevoy 2020-11-23 8:09 ` Serge Petrenko 2020-11-17 0:02 ` [Tarantool-patches] [PATCH 09/12] raft: introduce raft_msg, drop xrow dependency Vladislav Shpilevoy 2020-11-17 10:22 ` Serge Petrenko 2020-11-19 23:43 ` Vladislav Shpilevoy 2020-11-20 8:03 ` Serge Petrenko
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=697d34e7-c630-37b7-de39-21865b69bb33@tarantool.org \ --to=sergepetrenko@tarantool.org \ --cc=gorcunov@gmail.com \ --cc=tarantool-patches@dev.tarantool.org \ --cc=v.shpilevoy@tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH 08/12] raft: introduce vtab for disk and network' \ /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