From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp16.mail.ru (smtp16.mail.ru [94.100.176.153]) (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 00B194696C3 for ; Sun, 22 Dec 2019 20:59:18 +0300 (MSK) References: From: Vladislav Shpilevoy Message-ID: Date: Sun, 22 Dec 2019 18:59:17 +0100 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Subject: Re: [Tarantool-patches] [PATCH 4/5] vclock: ignore 0th component in comparisons. List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: sergepetrenko , georgy@tarantool.org Cc: tarantool-patches@dev.tarantool.org Thanks for the patch! See 2 comments below. On 15/12/2019 21:58, sergepetrenko wrote: > 0th vclock component will be used to count replica-local rows of an > anonymous replica. These rows won't be replicated and different > instances will have different values in vclock[0]. So ignore 0th > component in comparisons. 1. Lets add 'Part of #3186'. > --- > src/box/vclock.h | 7 +++++++ > test/unit/vclock.cc | 8 ++++---- > 2 files changed, 11 insertions(+), 4 deletions(-) > > diff --git a/src/box/vclock.h b/src/box/vclock.h > index b5eddcf8b..5dddbd173 100644 > --- a/src/box/vclock.h > +++ b/src/box/vclock.h > @@ -281,6 +281,13 @@ vclock_compare(const struct vclock *a, const struct vclock *b) > > for (size_t replica_id = bit_iterator_next(&it); replica_id < VCLOCK_MAX; > replica_id = bit_iterator_next(&it)) { > + /* > + * Ignore 0-th component in comparisons. > + * It is empty for normal replicas and should > + * be ignored for anonymous ones. > + */ > + if (replica_id == 0) > + continue; > > int64_t lsn_a = vclock_get(a, replica_id); > int64_t lsn_b = vclock_get(b, replica_id); 2. Consider this refactoring in order not to compare replica_id with 0 on each iteration: ================================================================================ diff --git a/src/box/vclock.h b/src/box/vclock.h index 5dddbd173..fc6aeb724 100644 --- a/src/box/vclock.h +++ b/src/box/vclock.h @@ -279,16 +279,15 @@ vclock_compare(const struct vclock *a, const struct vclock *b) struct bit_iterator it; bit_iterator_init(&it, &map, sizeof(map), true); - for (size_t replica_id = bit_iterator_next(&it); replica_id < VCLOCK_MAX; - replica_id = bit_iterator_next(&it)) { - /* - * Ignore 0-th component in comparisons. - * It is empty for normal replicas and should - * be ignored for anonymous ones. - */ - if (replica_id == 0) - continue; - + size_t replica_id = bit_iterator_next(&it); + /* + * Ignore 0-th component in comparisons. It is empty for + * normal replicas and should be ignored for anonymous + * ones. + */ + if (replica_id == 0) + replica_id = bit_iterator_next(&it); + for (; replica_id < VCLOCK_MAX; replica_id = bit_iterator_next(&it)) { int64_t lsn_a = vclock_get(a, replica_id); int64_t lsn_b = vclock_get(b, replica_id); le = le && lsn_a <= lsn_b; ================================================================================