[Tarantool-patches] [PATCH v4 2/4] replication: hide 0-th vclock components in replication responses

Serge Petrenko sergepetrenko at tarantool.org
Mon Mar 30 14:02:46 MSK 2020


> 28 марта 2020 г., в 08:57, Konstantin Osipov <kostja.osipov at gmail.com> написал(а):
> 
> * Serge Petrenko <sergepetrenko at tarantool.org> [20/03/27 18:08]:
>> If an anonymous replica is promoted to a normal one and becomes
>> replication master later, its vclock contains a non-empty zero
>> component, tracking local changes on this replica from the time when it
>> had been anonymous. No need to pollute joining instance's vclock with
>> our non-empty 0 component.
>> When an anonymous replica reports its status to a remote instance it
>> should also hide its 0-th vclock component.
>> 
>> This is needed for backward compatibility with old instances, which
>> don't ignore 0th vclock component coming from a remote instance by
>> default.
>> Also make sure that new instances ignore 0th vclock component.
> 
> If you added vclock_compare_ignore0, suggest to introduce and use 
> vclock_copy_ignore0 instead of a pair vclock_copy + vclock_reset.

Ok. The diff’s below.

> 
> Where was vclock_compare_ignore0 introduced, did I miss the
> patch?

I added it in one of the anonymous replica patches.

=============================================================
1st patch:

diff --git a/src/box/vclock.h b/src/box/vclock.h
index aeb8ca66b..2a3a29020 100644
--- a/src/box/vclock.h
+++ b/src/box/vclock.h
@@ -182,6 +182,19 @@ vclock_inc(struct vclock *vclock, uint32_t replica_id)
 	return ++vclock->lsn[replica_id];
 }
 
+/**
+ * Set vclock component represented by replica id to the desired
+ * value. Can be used to decrease stored LSN value for the given
+ * replica id while maintaining a valid signature or in the same
+ * manner as vclock_follow.
+ *
+ * @param vclock Vector clock.
+ * @param replica_id Replica identifier.
+ * @param lsn Lsn to set
+ */
+void
+vclock_reset(struct vclock *vclock, uint32_t replica_id, int64_t lsn);
+
 static inline void
 vclock_copy(struct vclock *dst, const struct vclock *src)
 {
@@ -194,6 +207,17 @@ vclock_copy(struct vclock *dst, const struct vclock *src)
 			 sizeof(*dst->lsn) * max_pos);
 }
 
+/**
+ * A shortcut for vclock_copy() + vclock_reset() for 0th clock
+ * component.
+ */
+static inline void
+vclock_copy_ignore0(struct vclock *dst, const struct vclock *src)
+{
+	vclock_copy(dst, src);
+	vclock_reset(dst, 0, 0);
+}
+
 static inline uint32_t
 vclock_size(const struct vclock *vclock)
 {
@@ -211,19 +235,6 @@ vclock_calc_sum(const struct vclock *vclock)
 	return sum;
 }
 
-/**
- * Set vclock component represented by replica id to the desired
- * value. Can be used to decrease stored LSN value for the given
- * replica id while maintaining a valid signature or in the same
- * manner as vclock_follow.
- *
- * @param vclock Vector clock.
- * @param replica_id Replica identifier.
- * @param lsn Lsn to set
- */
-void
-vclock_reset(struct vclock *vclock, uint32_t replica_id, int64_t lsn);
-
 static inline int64_t
 vclock_sum(const struct vclock *vclock)
 {

============================================================================
2nd patch:

diff --git a/src/box/applier.cc b/src/box/applier.cc
index 2e765ca12..f5f67b6a9 100644
--- a/src/box/applier.cc
+++ b/src/box/applier.cc
@@ -174,8 +174,7 @@ applier_writer_f(va_list ap)
 		try {
 			struct xrow_header xrow;
 			struct vclock vclock;
-			vclock_copy(&vclock, &replicaset.vclock);
-			vclock_reset(&vclock, 0, 0);
+			vclock_copy_ignore0(&vclock, &replicaset.vclock);
 			xrow_encode_vclock(&xrow, &vclock);
 			coio_write_xrow(&io, &xrow);
 		} catch (SocketError *e) {
diff --git a/src/box/box.cc b/src/box/box.cc
index 87e836432..b49fdbe21 100644
--- a/src/box/box.cc
+++ b/src/box/box.cc
@@ -1622,8 +1622,7 @@ box_process_register(struct ev_io *io, struct xrow_header *header)
 
 	struct xrow_header row;
 	/* Send end of WAL stream marker */
-	vclock_copy(&vclock, &replicaset.vclock);
-	vclock_reset(&vclock, 0, 0);
+	vclock_copy_ignore0(&vclock, &replicaset.vclock);
 	xrow_encode_vclock_xc(&row, &vclock);
 	row.sync = header->sync;
 	coio_write_xrow(io, &row);
@@ -1777,8 +1776,7 @@ box_process_join(struct ev_io *io, struct xrow_header *header)
 
 	/* Send end of WAL stream marker */
 	struct vclock vclock;
-	vclock_copy(&vclock, &replicaset.vclock);
-	vclock_reset(&vclock, 0, 0);
+	vclock_copy_ignore0(&vclock, &replicaset.vclock);
 	xrow_encode_vclock_xc(&row, &vclock);
 
 	row.sync = header->sync;
@@ -1911,8 +1909,7 @@ box_process_vote(struct ballot *ballot)
 	 */
 	ballot->is_loading = is_ro;
 	vclock_copy(&ballot->vclock, &replicaset.vclock);
-	vclock_copy(&ballot->gc_vclock, &gc.vclock);
-	vclock_reset(&ballot->gc_vclock, 0, 0);
+	vclock_copy_ignore0(&ballot->gc_vclock, &gc.vclock);
 }
 
 /** Insert a new cluster into _schema */
diff --git a/src/box/relay.cc b/src/box/relay.cc
index 9abf35fdf..5ed8f5dae 100644
--- a/src/box/relay.cc
+++ b/src/box/relay.cc
@@ -323,9 +323,7 @@ relay_initial_join(int fd, uint64_t sync, struct vclock *vclock)
 	/* Respond to the JOIN request with the current vclock. */
 	struct xrow_header row;
 	struct vclock subst_vclock;
-	vclock_copy(&subst_vclock, vclock);
-	/* zero - out 0-th vclock component. */
-	vclock_reset(&subst_vclock, 0, 0);
+	vclock_copy_ignore0(&subst_vclock, vclock);
 	xrow_encode_vclock_xc(&row, &subst_vclock);
 	row.sync = sync;
 	coio_write_xrow(&relay->io, &row);


> 
> -- 
> Konstantin Osipov, Moscow, Russia

--
Serge Petrenko
sergepetrenko at tarantool.org




More information about the Tarantool-patches mailing list