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 F42326EC55; Thu, 22 Jul 2021 02:26:33 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org F42326EC55 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1626909994; bh=vOhl2M0OgSk8lU59NCM1D3RL87sedKOIfXMszmbdw5Y=; 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=BfxajQnO/EZzdx8CruS/eedG6xk5CDr4FnW9Sa1qyN0lyxOtTtE7m629fnaxKIBrg gZW+W242lvs2VdTUCESYANOy2L1QdfUWEPs7lcf4Kz1vWuKloSwS2jE+GiWjhRxX0X 8U+xvgIPZ061JwzPk1IxvmaZzVnqvGnRN+IKrSFE= Received: from smtpng1.i.mail.ru (smtpng1.i.mail.ru [94.100.181.251]) (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 91D876EC55 for ; Thu, 22 Jul 2021 02:26:32 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 91D876EC55 Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1m6Lbj-0000ry-EX; Thu, 22 Jul 2021 02:26:32 +0300 To: Serge Petrenko , gorcunov@gmail.com Cc: tarantool-patches@dev.tarantool.org References: <5c38c2b4f516ce3777b2f3374f6c76f8e9229448.1626287002.git.sergepetrenko@tarantool.org> Message-ID: Date: Thu, 22 Jul 2021 01:26:30 +0200 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: <5c38c2b4f516ce3777b2f3374f6c76f8e9229448.1626287002.git.sergepetrenko@tarantool.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD941C43E597735A9C386C8E0DDEE7E2465724AB895DD30A549182A05F538085040D3527C5FE5E87A2ADE5B867CC0378004291F683FD6DC6D6B64EE90A6AD4C6E5E X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7DC4D3EB6E237C32AEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637EFACF7FB96444C4B8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D87B1215EB32F67A7157AB62544B280279117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC974A882099E279BDA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352033AC447995A7AD18F04B652EEC242312D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B613439FA09F3DCB32089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-C1DE0DAB: 0D63561A33F958A5D54A997A45764B31DF072E12E9E5CE538C4D8B287CC9C71AD59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA7501A9DF589746230F410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34BF5454112BD5BFD7FDBCDA8103A0CD25D113EA56080A9F6645C887EA5DBE892349021BA8D1913DF71D7E09C32AA3244C6D72876E531BE6AEC41531A182F3520430452B15D76AEC14FACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojaAaPr+N/4d1YGyL85Swm/Q== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5D2E15A632FE54CCC207B7C0647F4E84413841015FED1DE5223CC9A89AB576DD93FB559BB5D741EB963CF37A108A312F5C27E8A8C3839CE0E267EA787935ED9F1B X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH v4 09/16] box: split promote() into reasonable parts 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" Thanks for working on this! See 3 comments below. > diff --git a/src/box/box.cc b/src/box/box.cc > index 86370514a..445875f8f 100644 > --- a/src/box/box.cc > +++ b/src/box/box.cc > @@ -1527,6 +1527,147 @@ box_wait_quorum(uint32_t lead_id, int64_t target_lsn, int quorum, <...> > + > +/** > + * Check whether the greatest promote term has changed since it was last read. > + * IOW check that a foreign PROMOTE arrived while we were sleeping. > + */ > +static int > +box_check_promote_term_changed(uint64_t promote_term) 1. Normally you call check functions using the pattern "check_something_correct". Here the correct behaviour is the term being intact. So I propose to rename it to box_check_promote_term_intact. > +{ > + if (txn_limbo.promote_greatest_term != promote_term) { > + diag_set(ClientError, ER_INTERFERING_PROMOTE, > + txn_limbo.owner_id); > + return -1; > + } > + return 0; > +} <...> > + > +/** > + * A helper to wait until all limbo entries are ready to be confirmed, i.e. > + * written to WAL and have gathered a quorum of ACKs from replicas. > + * Return lsn of the last limbo entry on success, -1 on error. > + */ > +static int64_t > +box_wait_limbo_acked(void) > +{ > + if (txn_limbo_is_empty(&txn_limbo)) > + return txn_limbo.confirmed_lsn; > + > + uint64_t promote_term = txn_limbo.promote_greatest_term; > + int quorum = replication_synchro_quorum; > + struct txn_limbo_entry *last_entry; > + last_entry = txn_limbo_last_synchro_entry(&txn_limbo); > + /* Wait for the last entries WAL write. */ > + if (last_entry->lsn < 0) { > + int64_t tid = last_entry->txn->id; > + > + if (wal_sync(NULL) < 0) > + return -1; > + > + if (box_check_promote_term_changed(promote_term) < 0) 2. Why < 0? It is not a in the code guidelines, but don't we usually use '!= 0'? '< 0' normally assumes you can get > 0, 0, and < 0 meaning different things, like it is done in iproto occassionally. > + return -1; > + if (txn_limbo_is_empty(&txn_limbo)) > + return txn_limbo.confirmed_lsn; > + if (tid != txn_limbo_last_synchro_entry(&txn_limbo)->txn->id) { > + diag_set(ClientError, ER_QUORUM_WAIT, quorum, > + "new synchronous transactions appeared"); > + return -1; > + } > + } <...> > + > +/** Write and process a PROMOTE request. */ > +static void > +box_issue_promote(uint32_t prev_leader_id, int64_t promote_lsn) > +{ > + assert(box_raft()->volatile_term == box_raft()->term); > + assert(promote_lsn >= 0); > + txn_limbo_write_promote(&txn_limbo, promote_lsn, > + box_raft()->term); 3. Maybe cache box_raft() value in a variable? Its usage would look shorter then. The same in other places where it is used more than once. Up to you. > + struct synchro_request req = { > + .type = IPROTO_PROMOTE, > + .replica_id = prev_leader_id, > + .origin_id = instance_id, > + .lsn = promote_lsn, > + .term = box_raft()->term, > + }; > + txn_limbo_process(&txn_limbo, &req); > + assert(txn_limbo_is_empty(&txn_limbo)); > +}