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 EED3C6FC82; Fri, 12 Nov 2021 10:30:05 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org EED3C6FC82 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1636702206; bh=FoVwLn0JbPZYDTxnmhCWCI+iz/2dqmUhImHOqhcEOhA=; h=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=FTanvfZpafvZMZWZaE6QWLpeywgLopZbY0HXvOFgWUFOuEV5H6LoQXtAT9bX+pNzq 6C9JjY3Db0ZGLMhnOmL+0Gm5ZunwblME4RgG+K/8Uq78pXEog3iBxJfbEvcVyq46jQ qtww6MHUd8NHQK92q5r/MZhHLPNZC9o63T+8RhmU= Received: from smtp47.i.mail.ru (smtp47.i.mail.ru [94.100.177.107]) (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 BFCA76FC82 for ; Fri, 12 Nov 2021 10:30:04 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org BFCA76FC82 Received: by smtp47.i.mail.ru with esmtpa (envelope-from ) id 1mlR0e-0005XV-0n; Fri, 12 Nov 2021 10:30:04 +0300 Message-ID: Date: Fri, 12 Nov 2021 10:30:03 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.3.0 Content-Language: en-GB To: Vladislav Shpilevoy , tarantool-patches@dev.tarantool.org References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD9731B3922EC0639792FFC8A1478656943FA9F74D7A497B1C400894C459B0CD1B9C1784DCB2F71B5DCC5A4CD83E3E9D3523B3F10494FD07A607454BA882483358B X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7A179494B5629353BEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F790063776672C316918EFDB8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8A5B4287631D0F1DFFA42A7CA9832ECE5117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCF1175FABE1C0F9B6A471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F44604297287769387670735201E561CDFBCA1751FC26CFBAC0749D213D2E47CDBA5A96583BA9C0B312567BB2376E601842F6C81A19E625A9149C048EE7B96B19DC4093321E21AE983DBD7FFC1D8FC6C240DEA7642DBF02ECDB25306B2B78CF848AE20165D0A6AB1C7CE11FEE389DDFE3E282F3DD16136E347CC761E07C4224003CC836476EA7A3FFF5B025636E2021AF6380DFAD1A18204E546F3947CB11811A4A51E3B096D1867E19FE1407959CC434672EE6371089D37D7C0E48F6C8AA50765F7900637C970FD8DF19C51D2EFF80C71ABB335746BA297DBC24807EABDAD6C7F3747799A X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A213B5FB47DCBC3458834459D11680B505139B75DBBC6C2D8EF02FCC2E6F2BF09F X-C1DE0DAB: 0D63561A33F958A52ABEAD9B197F59C25272B9CD7A5994886983C42B3501723AD59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA7536C62C4FBC402878410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D3403182E70AE6895E0CDCDEF71B9691DB105138A060400F1EF16BBAE31F7D64EFF91A34993DBECAED81D7E09C32AA3244CC3A4B2BF6ACE8A1F3B0C181434494D384DBEAD0ED6C55A80729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojLk+X/GdHsnqXdwdc+aiCDA== X-Mailru-Sender: 11C2EC085EDE56FA38FD4C59F7EFE407DD0CF0A9BC9ABF8A9C9DBAFC8597D3A41BA506D4FF90C6E06BB2E709EA627F343C7DDD459B58856F0E45BC603594F5A135B915D4279FF0579437F6177E88F7363CDA0F3B3F5B9367 X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH v2 10/11] box: enrich ER_READONLY with new details 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" 12.11.2021 02:54, Vladislav Shpilevoy пишет: > ER_READONLY used not to have any details about the exact reason > why the instance is read-only. The patch changes that by adding > new fields into the error which explain why the error happened and > even help to avoid it for next requests. > Thanks for the changes! Please, find two comments below. Sorry for coming up late with this one, but I think it'd be good to report ro reason in box.info. Maybe box.info.ro_reason or something similar. Only when box.info.ro is true, of course. Otherwise we help the user only partially. He sees what's wrong when receives an error, but has to check every parameter manually when checks box.info.ro > --- > .../unreleased/gh-5568-readonly-reason.md | 4 + > src/box/box.cc | 54 +++- > .../gh_5568_read_only_reason_test.lua | 285 ++++++++++++++++++ > 3 files changed, 335 insertions(+), 8 deletions(-) > create mode 100644 changelogs/unreleased/gh-5568-readonly-reason.md > create mode 100644 test/replication-luatest/gh_5568_read_only_reason_test.lua > > diff --git a/changelogs/unreleased/gh-5568-readonly-reason.md b/changelogs/unreleased/gh-5568-readonly-reason.md > new file mode 100644 > index 000000000..f3a2db986 > --- /dev/null > +++ b/changelogs/unreleased/gh-5568-readonly-reason.md > @@ -0,0 +1,4 @@ > +## feature/core > + > +* Error objects with the code `box.error.READONLY` now have additional fields > + explaining why the error happened (gh-5568). > diff --git a/src/box/box.cc b/src/box/box.cc > index 1ed1ce3f8..323982969 100644 > --- a/src/box/box.cc > +++ b/src/box/box.cc > @@ -177,16 +177,54 @@ box_update_ro_summary(void) > static int > box_check_writable(void) > { > - if (is_ro_summary) { > + if (!is_ro_summary) > + return 0; > + struct error *e = diag_set(ClientError, ER_READONLY); > + struct raft *raft = box_raft(); > + /* > + * In case of multiple reasons at the same time only one is reported. > + * But the order is important. For example, if the instance has election > + * enabled, for the client it is better to see that it is a 'follower' > + * and who is the leader than just see cfg 'read_only' is true. > + */ > + if (raft_is_ro(raft)) { > + error_set_str(e, "reason", "election"); > + error_set_str(e, "state", raft_state_str(raft->state)); > + error_set_uint(e, "term", raft->volatile_term); > + uint32_t id = raft->leader; > + if (id != REPLICA_ID_NIL) { > + error_set_uint(e, "leader_id", id); > + struct replica *r = replica_by_id(id); > + /* > + * XXX: when the leader is dropped from _cluster, it > + * is not reported to Raft. > + */ > + if (r != NULL) > + error_set_uuid(e, "leader_uuid", &r->uuid); > + } > + } else if (txn_limbo_is_ro(&txn_limbo)) { > + error_set_str(e, "reason", "synchro"); > + uint32_t id = txn_limbo.owner_id; > + error_set_uint(e, "queue_owner_id", id); > + error_set_uint(e, "term", raft->volatile_term); I just noticed, we should report txn_limbo_greatest_term here, probably. This instance (which received ER_READONLY) is the leader, but hasn't claimed the limbo yet. This only makes sense when limbo term is behind raft's one. > + struct replica *r = replica_by_id(id); > /* > - * XXX: return a special error when the node is not a leader to > - * reroute to the leader node. > + * XXX: when an instance is deleted from _cluster, its limbo's > + * ownership is not cleared. > */ > - diag_set(ClientError, ER_READONLY); > - diag_log(); > - return -1; > - } > - return 0; > + if (r != NULL) > + error_set_uuid(e, "queue_owner_uuid", &r->uuid); > + } else { > + error_set_str(e, "reason", "state"); > + if (is_ro) > + error_set_str(e, "state", "read_only"); > + else if (is_orphan) > + error_set_str(e, "state", "orphan"); > + else > + assert(false); > + } > + diag_log(); > + return -1; > } > > static void > -- Serge Petrenko