Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladislav Shpilevoy via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: Cyrill Gorcunov <gorcunov@gmail.com>,
	tml <tarantool-patches@dev.tarantool.org>
Subject: Re: [Tarantool-patches] [PATCH v8 2/2] relay: provide information about downstream lag
Date: Mon, 7 Jun 2021 21:21:09 +0200	[thread overview]
Message-ID: <decaacd4-f2ff-42f6-7c9d-7628b89284d9@tarantool.org> (raw)
In-Reply-To: <20210607155519.109626-3-gorcunov@gmail.com>

Thanks for the patch!

See 6 comments below.

> diff --git a/src/box/relay.cc b/src/box/relay.cc
> index b1571b361..cdd1383e8 100644
> --- a/src/box/relay.cc
> +++ b/src/box/relay.cc
> @@ -158,6 +158,18 @@ struct relay {
>  	struct stailq pending_gc;
>  	/** Time when last row was sent to peer. */
>  	double last_row_time;
> +	/**
> +	 * A time difference between the moment when we
> +	 * wrote a transaction to the local WAL and when
> +	 * this transaction has been replicated to remote
> +	 * node (ie written to node's WAL).
> +	 */
> +	double txn_lag;
> +	/**
> +	 * Last timestamp observed from remote node to
> +	 * persist @a txn_lag value.
> +	 */
> +	double txn_acked_tm;
>  	/** Relay sync state. */
>  	enum relay_state state;
>  
> @@ -217,6 +229,12 @@ relay_last_row_time(const struct relay *relay)
>  	return relay->last_row_time;
>  }
>  
> +double
> +relay_txn_lag(const struct relay *relay)
> +{
> +	return relay->txn_lag;

1. As I said in the previous review, you can't read a variable from another
thread without any protection.

Please, use the way I proposed last time. Relay has 'tx' struct inside,
which is updated on each received ACK. You need to deliver the lag value
to TX thread in the same way as the acked vclock is delivered. In the
same message preferably.

> @@ -629,6 +659,26 @@ 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);
> +			/*
> +			 * Replica send us last replicated transaction
> +			 * timestamp which is needed for relay lag
> +			 * monitoring. Note that this transaction has
> +			 * been written to WAL with our current realtime
> +			 * clock value, thus when it get reported back we
> +			 * can compute time spent regardless of the clock
> +			 * value on remote replica.
> +			 *
> +			 * An interesting moment is replica restart - it will
> +			 * send us value 0 after that but we can preserve
> +			 * old reported value here since we *assume* that
> +			 * timestamp is not going backwards on properly
> +			 * set up nodes, otherwise the lag get raised.
> +			 * After all this is a not tamper-proof value.

2. I don't understand. Why does it send value 0? And if it does, why
can't you ignore only zeros? The non-0 values must be valid anyway.

> +			 */
> +			if (relay->txn_acked_tm < xrow.tm) {
> +				relay->txn_acked_tm = xrow.tm;
> +				relay->txn_lag = ev_now(loop()) - xrow.tm;
> +			}
> diff --git a/test/replication/gh-5447-downstream-lag.result b/test/replication/gh-5447-downstream-lag.result
> new file mode 100644
> index 000000000..8586d0ed3
> --- /dev/null
> +++ b/test/replication/gh-5447-downstream-lag.result
> @@ -0,0 +1,93 @@
> +-- test-run result file version 2
> +--
> +-- gh-5447: Test for box.info.replication[n].downstream.lag.
> +-- We need to be sure that if replica start been back of
> +-- master node reports own lagging and cluster admin would
> +-- be able to detect such situation.

3. I couldn't parse the last sentence. Could you use some
punctuation? It might help.

