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 BC5B9CC30D; Thu, 21 Jan 2021 20:19:05 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org BC5B9CC30D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1611249545; bh=r+gSd+oe7yajkAPAlcJpE1lN1O3SEL9VOVpVuAqJEF4=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=f6o42PNg2KRxJBe7KI8Ui7m9KVsNjRf/p1r3J5k8+hbxm1StQEn6mLKfH1sjmpd7Z WxJRJuI66A2yFngdUMSNZ4MuVGMTmDEuAR8XldfVhmS35YDkkWOAfmTQKGxIyGOG6w lDSFQA9mHbKA72pp+xNdPSatNcuw9wRqvxiORK9Q= Received: from mail-lj1-f169.google.com (mail-lj1-f169.google.com [209.85.208.169]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 067849387A for ; Thu, 21 Jan 2021 20:18:28 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 067849387A Received: by mail-lj1-f169.google.com with SMTP id f4so2491378ljo.11 for ; Thu, 21 Jan 2021 09:18:28 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=nyCds7k3MpkIZbCdiyjLmOG7bf7IOks3+J7jm3SMpuM=; b=SiEabIDa6/p7ROXn3hlh/3IAxhxjuqyYzeQee8fEyygJOi0XADB9ryPUAvMVGVjEV5 bMw/ULBjtpJ0Y5aSGJDb2Y3rEL/qCf8m0BhDtOVS7R/oZIbtyDYi6UFD5i/6WU8Ni7e2 vnE1e1Ye/TS8FbgGfTBw46Y6JnKVHfKb5dgs7aFTCRCKk5nmkxkaQbsIb/CFGfsjfY3U qunmP6VDGwDoldmmIk6Xf2vs1P7o1/RyC9jFF2tNivGFNARZMuqkTKxxBE1b7271gE9K fgpHPvQGIggXEtgOyUxdI9qC4LQS4taVBz76Up7TMd2TlFOjw5qs3EBmHGRVTJPcC334 RZsg== X-Gm-Message-State: AOAM532CaLnQ4YzoLz3P0gy76fWlZXQwUX9fSQaSGfgVWs/KmdowL/J9 t1uiT4R4F5lZFihUC1M8cYgchI9mbsY= X-Google-Smtp-Source: ABdhPJzALyRTFd051du/91sYeWEnzGgZMmSMki615P6tVCRhN2k7VzBTJQ1LW4Gk/0PU1uqNIWsbLw== X-Received: by 2002:a2e:80d6:: with SMTP id r22mr182008ljg.29.1611249506996; Thu, 21 Jan 2021 09:18:26 -0800 (PST) Received: from grain.localdomain ([5.18.91.94]) by smtp.gmail.com with ESMTPSA id q5sm585289lfr.172.2021.01.21.09.18.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Jan 2021 09:18:25 -0800 (PST) Received: by grain.localdomain (Postfix, from userid 1000) id F2FD256017B; Thu, 21 Jan 2021 20:17:58 +0300 (MSK) To: tml Date: Thu, 21 Jan 2021 20:17:51 +0300 Message-Id: <20210121171753.186891-3-gorcunov@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210121171753.186891-1-gorcunov@gmail.com> References: <20210121171753.186891-1-gorcunov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH 2/3] box/info: report replication.X.downstream.lag value 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: Cyrill Gorcunov via Tarantool-patches Reply-To: Cyrill Gorcunov Cc: Vladislav Shpilevoy Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" 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 Signed-off-by: Cyrill Gorcunov --- src/box/lua/info.c | 9 ++++++++- src/box/relay.cc | 17 +++++++++++++++++ src/box/relay.h | 8 ++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/box/lua/info.c b/src/box/lua/info.c index c4c9fa0a0..b36c2e6f4 100644 --- a/src/box/lua/info.c +++ b/src/box/lua/info.c @@ -132,17 +132,24 @@ lbox_pushrelay(lua_State *L, struct relay *relay) lua_pushstring(L, "status"); switch(relay_get_state(relay)) { - case RELAY_FOLLOW: + 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..9265a26b3 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 @@ -197,6 +205,7 @@ relay_new(struct replica *replica) } relay->replica = replica; relay->last_row_time = ev_monotonic_now(loop()); + relay->lag = 0; fiber_cond_create(&relay->reader_cond); diag_create(&relay->diag); stailq_create(&relay->pending_gc); @@ -219,6 +228,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 +568,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 + * as 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