[Tarantool-patches] [PATCH v2] replication: add box.info.replication_anon
Serge Petrenko
sergepetrenko at tarantool.org
Mon Apr 27 15:22:36 MSK 2020
> 24 апр. 2020 г., в 19:39, Konstantin Osipov <kostja.osipov at gmail.com> написал(а):
>
> * Serge Petrenko <sergepetrenko at tarantool.org> [20/04/24 19:33]:
>> 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()
>
> Why do you have to use ()? Isn't it inconsistent with
> box.info.replication?
>
It’s done in order to shorten `box.info` output. There may be lots
of anonymous replicas following a master. I’ve updated the commit message
correspondingly.
It was also agreed verbally, that we should output the number of anonymous
replicas following a master on `box.info.replication_anon` without the `()`.
The diff is below.
diff --git a/src/box/lua/info.c b/src/box/lua/info.c
index c4f90bda1..e7318fcd1 100644
--- a/src/box/lua/info.c
+++ b/src/box/lua/info.c
@@ -248,6 +248,10 @@ lbox_info_replication_anon(struct lua_State *L)
*/
lua_newtable(L);
+ lua_pushliteral(L, "count");
+ lua_pushinteger(L, replicaset.anon_count);
+ lua_settable(L, -3);
+
lua_newtable(L); /* metatable */
lua_pushstring(L, "__call");
diff --git a/src/box/replication.cc b/src/box/replication.cc
index 7c10fb6f2..1b61c92c0 100644
--- a/src/box/replication.cc
+++ b/src/box/replication.cc
@@ -219,6 +219,7 @@ replicaset_add_anon(const struct tt_uuid *replica_uuid)
replica->uuid = *replica_uuid;
replica_hash_insert(&replicaset.hash, replica);
replica->anon = true;
+ replicaset.anon_count++;
return replica;
}
@@ -909,6 +910,8 @@ replica_on_relay_stop(struct replica *replica)
* replicas.
*/
assert(replica->applier == NULL);
+ assert(replicaset.anon_count > 0);
+ replicaset.anon_count--;
}
}
if (replica_is_orphan(replica)) {
diff --git a/src/box/replication.h b/src/box/replication.h
index 9df91e611..93a25c8a7 100644
--- a/src/box/replication.h
+++ b/src/box/replication.h
@@ -203,6 +203,8 @@ struct replicaset {
* from a remote master.
*/
bool is_joining;
+ /* A number of anonymous replicas following this instance. */
+ int anon_count;
/** Applier state. */
struct {
/**
diff --git a/test/replication/anon.result b/test/replication/anon.result
index f3f9c60ed..a7e244d3f 100644
--- a/test/replication/anon.result
+++ b/test/replication/anon.result
@@ -154,7 +154,7 @@ test_run:cmd('switch default')
-- Test box.info.replication_anon.
box.info.replication_anon
| ---
- | - []
+ | - count: 1
| ...
#box.info.replication_anon()
| ---
>
> --
> Konstantin Osipov, Moscow, Russia
> https://scylladb.com
--
Serge Petrenko
sergepetrenko at tarantool.org
More information about the Tarantool-patches
mailing list