[Tarantool-patches] [PATCH 1/3] vclock: add an ability to set individual clock components

Serge Petrenko sergepetrenko at tarantool.org
Fri Jan 31 17:58:05 MSK 2020


This is needed to 'hide' 0-th vclock component in replication responses.

Follow-up #3186
---
 src/box/vclock.c | 12 ++++++++++++
 src/box/vclock.h | 11 +++++++++++
 2 files changed, 23 insertions(+)

diff --git a/src/box/vclock.c b/src/box/vclock.c
index 90ae27591..90802308e 100644
--- a/src/box/vclock.c
+++ b/src/box/vclock.c
@@ -37,6 +37,17 @@
 #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);
+	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)
 {
@@ -51,6 +62,7 @@ vclock_follow(struct vclock *vclock, uint32_t replica_id, int64_t lsn)
 	return prev_lsn;
 }
 
+
 static int
 vclock_snprint(char *buf, int size, const struct vclock *vclock)
 {
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.0 (Apple Git-122)



More information about the Tarantool-patches mailing list