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 A73966EC55; Fri, 16 Jul 2021 14:00:00 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org A73966EC55 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1626433200; bh=/yRd+U/fi9Qif8gUrit3twSQyizILdxRoP5EpF46o4M=; h=To:References:Date:In-Reply-To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=i4zBnL5GZEFXN9I8RYePbZS7spuqdv2ioLfMQl5moWiEsyhdJ1CIK2j7ShJL20A/e zG9JU0W9OgHRG+eSCFvfCMEWCDIqaqb/YYjERMsMn/DQWH9aMeBB5kyC7OAkN0q4fw xw+CnBFdBnT9xfR6+O44aaEb2mH1ij2ALZ/x9pL0= Received: from smtp32.i.mail.ru (smtp32.i.mail.ru [94.100.177.92]) (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 CD4356EC55 for ; Fri, 16 Jul 2021 13:59:58 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org CD4356EC55 Received: by smtp32.i.mail.ru with esmtpa (envelope-from ) id 1m4LZV-0007vy-Uy; Fri, 16 Jul 2021 13:59:58 +0300 To: Vladislav Shpilevoy , tarantool-patches@dev.tarantool.org, gorcunov@gmail.com References: <0c92a88ff1d392f8b03de59be8cb19a162bf78f8.1626392372.git.v.shpilevoy@tarantool.org> Message-ID: <37473da3-8525-16cb-f096-49c8c90e00d5@tarantool.org> Date: Fri, 16 Jul 2021 13:59:57 +0300 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <0c92a88ff1d392f8b03de59be8cb19a162bf78f8.1626392372.git.v.shpilevoy@tarantool.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-GB X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD941C43E597735A9C30288BCF456A452EC92BAB6D044D5CCDE182A05F5380850408A8DB30E188E920875DF5935BB0C6BDDA230042DC9A44A80551938AA961A1DAB X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7569E19AE644B2ACAEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006375C4806A08D329A618638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8C5AFD85FD10A04D976AB8B522EDA2BB3117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC2EE5AD8F952D28FBA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352033AC447995A7AD18618001F51B5FD3F9D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B60A62CEF541B197C8089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-C1DE0DAB: 0D63561A33F958A56C71EFBCE90775F0AA71D20AD5F93CC3461A71EE16DCEBCED59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA7501A9DF589746230F410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34C786159FDC4342B024C19539589D78C194357DD0146838ADA277E9F863E59FA48EDA6CDB5B5462DA1D7E09C32AA3244C347BE0C4914451E661DF526CA18F8ABAD08D48398F32B4A6FACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojk34dk3RWCsYvyoqu8whqLw== X-Mailru-Sender: 3B9A0136629DC9125D61937A2360A4469EBC037B9B19E014C1479114686EDB457A1FAD50085613C5424AE0EB1F3D1D21E2978F233C3FAE6EE63DB1732555E4A8EE80603BA4A5B0BC112434F685709FCF0DA7A0AF5A3A8387 X-Mras: Ok Subject: Re: [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: Serge Petrenko via Tarantool-patches Reply-To: Serge Petrenko Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" 16.07.2021 02:49, Vladislav Shpilevoy пишет: > 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 Hi and thanks for the patch! It's all good except the field name. It's rather long IMO, and may be confused with bootsrap leader, which we try to find using ballots. Wouldn't "can be candidate", or "is_election_candidate" be better? I do not insist, though. > @@ -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< diff --git a/src/box/xrow.c b/src/box/xrow.c > index 16cb2484c..a6b19ce89 100644 > --- a/src/box/xrow.c > +++ b/src/box/xrow.c > @@ -459,7 +459,9 @@ iproto_reply_vote(struct obuf *out, const struct ballot *ballot, > mp_sizeof_uint(UINT32_MAX) + > mp_sizeof_vclock_ignore0(&ballot->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. -- Serge Petrenko