Tarantool development patches archive
 help / color / mirror / Atom feed
From: sergepetrenko <sergepetrenko@tarantool.org>
To: alexander.turenko@tarantool.org, v.shpilevoy@tarantool.org,
	kostja.osipov@gmail.com
Cc: tarantool-patches@dev.tarantool.org
Subject: [Tarantool-patches] [PATCH v2 2/4] replication: check for rows to skip in applier correctly
Date: Fri, 14 Feb 2020 00:52:58 +0300	[thread overview]
Message-ID: <ef4d3beb98c2216cf2d3b4ecde3f4dee1e8bd4e4.1581630406.git.sergepetrenko@tarantool.org> (raw)
In-Reply-To: <cover.1581630406.git.sergepetrenko@tarantool.org>

From: Serge Petrenko <sergepetrenko@tarantool.org>

Remove applier vclock initialization from replication_init(), where it
is zeroed-out, and place it in the end of box_cfg_xc(), where replicaset
vclock already has a meaningful value.
Do not apply rows originating form the current instance if replication
sync has ended.

Closes #4739
---
 src/box/applier.cc     | 17 +++++++++++++++--
 src/box/box.cc         |  6 ++++++
 src/box/replication.cc |  1 -
 3 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/src/box/applier.cc b/src/box/applier.cc
index ae3d281a5..e931e1595 100644
--- a/src/box/applier.cc
+++ b/src/box/applier.cc
@@ -731,8 +731,21 @@ applier_apply_tx(struct stailq *rows)
 	struct latch *latch = (replica ? &replica->order_latch :
 			       &replicaset.applier.order_latch);
 	latch_lock(latch);
-	if (vclock_get(&replicaset.applier.vclock,
-		       first_row->replica_id) >= first_row->lsn) {
+	/*
+	 * Skip remote rows either if one of the appliers has
+	 * sent them to write or if the rows originate from the
+	 * local instance and we've already synced with the
+	 * replica. The latter is important because relay gets
+	 * notified about WAL write before tx does, so it is
+	 * possible that a remote instance receives our rows
+	 * via replication before we update replicaset vclock and
+	 * even sends these rows back to us. An attemt to apply
+	 * such rows will lead to having entries with duplicate
+	 * LSNs in WAL.
+	 */
+	if (vclock_get(&replicaset.applier.vclock, first_row->replica_id) >=
+	    first_row->lsn || (first_row->replica_id == instance_id &&
+	    !box_is_orphan())) {
 		latch_unlock(latch);
 		return 0;
 	}
diff --git a/src/box/box.cc b/src/box/box.cc
index 0290578b2..952d60ad1 100644
--- a/src/box/box.cc
+++ b/src/box/box.cc
@@ -2425,6 +2425,12 @@ box_cfg_xc(void)
 
 	rmean_cleanup(rmean_box);
 
+	/*
+	 * Local recovery is over so it's fine to update applier
+	 * vclock now.
+	 */
+	vclock_copy(&replicaset.applier.vclock, &replicaset.vclock);
+
 	/* Follow replica */
 	replicaset_follow();
 
diff --git a/src/box/replication.cc b/src/box/replication.cc
index e7bfa22ab..7b04573a4 100644
--- a/src/box/replication.cc
+++ b/src/box/replication.cc
@@ -93,7 +93,6 @@ replication_init(void)
 	latch_create(&replicaset.applier.order_latch);
 
 	vclock_create(&replicaset.applier.vclock);
-	vclock_copy(&replicaset.applier.vclock, &replicaset.vclock);
 	rlist_create(&replicaset.applier.on_rollback);
 	rlist_create(&replicaset.applier.on_commit);
 
-- 
2.20.1 (Apple Git-117)

  parent reply	other threads:[~2020-02-13 21:53 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-13 21:52 [Tarantool-patches] [PATCH v2 0/4] replication: fix applying of rows originating from local instance sergepetrenko
2020-02-13 21:52 ` [Tarantool-patches] [PATCH v2 1/4] box: expose box_is_orphan method sergepetrenko
2020-02-13 21:52 ` sergepetrenko [this message]
2020-02-14  7:19   ` [Tarantool-patches] [PATCH v2 2/4] replication: check for rows to skip in applier correctly Konstantin Osipov
2020-02-14  7:29     ` Konstantin Osipov
2020-02-13 21:52 ` [Tarantool-patches] [PATCH v2 3/4] wal: wart when trying to write a record with a broken lsn sergepetrenko
2020-02-14  7:20   ` Konstantin Osipov
2020-02-14 10:46     ` Serge Petrenko
2020-02-16 16:15   ` Vladislav Shpilevoy
2020-02-18 17:28     ` Serge Petrenko
2020-02-18 21:15       ` Vladislav Shpilevoy
2020-02-19  8:46         ` Serge Petrenko
2020-02-13 21:53 ` [Tarantool-patches] [PATCH v2 4/4] replication: do not promote local_vclock_at_subscribe unnecessarily sergepetrenko
2020-02-14  7:25   ` Konstantin Osipov
2020-02-14 10:46     ` Serge Petrenko
2020-02-14 10:52       ` Konstantin Osipov

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=ef4d3beb98c2216cf2d3b4ecde3f4dee1e8bd4e4.1581630406.git.sergepetrenko@tarantool.org \
    --to=sergepetrenko@tarantool.org \
    --cc=alexander.turenko@tarantool.org \
    --cc=kostja.osipov@gmail.com \
    --cc=tarantool-patches@dev.tarantool.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH v2 2/4] replication: check for rows to skip in applier correctly' \
    /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