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 6AFAF6EC58; Wed, 4 Aug 2021 16:08:18 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 6AFAF6EC58 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1628082498; bh=kZ8kXxwfsKqrveLGnE7esQeFLJk8F6G1hYwogJIVAAo=; h=To:Cc:References:Date:In-Reply-To:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=A1QzvLHaVQKb6yMkc3+9ZGGuDWfgklMAZPPY1B4UlmnbtOzLTlaXLzIGAceuUb89F +lgUBBpLgXu3b/MVFFNYqCLD+lvjJPHO/D7yvkvg29HmDVGXArx4s+HQWG1g3hUjgw pXU1t9gTUmJHOUe6PTlka5CheSAlP/9bU8N9A4Ao= Received: from smtp37.i.mail.ru (smtp37.i.mail.ru [94.100.177.97]) (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 818776EC58 for ; Wed, 4 Aug 2021 16:08:17 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 818776EC58 Received: by smtp37.i.mail.ru with esmtpa (envelope-from ) id 1mBGd6-0004Iu-QE; Wed, 04 Aug 2021 16:08:17 +0300 To: Vladislav Shpilevoy , gorcunov@gmail.com Cc: tarantool-patches@dev.tarantool.org References: <3b4f7752-f68b-afce-c83a-355bcfbc28cc@tarantool.org> <9ae5765f-ffcb-af66-469b-b0a99d71c331@tarantool.org> <036d7d32-54bc-3239-9291-d713b062f324@tarantool.org> <03c81edf-709b-6320-b3e3-a2331b2b08fe@tarantool.org> <5ca8fae1-c231-8903-a5d6-cc1aa03a9ea5@tarantool.org> Message-ID: Date: Wed, 4 Aug 2021 16:08:16 +0300 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 In-Reply-To: <5ca8fae1-c231-8903-a5d6-cc1aa03a9ea5@tarantool.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-GB X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD941C43E597735A9C33D83595CA30D6DC5179D1C9A908C47E5182A05F538085040431A9D459BF6DCA459F54848B37B61AA99B25C1D15F1EE9496B999F79A3013AA X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7904AD829351C4442EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006376D321F80F15DC2F18638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D861D1B515A30AEA0FA4CE05641D0A9BC0117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC8C7ADC89C2F0B2A5A471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F44604297287769387670735201E561CDFBCA1751FBDFBBEFFF4125B51D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B6C94F115956DE4A7A089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A213B5FB47DCBC3458834459D11680B5058B14986C02147A3013639C1F7BB0D804 X-C1DE0DAB: 0D63561A33F958A550ABD749598AD98458AB6FD9C4AC3EE1FFECEB363E0126FED59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA7501A9DF589746230F410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34D2AC226BFD455724A44C0B840DC16F2A15098E704B5130258FA5B5A50EEE6B26B1D054304A7C97121D7E09C32AA3244C9801C08B540E931E4D7FF16F03694BC2F522A1CF68F4BE05FACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojeDyvyeZJDJFSe742ozsMAA== X-Mailru-Sender: 3B9A0136629DC9125D61937A2360A44690981ED5E68E26C59D53DC22382C14321CF5646E804CED55424AE0EB1F3D1D21E2978F233C3FAE6EE63DB1732555E4A8EE80603BA4A5B0BC112434F685709FCF0DA7A0AF5A3A8387 X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH v3 07/12] box: introduce `box.ctl.demote` 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" 04.08.2021 02:25, Vladislav Shpilevoy пишет: > Thanks for the fixes! > > See 3 comments below. > >> diff --git a/src/box/iproto.cc b/src/box/iproto.cc >> index 3ed641eea..5cc69b77f 100644 >> --- a/src/box/iproto.cc >> +++ b/src/box/iproto.cc >> @@ -557,6 +558,20 @@ struct iproto_connection >>      struct iproto_thread *iproto_thread; >>  }; >> >> +#ifdef NDEBUG >> +#define iproto_write_error(fd, e, schema_version, sync)                         \ >> +    iproto_do_write_error(fd, e, schema_version, sync); >> +#else >> +#define iproto_write_error(fd, e, schema_version, sync) do {                    \ >> +    int flags = fcntl(fd, F_GETFL, 0);                                      \ >> +    if (flags >= 0)                                                         \ >> +        fcntl(fd, F_SETFL, flags & (~O_NONBLOCK));                      \ >> +    iproto_do_write_error(fd, e, schema_version, sync);                     \ >> +    if (flags >= 0)                                                         \ >> +        fcntl(fd, F_SETFL, flags);                                      \ >> +} while (0); >> +#endif > 1. Why didn't you do this right in iproto_write_error? Why do > you need to change iproto.cc code at all? I've found a commit way back from 2017 where you removed the fcntl dependency from xrow. I didn't want to introduce it again. >> diff --git a/src/box/relay.cc b/src/box/relay.cc >> index 805b5e7ff..2947468ba 100644 >> --- a/src/box/relay.cc >> +++ b/src/box/relay.cc >> @@ -444,20 +444,20 @@ relay_initial_join(int fd, uint64_t sync, struct vclock *vclock, >>       */ >>      if (replica_version_id > 0) { >>          /* Mark the beginning of the metadata stream. */ >> -        row.type = IPROTO_JOIN_META; >> -        coio_write_xrow(&relay->io, &row); >> +        xrow_encode_type(&row, IPROTO_JOIN_META); >> +        xstream_write(&relay->stream, &row); > 2. Why do you use xtream_write? And why coio_write_xrow just a few lines > above works just fine then? xstream write is basically a shortcut for "row.sync = sync ; coio_write_xrow" Writing row.sync = sync before every coio_write_xrow looked rather ugly IMO, that's why I changed it. I need to reassign row.sync before each despatch because xrow_encode_* functions usually reset all the xrow fields to 0. > >>          xrow_encode_raft(&row, &fiber()->gc, &raft_req); >> -        coio_write_xrow(&relay->io, &row); >> +        xstream_write(&relay->stream, &row); >> >>          char body[XROW_SYNCHRO_BODY_LEN_MAX]; >>          xrow_encode_synchro(&row, body, &req); >>          row.replica_id = req.replica_id; >> -        coio_write_xrow(&relay->io, &row); >> +        xstream_write(&relay->stream, &row); >> >>          /* Mark the end of the metadata stream. */ >> -        row.type = IPROTO_JOIN_SNAPSHOT; >> -        coio_write_xrow(&relay->io, &row); >> +        xrow_encode_type(&row, IPROTO_JOIN_SNAPSHOT); >> +        xstream_write(&relay->stream, &row); >>      } >> diff --git a/src/box/raft.c b/src/box/raft.c >> index f8d13aa32..bc69f7f1b 100644 >> --- a/src/box/raft.c >> +++ b/src/box/raft.c >> @@ -83,6 +83,24 @@ box_raft_request_to_msg(const struct raft_request *req, struct raft_msg *msg) >>      }; >>  } >> >> +static void >> +box_raft_update_synchro_queue(struct raft *raft) >> +{ >> +    assert(raft == box_raft()); >> +    if (raft->state != RAFT_STATE_LEADER) >> +        return; >> +    int rc = 0; >> +    uint32_t errcode = 0; >> +    do { >> +        rc = box_promote_qsync(); >> +        if (rc != 0) { >> +            struct error *err = diag_last_error(diag_get()); >> +            errcode = box_error_code(err); >> +            diag_log(); >> +        } > 3. Could it stop being a leader during the retries? Would it > make sense to continue them then? Thanks for noticing! Check out the diff: =============================== diff --git a/src/box/box.cc b/src/box/box.cc index 4882b76a4..c7a972992 100644 --- a/src/box/box.cc +++ b/src/box/box.cc @@ -1698,6 +1698,10 @@ box_promote_qsync(void)         int64_t wait_lsn = box_wait_limbo_acked(TIMEOUT_INFINITY);         if (wait_lsn < 0)                 return -1; +       if (raft->state != RAFT_STATE_LEADER) { +               diag_set(ClientError, ER_NOT_LEADER, raft->leader); +               return -1; +       }         box_issue_promote(txn_limbo.owner_id, wait_lsn);         return 0;  } diff --git a/src/box/errcode.h b/src/box/errcode.h index d2854677f..906cd28b2 100644 --- a/src/box/errcode.h +++ b/src/box/errcode.h @@ -278,6 +278,7 @@ struct errcode_record {         /*223 */_(ER_INTERFERING_PROMOTE,       "Instance with replica id %u was promoted first") \         /*224 */_(ER_ELECTION_DISABLED,         "Elections were turned off")\         /*225 */_(ER_TXN_ROLLBACK,              "Transaction was rolled back") \ +       /*226 */_(ER_NOT_LEADER,                "The instance is not a leader. New leader is %u")\  /*   * !IMPORTANT! Please follow instructions at start of the file =============================== > >> +    } while (rc != 0 && errcode == ER_QUORUM_WAIT && !fiber_is_cancelled()); >> +} -- Serge Petrenko