Tarantool development patches archive
 help / color / mirror / Atom feed
From: Konstantin Belyavskiy <k.belyavskiy@tarantool.org>
To: tarantool-patches@freelists.org
Subject: [tarantool-patches] [PATCH 1/2] [replication] [recovery] recover missing data
Date: Thu, 29 Mar 2018 19:15:15 +0300	[thread overview]
Message-ID: <c3c0e9cf5566c13da43cb3e028511f140e52eb1e.1522339565.git.k.belyavskiy@tarantool.org> (raw)
In-Reply-To: <cover.1522339565.git.k.belyavskiy@tarantool.org>
In-Reply-To: <cover.1522339565.git.k.belyavskiy@tarantool.org>

Part 1 of 2.
Add vclock comparison as a new synchronization condition.
And update catch test as now it works as expected.

Closes #3210
---
 branch: gh-3210-recover-missing-local-data-master-master
 src/box/applier.cc            | 16 +++++++++++-----
 test/replication/catch.result |  5 +++--
 2 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/src/box/applier.cc b/src/box/applier.cc
index 6bfe5a99a..12bf1f0d2 100644
--- a/src/box/applier.cc
+++ b/src/box/applier.cc
@@ -305,7 +305,7 @@ applier_join(struct applier *applier)
 				 * server is 1.6. Since we have
 				 * not initialized replication
 				 * vclock yet, do it now. In 1.7+
-				 * this vlcock is not used.
+				 * this vclock is not used.
 				 */
 				xrow_decode_vclock_xc(&row, &replicaset.vclock);
 			}
@@ -370,6 +370,7 @@ applier_subscribe(struct applier *applier)
 	struct ev_io *coio = &applier->io;
 	struct ibuf *ibuf = &applier->ibuf;
 	struct xrow_header row;
+	struct vclock remote_vclock_at_subscribe;
 
 	xrow_encode_subscribe_xc(&row, &REPLICASET_UUID, &INSTANCE_UUID,
 				 &replicaset.vclock);
@@ -411,9 +412,8 @@ applier_subscribe(struct applier *applier)
 		 * In case of successful subscribe, the server
 		 * responds with its current vclock.
 		 */
-		struct vclock vclock;
-		vclock_create(&vclock);
-		xrow_decode_vclock_xc(&row, &vclock);
+		vclock_create(&remote_vclock_at_subscribe);
+		xrow_decode_vclock_xc(&row, &remote_vclock_at_subscribe);
 	}
 	/**
 	 * Tarantool < 1.6.7:
@@ -452,8 +452,14 @@ applier_subscribe(struct applier *applier)
 			applier_set_state(applier, APPLIER_FOLLOW);
 		}
 
+		/*
+		 * Must stay in read-only mode, until it synchronized.
+		 * Check lag and compare local vclock with remote one.
+		 */
 		if (applier->state == APPLIER_SYNC &&
-		    applier->lag <= replication_sync_lag) {
+		    applier->lag <= replication_sync_lag &&
+		    vclock_compare(&remote_vclock_at_subscribe,
+				   &replicaset.vclock) <= 0) {
 			/* Applier is synced, switch to "follow". */
 			applier_set_state(applier, APPLIER_FOLLOW);
 		}
diff --git a/test/replication/catch.result b/test/replication/catch.result
index 7d61ad26f..05c1c243e 100644
--- a/test/replication/catch.result
+++ b/test/replication/catch.result
@@ -99,10 +99,11 @@ box.space.test ~= nil
 ...
 d = box.space.test:delete{1}
 ---
+- error: Can't modify data because this instance is in read-only mode.
 ...
 box.space.test:get(1) == nil
 ---
-- true
+- false
 ...
 -- case #2: delete tuple by net.box
 test_run:cmd("switch default")
@@ -118,7 +119,7 @@ c = net_box.connect(r_uri)
 ...
 c.space.test:get(1) == nil
 ---
-- true
+- false
 ...
 -- check sync
 errinj.set("ERRINJ_RELAY_TIMEOUT", 0)
-- 
2.14.3 (Apple Git-98)

  reply	other threads:[~2018-03-29 16:15 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-29 16:15 [tarantool-patches] [PATCH 0/2] " Konstantin Belyavskiy
2018-03-29 16:15 ` Konstantin Belyavskiy [this message]
2018-03-30 11:17   ` [tarantool-patches] [PATCH 1/2] " Vladimir Davydov
2018-03-29 16:15 ` [tarantool-patches] [PATCH 2/2] " Konstantin Belyavskiy
2018-03-30 11:33   ` Vladimir Davydov

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=c3c0e9cf5566c13da43cb3e028511f140e52eb1e.1522339565.git.k.belyavskiy@tarantool.org \
    --to=k.belyavskiy@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='Re: [tarantool-patches] [PATCH 1/2] [replication] [recovery] recover missing data' \
    /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