Tarantool development patches archive
 help / color / mirror / Atom feed
From: Serge Petrenko <sergepetrenko@tarantool.org>
To: v.shpilevoy@tarantool.org, gorcunov@gmail.com
Cc: tarantool-patches@dev.tarantool.org
Subject: [Tarantool-patches] [PATCH] applier: fix tx boundary check for half-applied txns
Date: Sun,  5 Jul 2020 14:57:49 +0300	[thread overview]
Message-ID: <20200705115749.45407-1-sergepetrenko@tarantool.org> (raw)

In case there are 2 "new" instances, running tarantool 2.2+,
master and replica, and one "old" instance, running an earlier tarantool
version, in a full-mesh cluster, it may happen that the "new" replica
receives part of a tx from an "old" instance, and the remaining part
from a "new" instance.

Since "new" instances preserve tx boundaries, "new" replica would skip
the tx remains assuming it has already applied the full tx if it has
applied the first tx row. This leads to gaps in "new" replica's WAL and
to skipping the remaining part of the tx forever.

Fix this behaviour to apply the full tx even if it's beginning is
already applied in mixed clusters.

Closes #5125
---

https://github.com/tarantool/tarantool/issues/5125
https://github.com/tarantool/tarantool/tree/sp/gh-5125-applier-tx-boundaries

 src/box/applier.cc | 23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)

diff --git a/src/box/applier.cc b/src/box/applier.cc
index df48b4796..6ca4cca94 100644
--- a/src/box/applier.cc
+++ b/src/box/applier.cc
@@ -737,6 +737,7 @@ applier_apply_tx(struct stailq *rows)
 	struct xrow_header *first_row = &stailq_first_entry(rows,
 					struct applier_tx_row, next)->row;
 	struct xrow_header *last_row;
+	last_row = &stailq_last_entry(rows, struct applier_tx_row, next)->row;
 	struct replica *replica = replica_by_id(first_row->replica_id);
 	/*
 	 * In a full mesh topology, the same set of changes
@@ -748,9 +749,28 @@ applier_apply_tx(struct stailq *rows)
 			       &replicaset.applier.order_latch);
 	latch_lock(latch);
 	if (vclock_get(&replicaset.applier.vclock,
-		       first_row->replica_id) >= first_row->lsn) {
+		       last_row->replica_id) >= last_row->lsn) {
 		latch_unlock(latch);
 		return 0;
+	} else if (vclock_get(&replicaset.applier.vclock,
+			      first_row->replica_id) >= first_row->lsn) {
+		/*
+		 * We've received part of the tx from an old
+		 * instance not knowing of tx boundaries.
+		 * Skip the already applied part.
+		 */
+		struct xrow_header *tmp;
+		while (true) {
+			tmp = &stailq_first_entry(rows,
+						  struct applier_tx_row,
+						  next)->row;
+			if (tmp->lsn <= vclock_get(&replicaset.applier.vclock,
+						   tmp->replica_id)) {
+				stailq_shift(rows);
+			} else {
+				break;
+			}
+		}
 	}
 
 	/**
@@ -835,7 +855,6 @@ applier_apply_tx(struct stailq *rows)
 	 * instances, which send every single tx row as a separate
 	 * transaction.
 	 */
-	last_row = &stailq_last_entry(rows, struct applier_tx_row, next)->row;
 	vclock_follow(&replicaset.applier.vclock, last_row->replica_id,
 		      last_row->lsn);
 	latch_unlock(latch);
-- 
2.24.3 (Apple Git-128)

             reply	other threads:[~2020-07-05 11:58 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-05 11:57 Serge Petrenko [this message]
2020-07-05 16:11 ` Vladislav Shpilevoy
2020-07-06  6:33 ` Kirill Yukhin

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=20200705115749.45407-1-sergepetrenko@tarantool.org \
    --to=sergepetrenko@tarantool.org \
    --cc=gorcunov@gmail.com \
    --cc=tarantool-patches@dev.tarantool.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH] applier: fix tx boundary check for half-applied txns' \
    /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