Tarantool development patches archive
 help / color / mirror / Atom feed
From: Konstantin Osipov <kostja@tarantool.org>
To: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
Cc: tarantool-patches@freelists.org
Subject: [tarantool-patches] Re: [PATCH 2/2] swim: introduce generation
Date: Sat, 22 Jun 2019 01:31:12 +0300	[thread overview]
Message-ID: <20190621223112.GA7915@atlas> (raw)
In-Reply-To: <c25473aa-fbac-c4d6-0d85-35ff8039b89f@tarantool.org>

* Vladislav Shpilevoy <v.shpilevoy@tarantool.org> [19/06/22 01:03]:

Yup.

> We have decided in a chat, that a user should be
> able to get separately 'generation', 'version', and
> accumulated 'incarnation' as a binary merge of these
> two values. It allows in simple cases do not care
> about generation/version, and stick to the incarnation
> only.
> 
> Concerning API. I suggest the following C API changes:
> 
> -	uint64_t
> -	swim_member_incarnation(const struct swim_member *member);
> 
> +	struct swim_incarnation {
> +		uint64_t generation;
> +		uint64_t version;
> +	};
> +
> +	int
> +	swim_incarnation_cmp(const struct swim_incarnation *l,
> +			     const struct swim_incarnation *r);
> +
> +	struct swim_incarnation
> +	swim_member_incarnation(const struct swim_member *member);
> 
> struct swim_incarnation will be a public structure in order to
> simplify working with C API. I am trying to avoid returning some
> const char * or similarly abstract thing.
> 
> 
> 
> Lua API changes are different. I know, we've talked about
> returning a binary string as an incarnation, but then we need
> separate methods to take version and generation, and waste
> memory on these temporary binary strings, useless for anything
> but comparison. Worse, we will desync with C API.
> 
> 
> I've found a revolutionary feature of Lua FFI which can help us
> very much. It combines your 'merged' incarnation, and my 'totally
> different numbers' incarnation. In Lua FFI you can define your
> own comparison operators for C structs (just learned about that)!
> 
> Method member:incarnation() will return cdata struct swim_incarnation,
> with ffi.metatype containing comparators. struct swim_incarnation
> will be initialized in Lua like this:
> 
> 
> 	ffi = require('ffi')
> 	ffi.cdef[[
> 		struct swim_incarnation {
> 			uint64_t generation;
> 			uint64_t version;
> 		};
> 	]]
> 	inc_t = ffi.typeof('struct swim_incarnation')
> 	inc_mt = {
> 		__eq = function(l, r)
> 			return l.generation == r.generation and
> 			       l.version == r.version
> 		end,
> 		__lt = function(l, r)
> 			return l.generation < r.generation or
> 			       l.generation == r.generation and l.version < r.version
> 		end,
> 		__le = function(l, r)
> 			return l.generation < r.generation or
> 			       l.generation == r.generation and l.version <= r.version
> 		end,
> 	}
> 	ffi.metatype(inc_t, inc_mt)
> 	ia = ffi.new('struct swim_incarnation')
> 	ib = ffi.new('struct swim_incarnation')
> 
> ia and ib can be compared using just '< > <= >= == ~=' operators,
> and at the same time you can access individual members!!!
> 
> What do you think? Both about C and Lua API changes.

-- 
Konstantin Osipov, Moscow, Russia

      reply	other threads:[~2019-06-21 22:31 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-20 21:23 [tarantool-patches] [PATCH 0/2] SWIM generation Vladislav Shpilevoy
2019-06-20 21:23 ` [tarantool-patches] [PATCH 1/2] swim: encapsulate incarnation behind 'age' Vladislav Shpilevoy
2019-06-20 21:23 ` [tarantool-patches] [PATCH 2/2] swim: introduce generation Vladislav Shpilevoy
2019-06-21  6:53   ` [tarantool-patches] " Konstantin Osipov
2019-06-21 19:03     ` Vladislav Shpilevoy
2019-06-21 19:48       ` Konstantin Osipov
2019-06-21 19:53         ` Konstantin Osipov
2019-06-21 22:00           ` Vladislav Shpilevoy
2019-06-21 22:31             ` Konstantin Osipov [this message]

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=20190621223112.GA7915@atlas \
    --to=kostja@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='[tarantool-patches] Re: [PATCH 2/2] swim: introduce generation' \
    /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