From: Cyrill Gorcunov via Tarantool-patches <tarantool-patches@dev.tarantool.org> To: tml <tarantool-patches@dev.tarantool.org> Cc: Vladislav Shpilevoy <v.shpilevoy@tarantool.org> Subject: [Tarantool-patches] [PATCH v2 2/3] box/info: report replication.X.downstream.lag value Date: Mon, 1 Feb 2021 13:00:36 +0300 [thread overview] Message-ID: <20210201100037.212301-3-gorcunov@gmail.com> (raw) In-Reply-To: <20210201100037.212301-1-gorcunov@gmail.com> This is basically a reflection of replication.X.upstream.lag value. The upstream lag can be considered as transaction RTT in direction from master to replica, in turn downstream lag is the reverse and represents RTT from replica to master. An example of output is (on replica node) | 2: | id: 2 | uuid: 8bb22366-cd21-492e-98df-693884be11bd | lsn: 0 | downstream: | status: follow | idle: 0.55381065199617 | vclock: {1: 119} | lag: 0.00019168853759766 In case if there some old replicas which are not sending timestamp in vclock encoding we simply don't show lag field for backward compatibility sake. Closes #5447 @TarantoolBot document Title: Document box.info.replication[n].downstream.lag replication[n].downstream.lag is time difference between local time of the replica `n` sending current vector clock state and the time this message was received by a master node. Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com> --- src/box/lua/info.c | 8 ++++++++ src/box/relay.cc | 16 ++++++++++++++++ src/box/relay.h | 8 ++++++++ 3 files changed, 32 insertions(+) diff --git a/src/box/lua/info.c b/src/box/lua/info.c index c4c9fa0a0..1e533fe8d 100644 --- a/src/box/lua/info.c +++ b/src/box/lua/info.c @@ -133,16 +133,24 @@ lbox_pushrelay(lua_State *L, struct relay *relay) switch(relay_get_state(relay)) { case RELAY_FOLLOW: + { + double lag = relay_lag(relay); lua_pushstring(L, "follow"); lua_settable(L, -3); lua_pushstring(L, "vclock"); lbox_pushvclock(L, relay_vclock(relay)); lua_settable(L, -3); + if (lag != 0) { + lua_pushstring(L, "lag"); + lua_pushnumber(L, relay_lag(relay)); + lua_settable(L, -3); + } lua_pushstring(L, "idle"); lua_pushnumber(L, ev_monotonic_now(loop()) - relay_last_row_time(relay)); lua_settable(L, -3); break; + } case RELAY_STOPPED: { lua_pushstring(L, "stopped"); diff --git a/src/box/relay.cc b/src/box/relay.cc index df04f8198..f23e43b30 100644 --- a/src/box/relay.cc +++ b/src/box/relay.cc @@ -138,6 +138,8 @@ struct relay { struct stailq pending_gc; /** Time when last row was sent to peer. */ double last_row_time; + /** Number of seconds this master is prior the remote replica. */ + double lag; /** Relay sync state. */ enum relay_state state; @@ -179,6 +181,12 @@ relay_last_row_time(const struct relay *relay) return relay->last_row_time; } +double +relay_lag(const struct relay *relay) +{ + return relay->lag; +} + static void relay_send(struct relay *relay, struct xrow_header *packet); static void @@ -219,6 +227,7 @@ relay_start(struct relay *relay, int fd, uint64_t sync, relay->sync = sync; relay->state = RELAY_FOLLOW; relay->last_row_time = ev_monotonic_now(loop()); + relay->lag = 0; } void @@ -558,6 +567,13 @@ relay_reader_f(va_list ap) /* vclock is followed while decoding, zeroing it. */ vclock_create(&relay->recv_vclock); xrow_decode_vclock_xc(&xrow, &relay->recv_vclock); + /* + * Old versions may send not a timestamp but + * zeroified memory field. We can use +0 as + * a sign that there is nothing encoded. + */ + if (xrow.tm != 0) + relay->lag = ev_now(loop()) - xrow.tm; fiber_cond_signal(&relay->reader_cond); } } catch (Exception *e) { diff --git a/src/box/relay.h b/src/box/relay.h index b32e2ea2a..ec9d16925 100644 --- a/src/box/relay.h +++ b/src/box/relay.h @@ -93,6 +93,14 @@ relay_vclock(const struct relay *relay); double relay_last_row_time(const struct relay *relay); +/** + * Returns relay's lag + * @param relay relay + * @returns relay's lag + */ +double +relay_lag(const struct relay *relay); + /** * Send a Raft update request to the relay channel. It is not * guaranteed that it will be delivered. The connection may break. -- 2.29.2
next prev parent reply other threads:[~2021-02-01 10:01 UTC|newest] Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-02-01 10:00 [Tarantool-patches] [PATCH v2 0/3] box/info: report replication.X.downstream.lag Cyrill Gorcunov via Tarantool-patches 2021-02-01 10:00 ` [Tarantool-patches] [PATCH v2 1/3] applier: encode timestamp into vclock message Cyrill Gorcunov via Tarantool-patches 2021-02-01 10:00 ` Cyrill Gorcunov via Tarantool-patches [this message] 2021-02-04 13:28 ` [Tarantool-patches] [PATCH v2 2/3] box/info: report replication.X.downstream.lag value Serge Petrenko via Tarantool-patches 2021-02-01 10:00 ` [Tarantool-patches] [PATCH v2 3/3] test: replication/status -- fetch downstream lag field Cyrill Gorcunov via Tarantool-patches
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20210201100037.212301-3-gorcunov@gmail.com \ --to=tarantool-patches@dev.tarantool.org \ --cc=gorcunov@gmail.com \ --cc=v.shpilevoy@tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH v2 2/3] box/info: report replication.X.downstream.lag value' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox