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 668206EC55; Fri, 16 Jul 2021 02:50:22 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 668206EC55 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1626393022; bh=4X7L3Qyq0CBEBRUptheorCXz/HWsne/My8n9QcxX32c=; 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=lao5VqNv3CaYFPaZAMmVM6rDa2CIeEDw2cexvG64CczPGzji+k8FVZc/NGGZgaiMH UrTGw23w/n53Xq6g6RE904wlb75xynFB9u6Tt3H8A6PlSeuek4ocHA04KsfVuW8xQn 7fc89P9kCThzZuosMXkmo3+ne59F7ywfZJRYr5K8= 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 6651F6EC55 for ; Fri, 16 Jul 2021 02:49:53 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 6651F6EC55 Received: by smtpng3.m.smailru.net with esmtpa (envelope-from ) id 1m4B72-000289-Ji; Fri, 16 Jul 2021 02:49:53 +0300 To: tarantool-patches@dev.tarantool.org, gorcunov@gmail.com, sergepetrenko@tarantool.org Date: Fri, 16 Jul 2021 01:49:49 +0200 Message-Id: <0c92a88ff1d392f8b03de59be8cb19a162bf78f8.1626392372.git.v.shpilevoy@tarantool.org> 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: 78E4E2B564C1792B X-77F55803: 4F1203BC0FB41BD941C43E597735A9C3D3726AD0AC8C7907896201F0AD2BBAE8182A05F538085040A4779F0BF815B2E78683F157A763ED2AB2E351221A416B883834CD005A155A43 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7E28898EEFCE30F12EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637835928C62272F24E8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8276E09FC9356585664E96BD976B603F6117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC974A882099E279BDA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352033AC447995A7AD1828451B159A507268D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B65D56369A3576CBA5089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975CAA8DC07915BC95B7B7447F7DC83CC049A236B27C631035C39C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EF3033054805BDE987699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34EB7BD66E9101C100FFFC4185E082EE82BCC30BC588A5DB18B9B9BC1F6BC6EE7363A6B84BAEBA708B1D7E09C32AA3244C86E5A986D0C0CB8E80A814DB479E815639C99C45E8D137E9FACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojSyb42jm8PHJSYkKAlsqUug== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5DCAAF12627E2A5E888707566A0B51CE793841015FED1DE5223CC9A89AB576DD93FB559BB5D741EB963CF37A108A312F5C27E8A8C3839CE0E267EA787935ED9F1B X-Mras: Ok Subject: [Tarantool-patches] [PATCH 1/2] replication: introduce ballot.can_be_leader 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_BE_LEADER 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..ef3efe3e0 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_be_leader = 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..f0f967008 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_BE_LEADER = 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_BE_LEADER) + + mp_sizeof_bool(ballot->can_be_leader); 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_BE_LEADER); + data = mp_encode_bool(data, ballot->can_be_leader); 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_be_leader = 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_BE_LEADER: + if (mp_typeof(*data) != MP_BOOL) + goto err; + ballot->can_be_leader = mp_decode_bool(&data); + break; default: mp_next(&data); } diff --git a/src/box/xrow.h b/src/box/xrow.h index 9f61bfd47..f77fa5a9b 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 is an election candidate. */ + bool can_be_leader; /** * A flag whether the instance is anonymous, not having an * ID, and not going to request it. -- 2.24.3 (Apple Git-128)