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 706056EC5F; Sat, 17 Apr 2021 01:24:30 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 706056EC5F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1618611870; bh=j1m6PzQKAdPZ+dayPT3Slj9nFOaZU/FWSiJo0r0zjQI=; 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=K+s/1bahTvBYfYhcu/F4/f9B+ZO7tgrStwbJ+Kkny890DKefZBIoW2i+nLamfbIFK ztCTvRZqe4k/3POapMMBRtbIiBu0+jUixlhodudqeP/VzQrS/TyreobsKQKS5osINX sUX+rK9xXRPjra5SPxtVjSOT/0aHFKY79sHjUH4o= Received: from smtp53.i.mail.ru (smtp53.i.mail.ru [94.100.177.113]) (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 8E7E76EC5F for ; Sat, 17 Apr 2021 01:24:28 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 8E7E76EC5F Received: by smtp53.i.mail.ru with esmtpa (envelope-from ) id 1lXWt1-0006pG-Vd; Sat, 17 Apr 2021 01:24:28 +0300 To: Serge Petrenko , gorcunov@gmail.com Cc: tarantool-patches@dev.tarantool.org References: Message-ID: <05b14638-53d8-51db-4a85-3adafd611db6@tarantool.org> Date: Sat, 17 Apr 2021 00:24:27 +0200 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.9.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD92FFCB8E6708E7480257C85EA0BB7A95D0F00AE41BB9A5343182A05F53808504036F95FAEA13AA7E2D1B3915F96345AD33F020EAD9C4314078F7F61EC41E79AAD X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7E188839ED9CF357EEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006375045C080FAAE96148638F802B75D45FF914D58D5BE9E6BC1A93B80C6DEB9DEE97C6FB206A91F05B2C2BFF9BB4D24A9D90F634A67207710DB79373A8315E4CF65D2E47CDBA5A96583C09775C1D3CA48CFE478A468B35FE767117882F4460429724CE54428C33FAD30A8DF7F3B2552694AC26CFBAC0749D213D2E47CDBA5A9658378DA827A17800CE71DD432BB81541BCF9FA2833FD35BB23DF004C90652538430302FCEF25BFAB3454AD6D5ED66289B5278DA827A17800CE75FA4EAFDF67E9D92D32BA5DBAC0009BE395957E7521B51C20BC6067A898B09E4090A508E0FED6299176DF2183F8FC7C0D405410565B6B015CD04E86FAF290E2D7E9C4E3C761E06A71DD303D21008E298D5E8D9A59859A8B6B372FE9A2E580EFC725E5C173C3A84C369456C5265B6C55C35872C767BF85DA2F004C90652538430E4A6367B16DE6309 X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A2368A440D3B0F6089093C9A16E5BC824A2A04A2ABAA09D25379311020FFC8D4ADC9C490B0B7E26B4639745FB2D4257D4E X-C1DE0DAB: 0D63561A33F958A5D0DE4A8205B17D5A4DF47CF01701123F60F37882A80C2E64D59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA7502E6951B79FF9A3F410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D347D10A9FCB2A62DFEC815ACE95E8C1E79083DE8DB5F960E7732D232FC25CB6546EE7AACAA5A41BB481D7E09C32AA3244CB74E9463AA503F0AEFA9EB583BE19285D9ADFF0C0BDB8D1FFACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojr8JA+pXcDunGyc8oGgc6Sw== X-Mailru-Sender: 504CC1E875BF3E7D9BC0E5172ADA31101810D3E46D7ED85624C5AB159C009C65C21B9075C3705D6207784C02288277CA03E0582D3806FB6A5317862B1921BA260ED6CFD6382C13A6112434F685709FCF0DA7A0AF5A3A8387 X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH v4 10/12] election: support manual elections in clear_synchro_queue() 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 the patch! See 1 comment below. > diff --git a/src/box/box.cc b/src/box/box.cc > index d5a55a30a..fcd812c09 100644 > --- a/src/box/box.cc > +++ b/src/box/box.cc > @@ -1521,12 +1521,75 @@ box_clear_synchro_queue(bool try_wait) > if (!is_box_configured || > raft_node_term(box_raft(), instance_id) == box_raft()->term) > return 0; > + > + bool run_elections = false; > + > + switch (box_election_mode) { > + case ELECTION_MODE_OFF: > + break; > + case ELECTION_MODE_VOTER: > + assert(box_raft()->state == RAFT_STATE_FOLLOWER); > + diag_set(ClientError, ER_UNSUPPORTED, "election_mode='voter'", > + "manual elections"); > + return -1; > + case ELECTION_MODE_MANUAL: > + assert(box_raft()->state == RAFT_STATE_FOLLOWER); > + run_elections = true; > + try_wait = false; > + break; > + case ELECTION_MODE_CANDIDATE: > + /* > + * Leader elections are enabled, and this instance is allowed to > + * promote only if it's already an elected leader. No manual > + * elections. > + */ > + if (box_raft()->state != RAFT_STATE_LEADER) { > + diag_set(ClientError, ER_UNSUPPORTED, "election_mode=" > + "'candidate'", "manual elections"); > + return -1; > + } > + break; > + default: > + unreachable(); > + } > + > uint32_t former_leader_id = txn_limbo.owner_id; > int64_t wait_lsn = txn_limbo.confirmed_lsn; > int rc = 0; > int quorum = replication_synchro_quorum; > in_clear_synchro_queue = true; > > + if (run_elections) { > + /* > + * Make this instance a candidate and run until some leader, not > + * necessarily this instance, emerges. > + */ > + raft_start_candidate(box_raft()); > + /* > + * Trigger new elections without waiting for an old leader to > + * disappear. > + */ > + raft_new_term(box_raft()); > + box_raft_wait_leader_found(); Shouldn't we wait for election_timeout? Also what if the fiber is canceled before the leader is found? It seems box_raft_wait_leader_found() would fail on an assertion because raft is still enabled, but leader_id is nil. > + /* > + * Do not reset raft mode if it was changed while running the > + * elections. > + */ > + if (box_election_mode == ELECTION_MODE_MANUAL) > + raft_stop_candidate(box_raft(), false); > + if (!box_raft()->is_enabled) { > + diag_set(ClientError, ER_RAFT_DISABLED); > + in_clear_synchro_queue = false; > + return -1; > + } > + if (box_raft()->state != RAFT_STATE_LEADER) { > + diag_set(ClientError, ER_INTERFERING_PROMOTE, > + box_raft()->leader); > + in_clear_synchro_queue = false; > + return -1; > + } > + } > + > if (txn_limbo_is_empty(&txn_limbo)) > goto promote; >