From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 85A6624D06 for ; Fri, 4 Jan 2019 05:32:55 -0500 (EST) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id pt7ey5hjj7mp for ; Fri, 4 Jan 2019 05:32:55 -0500 (EST) Received: from smtp58.i.mail.ru (smtp58.i.mail.ru [217.69.128.38]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id 41E4524D05 for ; Fri, 4 Jan 2019 05:32:55 -0500 (EST) From: Georgy Kirichenko Subject: [tarantool-patches] [PATCH 5/5] Disallow lsn gaps while vclock following Date: Fri, 4 Jan 2019 13:34:15 +0300 Message-Id: <1b75f8d5ccd7474862a5812550cc68680ba1142e.1546593619.git.georgy@tarantool.org> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-help: List-unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-subscribe: List-owner: List-post: List-archive: To: tarantool-patches@freelists.org Cc: Georgy Kirichenko Only one-step vclock following is allowed. This enforces wal and replication consistency against out of order execution. Needed for: #980 --- src/box/replication.cc | 1 + src/box/vclock.c | 2 +- src/box/xrow.c | 2 +- test/unit/vclock.cc | 10 +++++----- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/box/replication.cc b/src/box/replication.cc index 51e08886c..ee92a941b 100644 --- a/src/box/replication.cc +++ b/src/box/replication.cc @@ -91,6 +91,7 @@ replication_init(void) replicaset.replica_by_id = (struct replica **)calloc(VCLOCK_MAX, sizeof(struct replica *)); latch_create(&replicaset.applier.order_latch); vclock_create(&replicaset.applier.vclock); + vclock_clear(&replicaset.applier.vclock); } void diff --git a/src/box/vclock.c b/src/box/vclock.c index c297d1ff9..807da9109 100644 --- a/src/box/vclock.c +++ b/src/box/vclock.c @@ -56,7 +56,7 @@ vclock_follow(struct vclock *vclock, uint32_t replica_id, int64_t lsn) assert(lsn >= 0); assert(replica_id < VCLOCK_MAX); int64_t prev_lsn = vclock->lsn[replica_id]; - assert(lsn > prev_lsn); + assert(lsn == prev_lsn + 1); /* Easier add each time than check. */ vclock->map |= 1 << replica_id; vclock->lsn[replica_id] = lsn; diff --git a/src/box/xrow.c b/src/box/xrow.c index 67019a68d..ef3f81add 100644 --- a/src/box/xrow.c +++ b/src/box/xrow.c @@ -83,7 +83,7 @@ mp_decode_vclock(const char **data, struct vclock *vclock) return -1; int64_t lsn = mp_decode_uint(data); if (lsn > 0) - vclock_follow(vclock, id, lsn); + vclock_set(vclock, id, lsn); } return 0; } diff --git a/test/unit/vclock.cc b/test/unit/vclock.cc index 8498eba3b..6a8d498ef 100644 --- a/test/unit/vclock.cc +++ b/test/unit/vclock.cc @@ -50,11 +50,11 @@ test_compare_one(uint32_t a_count, const int64_t *lsns_a, vclock_create(&b); for (uint32_t node_id = 0; node_id < a_count; node_id++) { if (lsns_a[node_id] > 0) - vclock_follow(&a, node_id, lsns_a[node_id]); + vclock_set(&a, node_id, lsns_a[node_id]); } for (uint32_t node_id = 0; node_id < b_count; node_id++) { if (lsns_b[node_id] > 0) - vclock_follow(&b, node_id, lsns_b[node_id]); + vclock_set(&b, node_id, lsns_b[node_id]); } return vclock_compare(&a, &b); @@ -119,7 +119,7 @@ testset_create(vclockset_t *set, int64_t *files, int files_n, int node_n) signature += lsn; /* Update cluster hash */ - vclock_follow(vclock, node_id, lsn); + vclock_set(vclock, node_id, lsn); } vclockset_insert(set, vclock); } @@ -225,7 +225,7 @@ test_isearch() if (lsn <= 0) continue; - vclock_follow(&vclock, node_id, lsn); + vclock_set(&vclock, node_id, lsn); } int64_t check = *(query + NODE_N); @@ -247,7 +247,7 @@ test_tostring_one(uint32_t count, const int64_t *lsns, const char *res) vclock_create(&vclock); for (uint32_t node_id = 0; node_id < count; node_id++) { if (lsns[node_id] > 0) - vclock_follow(&vclock, node_id, lsns[node_id]); + vclock_set(&vclock, node_id, lsns[node_id]); } char *str = vclock_to_string(&vclock); int result = strcmp(str, res); -- 2.20.1