Tarantool development patches archive
 help / color / mirror / Atom feed
From: Konstantin Osipov <kostja@tarantool.org>
To: tarantool-patches@freelists.org
Cc: Georgy Kirichenko <georgy@tarantool.org>
Subject: [tarantool-patches] Re: [PATCH 1/2] Lightweight vclock_create and vclock_copy
Date: Tue, 12 Feb 2019 22:25:24 +0300	[thread overview]
Message-ID: <20190212192524.GB10042@chai> (raw)
In-Reply-To: <ba1b593a3774d0cf11ef03f584fe51784729b983.1549978870.git.georgy@tarantool.org>

* Georgy Kirichenko <georgy@tarantool.org> [19/02/12 17:09]:
>  /**
> @@ -158,6 +159,8 @@ vclock_get(const struct vclock *vclock, uint32_t replica_id)
>  {
>  	if (replica_id >= VCLOCK_MAX)
>  		return 0;

I checked the code and I there is no place which passes arbitrary
replica id. I believe this was added to avoid access to
uninitialized memory in case of corrupt network packet. Now that
vclock_get() becomes a hot path, let's avoid branching by having a
cheaper solution for this problem:

/** Avoid segmentation fault in case of malformed packet. */
replica_id &= VLCOCK_MAX - 1;


> +	if ((vclock->map & (1 << replica_id)) == 0)
> +		return 0;
>  	return vclock->lsn[replica_id];
>  }
>  
> @@ -165,6 +168,8 @@ static inline int64_t
>  vclock_inc(struct vclock *vclock, uint32_t replica_id)
>  {
>  	/* Easier add each time than check. */
> +	if ((vclock->map & (1 << replica_id)) == 0)
> +		vclock->lsn[replica_id] = 0;
>  	vclock->map |= 1 << replica_id;

Since you added a check, please move this assignment inside the
branch.

>  	vclock->signature++;
>  	return ++vclock->lsn[replica_id];
> @@ -173,7 +178,13 @@ vclock_inc(struct vclock *vclock, uint32_t replica_id)
>  static inline void
>  vclock_copy(struct vclock *dst, const struct vclock *src)
>  {
> -	*dst = *src;
> +	if (src->map == 0) {
> +		dst->map = src->map;
> +		dst->signature = src->signature;
> +		return;
> +	}

Why would you ever need this branch? Looks like you can safely
delete it.

> +	unsigned int max_pos = VCLOCK_MAX - bit_clz_u32(src->map);
> +	memcpy(dst, src, offsetof(struct vclock, lsn) + sizeof(*dst->lsn) * max_pos);
>  }

Apart from these minor comments the branch is looking good, thank
you!

-- 
Konstantin Osipov, Moscow, Russia, +7 903 626 22 32
http://tarantool.io - www.twitter.com/kostja_osipov

  reply	other threads:[~2019-02-12 19:25 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-12 14:09 [tarantool-patches] [PATCH 0/2] Reduce wal vclock handling complecity Georgy Kirichenko
2019-02-12 14:09 ` [tarantool-patches] [PATCH 1/2] Lightweight vclock_create and vclock_copy Georgy Kirichenko
2019-02-12 19:25   ` Konstantin Osipov [this message]
2019-02-12 19:37     ` [tarantool-patches] " Георгий Кириченко
2019-02-12 14:09 ` [tarantool-patches] [PATCH 2/2] Track wal vclock changes instead of copying Georgy Kirichenko
2019-02-12 19:15   ` [tarantool-patches] " Konstantin Osipov
2019-02-12 19:47     ` Георгий Кириченко

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190212192524.GB10042@chai \
    --to=kostja@tarantool.org \
    --cc=georgy@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='[tarantool-patches] Re: [PATCH 1/2] Lightweight vclock_create and vclock_copy' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox