From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp60.i.mail.ru (smtp60.i.mail.ru [217.69.128.40]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 30740441840 for ; Mon, 30 Mar 2020 14:02:48 +0300 (MSK) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 13.0 \(3608.40.2.2.4\)) From: Serge Petrenko In-Reply-To: <20200328055744.GA23207@atlas> Date: Mon, 30 Mar 2020 14:02:46 +0300 Content-Transfer-Encoding: quoted-printable Message-Id: <1A4735AC-A4B1-4CEA-AC0E-0CA173EFDECE@tarantool.org> References: <56c1a9001fafcd7525fdd3c6a68be2760b095532.1585303629.git.sergepetrenko@tarantool.org> <20200328055744.GA23207@atlas> Subject: Re: [Tarantool-patches] [PATCH v4 2/4] replication: hide 0-th vclock components in replication responses List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Konstantin Osipov Cc: tarantool-patches@dev.tarantool.org, Vladislav Shpilevoy > 28 =D0=BC=D0=B0=D1=80=D1=82=D0=B0 2020 =D0=B3., =D0=B2 08:57, = Konstantin Osipov =D0=BD=D0=B0=D0=BF=D0=B8=D1=81= =D0=B0=D0=BB(=D0=B0): >=20 > * Serge Petrenko [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. >>=20 >> 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. >=20 > If you added vclock_compare_ignore0, suggest to introduce and use=20 > vclock_copy_ignore0 instead of a pair vclock_copy + vclock_reset. Ok. The diff=E2=80=99s below. >=20 > Where was vclock_compare_ignore0 introduced, did I miss the > patch? I added it in one of the anonymous replica patches. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D 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]; } =20 +/** + * 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); } =20 +/** + * 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; } =20 -/** - * 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) { = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D 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) =20 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 =3D header->sync; coio_write_xrow(io, &row); @@ -1777,8 +1776,7 @@ box_process_join(struct ev_io *io, struct = xrow_header *header) =20 /* 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); =20 row.sync =3D header->sync; @@ -1911,8 +1909,7 @@ box_process_vote(struct ballot *ballot) */ ballot->is_loading =3D 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); } =20 /** 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 =3D sync; coio_write_xrow(&relay->io, &row); >=20 > --=20 > Konstantin Osipov, Moscow, Russia -- Serge Petrenko sergepetrenko@tarantool.org