From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 59E036EC55; Sun, 18 Jul 2021 19:54:32 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 59E036EC55 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1626627272; bh=7nmtxS27dijGwwdNM59kV1psMIL6KBLFczNCGG9KXJk=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=Gye8F5V3Ndz5KBhpCECWy2keTB/DaQj7ewWrkGj0qhHAauhWSwB2MtnIDPAntKUmH bPN/Rx80Y2HxyP9lc0wXUXcUXQK2Zq/LcFOVrYxh2k2Mjj0tH55e36VzXooOEKTvhL xORAwEPY9thMNQD/0oDC49Rht+ohZF1f9nqsBjoA= Received: from smtpng3.i.mail.ru (smtpng3.i.mail.ru [94.100.177.149]) (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 D87CD6EC56 for ; Sun, 18 Jul 2021 19:53:32 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org D87CD6EC56 Received: by smtpng3.m.smailru.net with esmtpa (envelope-from ) id 1m5A2m-0005NM-2z; Sun, 18 Jul 2021 19:53:32 +0300 To: tarantool-patches@dev.tarantool.org, gorcunov@gmail.com, sergepetrenko@tarantool.org Date: Sun, 18 Jul 2021 18:53:26 +0200 Message-Id: X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD941C43E597735A9C320FB367CC9CBEE800EEBD3117ABA9A5B182A05F5380850400BAE48B6C0173AC6EB590E7BCD674BAFF3052CFECB02846912015921E9AD7FB8 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE732599CA775888A0BEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006370FDF1CE57EA9D07C8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D853BB9F45338E42788C22FB27D7149579117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCED943DBD20860CC2A471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F44604297287769387670735209647ADFADE5905B1E5D25F19253116ADD2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B65D56369A3576CBA5089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975CBC3D6B4D9834ECA78DA95F87ED21E7BCAC22BDD4695D6D4A9C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EF3033054805BDE987699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34D2AC226BFD455724A492062F6BC241D208FB1094E20171BAA0A1981DB553B6FA7D0A65933C871DA41D7E09C32AA3244CC2866BCAB88951703A8881CEB25B1FBC8580396430872480FACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2bioj+8+KVR9NZrHyX7zQcI3ong== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5D68A84EBB510A53F94AF458A314FF5D4A3841015FED1DE5223CC9A89AB576DD93FB559BB5D741EB963CF37A108A312F5C27E8A8C3839CE0E267EA787935ED9F1B X-Mras: Ok Subject: [Tarantool-patches] [PATCH v2 2/5] box: save box_raft() into a variable X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Vladislav Shpilevoy via Tarantool-patches Reply-To: Vladislav Shpilevoy Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" 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)