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 012176EC55; Sun, 18 Jul 2021 19:54:02 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 012176EC55 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1626627243; bh=JlA44B9CulZOShI1YHMHvxKGFNqyHmegDxu75+6tCZE=; 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=vNGbkJyE6zk74mIzx9ImpNLFpO6pu3lXZRX2cQvUgeDgwzL1GPkz9UjqeQJVubJ6c Rm8r7tKVzgT6+X+ItT7OMr/uHRtLvSxqr5ChKzYmuLu5JRakXpvESIZt6ad5aNGjXM hjpOJmIyhjafokC6ZbGd7WPwAbdxc7yc6hwCLufM= 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 1917A6EC55 for ; Sun, 18 Jul 2021 19:53:32 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 1917A6EC55 Received: by smtpng3.m.smailru.net with esmtpa (envelope-from ) id 1m5A2l-0005NM-AZ; Sun, 18 Jul 2021 19:53:31 +0300 To: tarantool-patches@dev.tarantool.org, gorcunov@gmail.com, sergepetrenko@tarantool.org Date: Sun, 18 Jul 2021 18:53:25 +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: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD941C43E597735A9C36A98DBA789EBB6AEFB5A483DCE5E7579182A05F538085040C4396B5B12EF67AC1900C21CEC46F91B1C629360E677B7B2D5A8EDA0343E803D X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE791E547C23789F646EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637D07BBD2EBFB7BF888638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D82C1D376D8F3285CF16353F81BE236684117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC3A703B70628EAD7BA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352026055571C92BF10F618001F51B5FD3F9D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B65D56369A3576CBA5089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975CBC3D6B4D9834ECA7152F540E8FBA2F4EAA03BE89DE2D6BE29C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EF3033054805BDE987699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D343D1F112031EF3D62DC064BBDC94706AF7FD010BCED0815EB8CD71C8AD332E82A7AC0E6D160278AF31D7E09C32AA3244C008637C5E0C9A7062BF5E4594A9CE3E763871F383B54D9B3FACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2bioj+8+KVR9NZrHC/5QxJupNaw== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5D858F7265DE631FACA00407C8E36BB7883841015FED1DE5223CC9A89AB576DD93FB559BB5D741EB963CF37A108A312F5C27E8A8C3839CE0E267EA787935ED9F1B X-Mras: Ok Subject: [Tarantool-patches] [PATCH v2 1/5] replication: introduce ballot.can_lead 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" The flag tells whether the sender has election mode 'candidate' or 'manual'. The new field during bootstrap will help to avoid selecting a 'voter' as a master. Voters can't write, they are unable to boot themselves nor register others. @TarantoolBot document Title: New field - IPROTO_BALLOT_CAN_LEAD It is sent as a part of `IPROTO_BALLOT (0x29)`. The field is a boolean flag which is true if the sender has `election_mode` in its config `'manual'` or `'candidate'`. During bootstrap the nodes able to become a leader are preferred over the nodes configured as `'voter'`. The field key is `0x07`. --- src/box/box.cc | 3 +++ src/box/iproto_constants.h | 1 + src/box/xrow.c | 14 ++++++++++++-- src/box/xrow.h | 2 ++ 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/box/box.cc b/src/box/box.cc index eeb57b04e..800f4d76f 100644 --- a/src/box/box.cc +++ b/src/box/box.cc @@ -2881,6 +2881,9 @@ void box_process_vote(struct ballot *ballot) { ballot->is_ro_cfg = cfg_geti("read_only") != 0; + enum election_mode mode = box_check_election_mode(); + ballot->can_lead = mode == ELECTION_MODE_CANDIDATE || + mode == ELECTION_MODE_MANUAL; ballot->is_anon = replication_anon; ballot->is_ro = is_ro_summary; ballot->is_booted = is_box_configured; diff --git a/src/box/iproto_constants.h b/src/box/iproto_constants.h index 137bee9da..ea7290da6 100644 --- a/src/box/iproto_constants.h +++ b/src/box/iproto_constants.h @@ -168,6 +168,7 @@ enum iproto_ballot_key { IPROTO_BALLOT_IS_RO = 0x04, IPROTO_BALLOT_IS_ANON = 0x05, IPROTO_BALLOT_IS_BOOTED = 0x06, + IPROTO_BALLOT_CAN_LEAD = 0x07, }; #define bit(c) (1ULL<vclock) + mp_sizeof_uint(UINT32_MAX) + - mp_sizeof_vclock_ignore0(&ballot->gc_vclock); + mp_sizeof_vclock_ignore0(&ballot->gc_vclock) + + mp_sizeof_uint(IPROTO_BALLOT_CAN_LEAD) + + mp_sizeof_bool(ballot->can_lead); char *buf = obuf_reserve(out, max_size); if (buf == NULL) { @@ -471,7 +473,7 @@ iproto_reply_vote(struct obuf *out, const struct ballot *ballot, char *data = buf + IPROTO_HEADER_LEN; data = mp_encode_map(data, 1); data = mp_encode_uint(data, IPROTO_BALLOT); - data = mp_encode_map(data, 6); + data = mp_encode_map(data, 7); data = mp_encode_uint(data, IPROTO_BALLOT_IS_RO_CFG); data = mp_encode_bool(data, ballot->is_ro_cfg); data = mp_encode_uint(data, IPROTO_BALLOT_IS_RO); @@ -484,6 +486,8 @@ iproto_reply_vote(struct obuf *out, const struct ballot *ballot, data = mp_encode_vclock_ignore0(data, &ballot->vclock); data = mp_encode_uint(data, IPROTO_BALLOT_GC_VCLOCK); data = mp_encode_vclock_ignore0(data, &ballot->gc_vclock); + data = mp_encode_uint(data, IPROTO_BALLOT_CAN_LEAD); + data = mp_encode_bool(data, ballot->can_lead); size_t size = data - buf; assert(size <= max_size); @@ -1362,6 +1366,7 @@ int xrow_decode_ballot(struct xrow_header *row, struct ballot *ballot) { ballot->is_ro_cfg = false; + ballot->can_lead = false; ballot->is_ro = false; ballot->is_anon = false; ballot->is_booted = true; @@ -1434,6 +1439,11 @@ xrow_decode_ballot(struct xrow_header *row, struct ballot *ballot) goto err; ballot->is_booted = mp_decode_bool(&data); break; + case IPROTO_BALLOT_CAN_LEAD: + if (mp_typeof(*data) != MP_BOOL) + goto err; + ballot->can_lead = mp_decode_bool(&data); + break; default: mp_next(&data); } diff --git a/src/box/xrow.h b/src/box/xrow.h index 9f61bfd47..000cd6b88 100644 --- a/src/box/xrow.h +++ b/src/box/xrow.h @@ -368,6 +368,8 @@ xrow_encode_auth(struct xrow_header *row, const char *salt, size_t salt_len, struct ballot { /** Set if the instance is configured in read-only mode. */ bool is_ro_cfg; + /** Set if the instance can become a Raft leader. */ + bool can_lead; /** * A flag whether the instance is anonymous, not having an * ID, and not going to request it. -- 2.24.3 (Apple Git-128)