> +--
> +
> +fiber = require('fiber')
> + | ---
> + | ...
> +test_run = require('test_run').new()
> + | ---
> + | ...
> +engine = test_run:get_cfg('engine')
> + | ---
> + | ...
> +
> +box.schema.user.grant('guest', 'replication')
> + | ---
> + | ...
> +
> +test_run:cmd('create server replica with rpl_master=default, \
> +             script="replication/replica.lua"')
> + | ---
> + | - true
> + | ...
> +test_run:cmd('start server replica')
> + | ---
> + | - true
> + | ...
> +
> +s = box.schema.space.create('test', {engine = engine})
> + | ---
> + | ...
> +_ = s:create_index('pk')
> + | ---
> + | ...
> +
> +--
> +-- The replica should wait some time (wal delay is 1 second
> +-- by default) so we would be able to detect the lag, since
> +-- on local instances the lag is minimal and usually transactions
> +-- are handled instantly.

4. But it is not 1 second. usleep(1000) means 1 millisecond, and it
happens in a loop, so it does not matter much. It works until you
set the delay back to false. That makes WAL thread blocked until
you free it. It is not a fixed delay.

> +test_run:switch('replica')
> + | ---
> + | - true
> + | ...
> +box.error.injection.set("ERRINJ_WAL_DELAY", true)
> + | ---
> + | - ok
> + | ...
> +
> +test_run:switch('default')
> + | ---
> + | - true
> + | ...
> +box.space.test:insert({1})
> + | ---
> + | - [1]
> + | ...
> +test_run:wait_cond(function() return box.info.replication[2].downstream.lag ~= 0 end, 10)

5. This condition is true even before you did the insert.
And it couldn't change during insert, because there are no
ACKs - the replica can't write to WAL because of the delay,
it is blocked in a busy loop.

> + | ---
> + | - true
> + | ...
> +
> +test_run:switch('replica')
> + | ---
> + | - true
> + | ...
> +box.error.injection.set("ERRINJ_WAL_DELAY", false)
> + | ---
> + | - ok
> + | ...
> +--
> +-- Cleanup everything.

6. You need to revoke the granted rights and drop the space.

> +test_run:switch('default')
> + | ---
> + | - true
> + | ...
> +
> +test_run:cmd('stop server replica')
> + | ---
> + | - true
> + | ...
> +test_run:cmd('cleanup server replica')
> + | ---
> + | - true
> + | ...
> +test_run:cmd('delete server replica')
> + | ---
> + | - true
> + | ...

  reply	other threads:[~2021-06-07 19:21 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-07 15:55 [Tarantool-patches] [PATCH v8 0/2] relay: provide downstream lag information Cyrill Gorcunov via Tarantool-patches
2021-06-07 15:55 ` [Tarantool-patches] [PATCH v8 1/2] applier: send transaction's first row WAL time in the applier_writer_f Cyrill Gorcunov via Tarantool-patches
2021-06-07 19:20   ` Vladislav Shpilevoy via Tarantool-patches
2021-06-15  9:36   ` Serge Petrenko via Tarantool-patches
2021-06-16 13:32     ` Cyrill Gorcunov via Tarantool-patches
2021-06-17  9:16       ` Serge Petrenko via Tarantool-patches
2021-06-07 15:55 ` [Tarantool-patches] [PATCH v8 2/2] relay: provide information about downstream lag Cyrill Gorcunov via Tarantool-patches
2021-06-07 19:21   ` Vladislav Shpilevoy via Tarantool-patches [this message]
2021-06-08  8:40     ` Cyrill Gorcunov via Tarantool-patches
2021-06-08  9:58       ` Cyrill Gorcunov via Tarantool-patches
2021-06-08 18:15       ` Vladislav Shpilevoy via Tarantool-patches
2021-06-15 10:03   ` Serge Petrenko via Tarantool-patches
2021-06-17  6:55     ` Cyrill Gorcunov via Tarantool-patches
2021-06-17  9:01       ` Serge Petrenko via Tarantool-patches
2021-06-17  9:58         ` Cyrill Gorcunov via Tarantool-patches
2021-06-07 19:20 ` [Tarantool-patches] [PATCH v8 0/2] relay: provide downstream lag information Vladislav Shpilevoy via Tarantool-patches
2021-06-07 20:00   ` 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=decaacd4-f2ff-42f6-7c9d-7628b89284d9@tarantool.org \
    --to=tarantool-patches@dev.tarantool.org \
    --cc=gorcunov@gmail.com \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH v8 2/2] relay: provide information about downstream lag' \
    /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