Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
To: tarantool-patches@dev.tarantool.org, sergepetrenko@tarantool.org
Subject: [Tarantool-patches] [PATCH v2 14/16] raft: move RO summary update to box-Raft
Date: Fri, 20 Nov 2020 00:46:02 +0100	[thread overview]
Message-ID: <2605013dec76594d2a9f05d1ac162c58d7290ebc.1605829282.git.v.shpilevoy@tarantool.org> (raw)
In-Reply-To: <cover.1605829282.git.v.shpilevoy@tarantool.org>

RO summary update is supposed to make the instance read-only, when
it becomes a follower, and read-write when becomes a leader.

But it makes Raft depend on box, and prevents Raft move to a
separate library.

The patch moves the RO update to box-Raft.

This became possible after some preparatory work was done to make
Raft update triggers non-yielding, and invoked right after state
change (without a yield between the change and the triggers).

Part of #5303
---
 src/box/raft.c    | 8 ++++++++
 src/box/raftlib.c | 8 --------
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/src/box/raft.c b/src/box/raft.c
index 5ccfb3449..c5a27cdec 100644
--- a/src/box/raft.c
+++ b/src/box/raft.c
@@ -153,6 +153,14 @@ box_raft_on_update_f(struct trigger *trigger, void *event)
 	(void)trigger;
 	struct raft *raft = (struct raft *)event;
 	assert(raft == box_raft());
+	/*
+	 * XXX: in case the instance became a leader, RO must be updated only
+	 * after clearing the synchro queue.
+	 *
+	 * When the instance became a follower, then on the contrary - make it
+	 * read-only ASAP, this is good.
+	 */
+	box_update_ro_summary();
 	if (raft->state != RAFT_STATE_LEADER)
 		return 0;
 	/*
diff --git a/src/box/raftlib.c b/src/box/raftlib.c
index f64a66942..6e6bc658f 100644
--- a/src/box/raftlib.c
+++ b/src/box/raftlib.c
@@ -33,7 +33,6 @@
 #include "error.h"
 #include "fiber.h"
 #include "small/region.h"
-#include "box.h"
 #include "tt_static.h"
 
 /**
@@ -618,8 +617,6 @@ raft_sm_become_leader(struct raft *raft)
 	raft->state = RAFT_STATE_LEADER;
 	raft->leader = raft->self;
 	ev_timer_stop(loop(), &raft->timer);
-	/* Make read-write (if other subsystems allow that. */
-	box_update_ro_summary();
 	/* State is visible and it is changed - broadcast. */
 	raft_schedule_broadcast(raft);
 }
@@ -670,7 +667,6 @@ raft_sm_schedule_new_term(struct raft *raft, uint64_t new_term)
 	raft->volatile_vote = 0;
 	raft->leader = 0;
 	raft->state = RAFT_STATE_FOLLOWER;
-	box_update_ro_summary();
 	raft_sm_pause_and_dump(raft);
 	/*
 	 * State is visible and it is changed - broadcast. Term is also visible,
@@ -701,7 +697,6 @@ raft_sm_schedule_new_election(struct raft *raft)
 	/* Everyone is a follower until its vote for self is persisted. */
 	raft_sm_schedule_new_term(raft, raft->term + 1);
 	raft_sm_schedule_new_vote(raft, raft->self);
-	box_update_ro_summary();
 }
 
 static void
@@ -786,7 +781,6 @@ raft_sm_start(struct raft *raft)
 		 */
 		raft_sm_wait_leader_found(raft);
 	}
-	box_update_ro_summary();
 	/*
 	 * Nothing changed. But when raft was stopped, its state wasn't sent to
 	 * replicas. At least this was happening at the moment of this being
@@ -808,7 +802,6 @@ raft_sm_stop(struct raft *raft)
 		raft->leader = 0;
 	raft->state = RAFT_STATE_FOLLOWER;
 	ev_timer_stop(loop(), &raft->timer);
-	box_update_ro_summary();
 	/* State is visible and changed - broadcast. */
 	raft_schedule_broadcast(raft);
 }
@@ -894,7 +887,6 @@ raft_cfg_is_candidate(struct raft *raft, bool is_candidate)
 			raft_schedule_broadcast(raft);
 		}
 	}
-	box_update_ro_summary();
 }
 
 void
-- 
2.24.3 (Apple Git-128)

  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 ` Vladislav Shpilevoy [this message]
2020-11-20  9:13   ` [Tarantool-patches] [PATCH v2 14/16] raft: move RO summary update to box-Raft 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 ` [Tarantool-patches] [PATCH v2 07/16] raft: stop using replicaset.vclock Vladislav Shpilevoy
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=2605013dec76594d2a9f05d1ac162c58d7290ebc.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 14/16] raft: move RO summary update to box-Raft' \
    /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