From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp51.i.mail.ru (smtp51.i.mail.ru [94.100.177.111]) (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 55DF3430411 for ; Wed, 26 Aug 2020 10:53:04 +0300 (MSK) From: Serge Petrenko Date: Wed, 26 Aug 2020 10:52:38 +0300 Message-Id: <1fb0f4b22ccfea68e73f040f5404eebc2fe0154d.1598427905.git.sergepetrenko@tarantool.org> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [RAFT 06/10] [tosquash] raft: don't fill raft_request manually List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: v.shpilevoy@tarantool.org, gorcunov@gmail.com, sergos@tarantool.org Cc: tarantool-patches@dev.tarantool.org From: Vladislav Shpilevoy At 'subscribe' the raft complete state was sent to the peer. But it was filled manually into struct raft_request. There is a function raft_serialize() exactly to avoid such manual work. The patch extends the serializer with vclock argument. Since raft does not manage vclocks and needs them provided externally (so far, perhaps that will change). --- src/box/box.cc | 5 +---- src/box/memtx_engine.c | 6 +++++- src/box/raft.c | 7 ++++++- src/box/raft.h | 2 +- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/box/box.cc b/src/box/box.cc index b871f45e2..e7eb79e9f 100644 --- a/src/box/box.cc +++ b/src/box/box.cc @@ -2056,14 +2056,11 @@ box_process_subscribe(struct ev_io *io, struct xrow_header *header) */ if (raft.state != RAFT_STATE_NONE) { struct raft_request req; - req.term = raft.term; - req.vote = raft.vote; - req.state = raft.state; /* * Omit the candidate vclock, since we've just * sent it in subscribe response. */ - req.vclock = NULL; + raft_serialize(&req, NULL); xrow_encode_raft(&row, &fiber()->gc, &req); coio_write_xrow(io, &row); } diff --git a/src/box/memtx_engine.c b/src/box/memtx_engine.c index a034baa6c..7de12a569 100644 --- a/src/box/memtx_engine.c +++ b/src/box/memtx_engine.c @@ -517,7 +517,11 @@ checkpoint_new(const char *snap_dirname, uint64_t snap_io_rate_limit) opts.free_cache = true; xdir_create(&ckpt->dir, snap_dirname, SNAP, &INSTANCE_UUID, &opts); vclock_create(&ckpt->vclock); - raft_serialize(&ckpt->raft); + /* + * Don't encode vclock, because it is stored in the snapshot header + * anyway. + */ + raft_serialize(&ckpt->raft, NULL); ckpt->touch = false; return ckpt; } diff --git a/src/box/raft.c b/src/box/raft.c index 227846596..1d25459e9 100644 --- a/src/box/raft.c +++ b/src/box/raft.c @@ -80,11 +80,16 @@ raft_process_msg(const struct raft_request *req) } void -raft_serialize(struct raft_request *req) +raft_serialize(struct raft_request *req, struct vclock *vclock) { memset(req, 0, sizeof(*req)); req->term = raft.term; req->vote = raft.vote; + req->state = raft.state; + /* + * Raft does not own vclock, so it always expects it passed externally. + */ + req->vclock = vclock; } static void diff --git a/src/box/raft.h b/src/box/raft.h index b11ae7b1d..c95a51873 100644 --- a/src/box/raft.h +++ b/src/box/raft.h @@ -72,7 +72,7 @@ void raft_process_msg(const struct raft_request *req); void -raft_serialize(struct raft_request *req); +raft_serialize(struct raft_request *req, struct vclock *vclock); void raft_free_msg(struct cmsg *msg); -- 2.20.1 (Apple Git-117)