From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp39.i.mail.ru (smtp39.i.mail.ru [94.100.177.99]) (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 E869F4696C3 for ; Fri, 24 Apr 2020 19:29:20 +0300 (MSK) From: Serge Petrenko Date: Fri, 24 Apr 2020 19:28:55 +0300 Message-Id: <20200424162855.25920-1-sergepetrenko@tarantool.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH v2] replication: add box.info.replication_anon List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: kostja.osipov@gmail.com, v.shpilevoy@tarantool.org, gorcunov@gmail.com Cc: tarantool-patches@dev.tarantool.org Closes #4900 @TarantoolBot document Title: add new field to box.info: replication_anon It is now possible to list all the anonymous replicas following the instance with a call to `box.info.replication_anon()` The output is similar to the one produced by `box.info.replication` with an exception that anonymous replicas are indexed by their uuid strings rather then server ids, since server ids have no meaning for anonymous replicas. Example: ``` tarantool> box.info.replication_anon --- - [] ... tarantool> box.info.replication_anon() --- - 02757524-1887-4c75-9137-d5c191fba507: id: 0 uuid: 02757524-1887-4c75-9137-d5c191fba507 lsn: 0 downstream: status: follow idle: 0.43651100000716 vclock: {1: 1} 937a8292-8f99-4d11-aede-b97e9f5e9473: id: 0 uuid: 937a8292-8f99-4d11-aede-b97e9f5e9473 lsn: 0 downstream: status: follow idle: 0.5189309999987 vclock: {1: 1} ... ``` Note, that anonymous replicas hide their lsn from the others, so anonymous replica lsn will always be reported as zero, even if anonymous replicas perform some local space operations. To know the anonymous replica's lsn, you have to issue `box.info.lsn` on it. --- https://github.com/tarantool/tarantool/issues/4900 https://github.com/tarantool/tarantool/tree/sp/gh-4900-list-anon-replicas Changes in v2: - move anon replicas output to box.info.replication_anon() @ChangeLog - Add `box.info.replication_anon`. When called, it lists anonymous replicas in the same format as `box.info.replication`, the only exception is that anon replicas are indexed by their uuid strings (gh-4900). src/box/lua/info.c | 45 ++++++++++++++++++++++++++++++++++ test/box/info.result | 1 + test/replication/anon.result | 24 +++++++++++++++--- test/replication/anon.test.lua | 11 +++++++-- 4 files changed, 76 insertions(+), 5 deletions(-) diff --git a/src/box/lua/info.c b/src/box/lua/info.c index a789f7822..c4f90bda1 100644 --- a/src/box/lua/info.c +++ b/src/box/lua/info.c @@ -214,6 +214,50 @@ lbox_info_replication(struct lua_State *L) return 1; } +static int +lbox_info_replication_anon_call(struct lua_State *L) +{ + lua_newtable(L); /* box.info.replication_anon */ + + /* Nice formatting */ + lua_newtable(L); /* metatable */ + lua_pushliteral(L, "mapping"); + lua_setfield(L, -2, "__serialize"); + lua_setmetatable(L, -2); + + replicaset_foreach(replica) { + if (!replica->anon) + continue; + + lua_pushstring(L, tt_uuid_str(&replica->uuid)); + lbox_pushreplica(L, replica); + + lua_settable(L, -3); + } + + return 1; +} + +static int +lbox_info_replication_anon(struct lua_State *L) +{ + /* + * Make the .replication_anon field callable in order to + * not flood the output with possibly lots of anonymous + * replicas on box.info call. + */ + lua_newtable(L); + + lua_newtable(L); /* metatable */ + + lua_pushstring(L, "__call"); + lua_pushcfunction(L, lbox_info_replication_anon_call); + lua_settable(L, -3); + + lua_setmetatable(L, -2); + return 1; +} + static int lbox_info_id(struct lua_State *L) { @@ -534,6 +578,7 @@ static const struct luaL_Reg lbox_info_dynamic_meta[] = { {"vclock", lbox_info_vclock}, {"ro", lbox_info_ro}, {"replication", lbox_info_replication}, + {"replication_anon", lbox_info_replication_anon}, {"status", lbox_info_status}, {"uptime", lbox_info_uptime}, {"pid", lbox_info_pid}, diff --git a/test/box/info.result b/test/box/info.result index e6d0ba6aa..40eeae069 100644 --- a/test/box/info.result +++ b/test/box/info.result @@ -83,6 +83,7 @@ t - package - pid - replication + - replication_anon - ro - signature - sql diff --git a/test/replication/anon.result b/test/replication/anon.result index cbbeeef09..f3f9c60ed 100644 --- a/test/replication/anon.result +++ b/test/replication/anon.result @@ -151,10 +151,28 @@ test_run:cmd('switch default') | - true | ... --- Replica isn't visible on master. -#box.info.replication +-- Test box.info.replication_anon. +box.info.replication_anon + | --- + | - [] + | ... +#box.info.replication_anon() + | --- + | - 0 + | ... +uuid, tbl = next(box.info.replication_anon()) + | --- + | ... +-- Anonymous replicas are indexed by uuid strings. +require("uuid").fromstr(uuid) ~= nil + | --- + | - true + | ... +-- Anonymous replicas share box.info representation with +-- normal replicas. +tbl.downstream.status | --- - | - 1 + | - follow | ... -- Test that replication (even anonymous) from an anonymous diff --git a/test/replication/anon.test.lua b/test/replication/anon.test.lua index 627dc5c8e..fef72d07d 100644 --- a/test/replication/anon.test.lua +++ b/test/replication/anon.test.lua @@ -50,8 +50,15 @@ box.space.loc:truncate() test_run:cmd('switch default') --- Replica isn't visible on master. -#box.info.replication +-- Test box.info.replication_anon. +box.info.replication_anon +#box.info.replication_anon() +uuid, tbl = next(box.info.replication_anon()) +-- Anonymous replicas are indexed by uuid strings. +require("uuid").fromstr(uuid) ~= nil +-- Anonymous replicas share box.info representation with +-- normal replicas. +tbl.downstream.status -- Test that replication (even anonymous) from an anonymous -- instance is forbidden. An anonymous replica will fetch -- 2.21.1 (Apple Git-122.3)