From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org> To: Konstantin Osipov <kostja@tarantool.org> Cc: tarantool-patches@freelists.org Subject: [tarantool-patches] Re: [PATCH 2/2] swim: introduce generation Date: Sat, 22 Jun 2019 00:00:23 +0200 [thread overview] Message-ID: <c25473aa-fbac-c4d6-0d85-35ff8039b89f@tarantool.org> (raw) In-Reply-To: <20190621195326.GC28557@atlas> 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.
next prev parent reply other threads:[~2019-06-21 21:59 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 [this message] 2019-06-21 22:31 ` Konstantin Osipov
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=c25473aa-fbac-c4d6-0d85-35ff8039b89f@tarantool.org \ --to=v.shpilevoy@tarantool.org \ --cc=kostja@tarantool.org \ --cc=tarantool-patches@freelists.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