Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladislav Shpilevoy via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: tarantool-patches@dev.tarantool.org, gorcunov@gmail.com,
	sergepetrenko@tarantool.org
Subject: [Tarantool-patches] [PATCH v2 2/5] box: save box_raft() into a variable
Date: Sun, 18 Jul 2021 18:53:26 +0200	[thread overview]
Message-ID: <a1656f2d52c4f7278e05bca8d9373a4b869cd290.1626627097.git.v.shpilevoy@tarantool.org> (raw)
In-Reply-To: <cover.1626627097.git.v.shpilevoy@tarantool.org>

It is shorter. Also in the next patches it is going to be used
more, so better stop calling box_raft() constantly.
---
 src/box/box.cc | 35 ++++++++++++++++++-----------------
 1 file changed, 18 insertions(+), 17 deletions(-)

diff --git a/src/box/box.cc b/src/box/box.cc
index 800f4d76f..673f6bed6 100644
--- a/src/box/box.cc
+++ b/src/box/box.cc
@@ -1536,7 +1536,7 @@ box_promote(void)
 			 "simultaneous invocations");
 		return -1;
 	}
-
+	struct raft *raft = box_raft();
 	/*
 	 * Do nothing when box isn't configured and when PROMOTE was already
 	 * written for this term (synchronous replication and leader election
@@ -1552,12 +1552,12 @@ box_promote(void)
 		try_wait = true;
 		break;
 	case ELECTION_MODE_VOTER:
-		assert(box_raft()->state == RAFT_STATE_FOLLOWER);
+		assert(raft->state == RAFT_STATE_FOLLOWER);
 		diag_set(ClientError, ER_UNSUPPORTED, "election_mode='voter'",
 			 "manual elections");
 		return -1;
 	case ELECTION_MODE_MANUAL:
-		if (box_raft()->state == RAFT_STATE_LEADER)
+		if (raft->state == RAFT_STATE_LEADER)
 			return 0;
 		run_elections = true;
 		break;
@@ -1567,13 +1567,13 @@ box_promote(void)
 		 * promote only if it's already an elected leader. No manual
 		 * elections.
 		 */
-		if (box_raft()->state != RAFT_STATE_LEADER) {
+		if (raft->state != RAFT_STATE_LEADER) {
 			diag_set(ClientError, ER_UNSUPPORTED, "election_mode="
 				 "'candidate'", "manual elections");
 			return -1;
 		}
 		if (txn_limbo_replica_term(&txn_limbo, instance_id) ==
-		    box_raft()->term)
+		    raft->term)
 			return 0;
 
 		break;
@@ -1595,28 +1595,28 @@ box_promote(void)
 		 * Make this instance a candidate and run until some leader, not
 		 * necessarily this instance, emerges.
 		 */
-		raft_start_candidate(box_raft());
+		raft_start_candidate(raft);
 		/*
 		 * Trigger new elections without waiting for an old leader to
 		 * disappear.
 		 */
-		raft_new_term(box_raft());
+		raft_new_term(raft);
 		rc = box_raft_wait_leader_found();
 		/*
 		 * Do not reset raft mode if it was changed while running the
 		 * elections.
 		 */
 		if (box_election_mode == ELECTION_MODE_MANUAL)
-			raft_stop_candidate(box_raft(), false);
+			raft_stop_candidate(raft, false);
 		if (rc != 0)
 			return -1;
-		if (!box_raft()->is_enabled) {
+		if (!raft->is_enabled) {
 			diag_set(ClientError, ER_RAFT_DISABLED);
 			return -1;
 		}
-		if (box_raft()->state != RAFT_STATE_LEADER) {
+		if (raft->state != RAFT_STATE_LEADER) {
 			diag_set(ClientError, ER_INTERFERING_PROMOTE,
-				 box_raft()->leader);
+				 raft->leader);
 			return -1;
 		}
 	}
@@ -1682,15 +1682,15 @@ box_promote(void)
 		} else {
 promote:
 			/* We cannot possibly get here in a volatile state. */
-			assert(box_raft()->volatile_term == box_raft()->term);
+			assert(raft->volatile_term == raft->term);
 			txn_limbo_write_promote(&txn_limbo, wait_lsn,
-						box_raft()->term);
+						raft->term);
 			struct synchro_request req = {
 				.type = IPROTO_PROMOTE,
 				.replica_id = former_leader_id,
 				.origin_id = instance_id,
 				.lsn = wait_lsn,
-				.term = box_raft()->term,
+				.term = raft->term,
 			};
 			txn_limbo_process(&txn_limbo, &req);
 			assert(txn_limbo_is_empty(&txn_limbo));
@@ -3493,9 +3493,10 @@ box_cfg_xc(void)
 	 * new records into WAL. Another reason - before recovery is done,
 	 * instance_id is not known, so Raft simply can't work.
 	 */
+	struct raft *raft = box_raft();
 	if (!replication_anon)
-		raft_cfg_instance_id(box_raft(), instance_id);
-	raft_cfg_vclock(box_raft(), &replicaset.vclock);
+		raft_cfg_instance_id(raft, instance_id);
+	raft_cfg_vclock(raft, &replicaset.vclock);
 
 	if (box_set_election_timeout() != 0)
 		diag_raise();
@@ -3519,7 +3520,7 @@ box_cfg_xc(void)
 		 * should take the control over the situation and start a new
 		 * term immediately.
 		 */
-		raft_new_term(box_raft());
+		raft_new_term(raft);
 	}
 
 	/* box.cfg.read_only is not read yet. */
-- 
2.24.3 (Apple Git-128)


  parent reply	other threads:[~2021-07-18 16:54 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-18 16:53 [Tarantool-patches] [PATCH v2 0/5] Bootstrap voter Vladislav Shpilevoy via Tarantool-patches
2021-07-18 16:53 ` [Tarantool-patches] [PATCH v2 1/5] replication: introduce ballot.can_lead Vladislav Shpilevoy via Tarantool-patches
2021-07-21 21:38   ` Vladislav Shpilevoy via Tarantool-patches
2021-07-18 16:53 ` Vladislav Shpilevoy via Tarantool-patches [this message]
2021-07-18 16:53 ` [Tarantool-patches] [PATCH v2 3/5] raft: replace raft_start_candidate with _promote Vladislav Shpilevoy via Tarantool-patches
2021-07-18 16:53 ` [Tarantool-patches] [PATCH v2 4/5] election: during bootstrap prefer candidates Vladislav Shpilevoy via Tarantool-patches
2021-07-18 16:53 ` [Tarantool-patches] [PATCH v2 5/5] election: promote 'manual' bootstrap master Vladislav Shpilevoy via Tarantool-patches
2021-07-19 14:27 ` [Tarantool-patches] [PATCH v2 0/5] Bootstrap voter Sergey Petrenko via Tarantool-patches
2021-07-20  8:18 ` Cyrill Gorcunov via Tarantool-patches

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=a1656f2d52c4f7278e05bca8d9373a4b869cd290.1626627097.git.v.shpilevoy@tarantool.org \
    --to=tarantool-patches@dev.tarantool.org \
    --cc=gorcunov@gmail.com \
    --cc=sergepetrenko@tarantool.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH v2 2/5] box: save box_raft() into a variable' \
    /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