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 889CC430413 for ; Wed, 26 Aug 2020 10:53:09 +0300 (MSK) From: Serge Petrenko Date: Wed, 26 Aug 2020 10:52:40 +0300 Message-Id: In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [RAFT 08/10] [tosquash] raft: rename raft_process to raft_process_recovery 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 There is another 'process' for remote messages from other raft nodes. In order to make these functions more clearly separated, the old function used for local state recovery is renamed to raft_process_recovery. This should be squashed into the first commit about persistent raft state. --- src/box/box.cc | 2 +- src/box/memtx_engine.c | 2 +- src/box/raft.c | 14 +++++++++++++- src/box/raft.h | 2 +- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/box/box.cc b/src/box/box.cc index e7eb79e9f..d01de2519 100644 --- a/src/box/box.cc +++ b/src/box/box.cc @@ -380,7 +380,7 @@ apply_wal_row(struct xstream *stream, struct xrow_header *row) /* Vclock is never persisted in WAL by Raft. */ if (xrow_decode_raft(row, &raft_req, NULL) != 0) diag_raise(); - raft_process(&raft_req); + raft_process_recovery(&raft_req); return; } xrow_decode_dml_xc(row, &request, dml_request_key_map(row->type)); diff --git a/src/box/memtx_engine.c b/src/box/memtx_engine.c index 7de12a569..b0b744db8 100644 --- a/src/box/memtx_engine.c +++ b/src/box/memtx_engine.c @@ -209,7 +209,7 @@ memtx_engine_recover_raft(const struct xrow_header *row) /* Vclock is never persisted in WAL by Raft. */ if (xrow_decode_raft(row, &req, NULL) != 0) return -1; - raft_process(&req); + raft_process_recovery(&req); return 0; } diff --git a/src/box/raft.c b/src/box/raft.c index 714a1518a..34c1cf7aa 100644 --- a/src/box/raft.c +++ b/src/box/raft.c @@ -45,12 +45,24 @@ struct raft raft = { }; void -raft_process(const struct raft_request *req) +raft_process_recovery(const struct raft_request *req) { if (req->term != 0) raft.term = req->term; if (req->vote != 0) raft.vote = req->vote; + /* + * Role is never persisted. If recovery is happening, the + * node was restarted, and the former role can be false + * anyway. + */ + assert(req->state == RAFT_STATE_NONE); + /* + * Vclock is always persisted by some other subsystem - WAL, snapshot. + * It is used only to decide to whom to give the vote during election, + * as a part of the volatile state. + */ + assert(req->vclock == NULL); } void diff --git a/src/box/raft.h b/src/box/raft.h index 927aa8f5f..be071c215 100644 --- a/src/box/raft.h +++ b/src/box/raft.h @@ -65,7 +65,7 @@ raft_vote(uint32_t vote_for); /** Process a raft entry stored in WAL/snapshot. */ void -raft_process(const struct raft_request *req); +raft_process_recovery(const struct raft_request *req); /** Process a raft status message coming from the network. */ void -- 2.20.1 (Apple Git-117)