From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp40.i.mail.ru (smtp40.i.mail.ru [94.100.177.100]) (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 F05EB4696C3 for ; Fri, 1 May 2020 22:56:11 +0300 (MSK) References: <20200424162855.25920-1-sergepetrenko@tarantool.org> From: Vladislav Shpilevoy Message-ID: <42b75006-21a7-40be-c4bd-e1e83e2c0aaf@tarantool.org> Date: Fri, 1 May 2020 21:56:09 +0200 MIME-Version: 1.0 In-Reply-To: <20200424162855.25920-1-sergepetrenko@tarantool.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Subject: Re: [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: Serge Petrenko , kostja.osipov@gmail.com, gorcunov@gmail.com Cc: tarantool-patches@dev.tarantool.org Hi! Thanks for the patch! > 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. > > Note, that when you issue a plain `box.info.replication_anon`, the only > info returned is the number of anonymous replicas following the current > instance. In order to see the full stats, you have to call > `box.info.replication_anon()` . This is done to not overload the `box.info` > output with excess info, since there may be lots of anonymous replicas. Double whitespaces on this line and previous. Also see 2 nits about comments below. > diff --git a/src/box/lua/info.c b/src/box/lua/info.c > index a789f7822..e7318fcd1 100644 > --- a/src/box/lua/info.c > +++ b/src/box/lua/info.c > @@ -214,6 +214,54 @@ 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 */ 1. Better write comments on separate lines, use '.' in the end of sentences and capital letters when start them. > + 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_pushliteral(L, "count"); > + lua_pushinteger(L, replicaset.anon_count); > + lua_settable(L, -3); > + > + lua_newtable(L); /* metatable */ 2. Here too. > + > + lua_pushstring(L, "__call"); > + lua_pushcfunction(L, lbox_info_replication_anon_call); > + lua_settable(L, -3); > + > + lua_setmetatable(L, -2); > + return 1; > +}