From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp15.mail.ru (smtp15.mail.ru [94.100.176.133]) (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 5525D436218 for ; Wed, 18 Mar 2020 22:48:28 +0300 (MSK) From: Serge Petrenko Date: Wed, 18 Mar 2020 22:47:46 +0300 Message-Id: <51d5cb03a56b7e99481d9ab62cb90ba072a83dc3.1584558067.git.sergepetrenko@tarantool.org> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH v2 3/5] vclock: add an ability to set individual clock components List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: v.shpilevoy@tarantool.org, kostja.osipov@gmail.com, georgy@tarantool.org Cc: tarantool-patches@dev.tarantool.org This is needed to 'hide' 0-th vclock component in replication responses. Follow-up #3186 Prerequisite #4114 --- src/box/vclock.c | 15 +++++++++++++++ src/box/vclock.h | 11 +++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/box/vclock.c b/src/box/vclock.c index 90ae27591..302c0438d 100644 --- a/src/box/vclock.c +++ b/src/box/vclock.c @@ -37,6 +37,21 @@ #include "diag.h" #include "tt_static.h" +void +vclock_set(struct vclock *vclock, uint32_t replica_id, int64_t lsn) +{ + assert(lsn >= 0); + assert(replica_id < VCLOCK_MAX); + vclock->signature -= vclock_get(vclock, replica_id); + if (lsn == 0) { + vclock->map &= ~(1 << replica_id); + return; + } + vclock->lsn[replica_id] = lsn; + vclock->map |= 1 << replica_id; + vclock->signature += lsn; +} + int64_t vclock_follow(struct vclock *vclock, uint32_t replica_id, int64_t lsn) { diff --git a/src/box/vclock.h b/src/box/vclock.h index eb0fb5d8b..e54711bc1 100644 --- a/src/box/vclock.h +++ b/src/box/vclock.h @@ -209,6 +209,17 @@ vclock_calc_sum(const struct vclock *vclock) return sum; } +/** + * Set vclock component represented by replica id to the desired + * value. + * + * @param vclock Vector clock. + * @param replica_id Replica identifier. + * @param lsn Lsn to set + */ +void +vclock_set(struct vclock *vclock, uint32_t replica_id, int64_t lsn); + static inline int64_t vclock_sum(const struct vclock *vclock) { -- 2.21.1 (Apple Git-122.3)