From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org> To: tarantool-patches@freelists.org Cc: kostja@tarantool.org Subject: [tarantool-patches] [PATCH 4/4] swim: default generation is timestamp Date: Fri, 28 Jun 2019 01:25:46 +0200 [thread overview] Message-ID: <10331a1cf299564445f145ccff4af4913c055454.1561677891.git.v.shpilevoy@tarantool.org> (raw) In-Reply-To: <cover.1561677891.git.v.shpilevoy@tarantool.org> Generation is supposed to be a persistent counter to distinguish between different installations of the same SWIM instance. By default it was set to 0, which was quite unsafe. Kostja proposed an easy and bright solution - generation could be set to timestamp by default. In such a case on each restart it is almost 100% will be different. Follow up #4280 --- src/lua/swim.lua | 4 +++- test/swim/swim.result | 24 ++++++++++++------------ test/swim/swim.test.lua | 24 ++++++++++++------------ 3 files changed, 27 insertions(+), 25 deletions(-) diff --git a/src/lua/swim.lua b/src/lua/swim.lua index 69d077c37..01eeb7eae 100644 --- a/src/lua/swim.lua +++ b/src/lua/swim.lua @@ -969,7 +969,7 @@ end -- provided. -- local function swim_new(cfg) - local generation = 0 + local generation if cfg and type(cfg) == 'table' and cfg.generation then generation = cfg.generation if type(generation) ~= 'number' or generation < 0 or @@ -985,6 +985,8 @@ local function swim_new(cfg) if next(cfg) == nil then cfg = nil end + else + generation = fiber.time64() end local ptr = internal.swim_new(generation) if ptr == nil then diff --git a/test/swim/swim.result b/test/swim/swim.result index 26f74f9f4..c7d539f5d 100644 --- a/test/swim/swim.result +++ b/test/swim/swim.result @@ -208,10 +208,10 @@ s:delete() -- -- Basic member table manipulations. -- -s1 = swim.new({uuid = uuid(1), uri = uri(), heartbeat_rate = 0.01}) +s1 = swim.new({uuid = uuid(1), uri = uri(), heartbeat_rate = 0.01, generation = 0}) --- ... -s2 = swim.new({uuid = uuid(2), uri = listen_uri, heartbeat_rate = 0.01}) +s2 = swim.new({uuid = uuid(2), uri = listen_uri, heartbeat_rate = 0.01, generation = 0}) --- ... s1.broadcast() @@ -381,7 +381,7 @@ s2:delete() -- -- Member API. -- -s1 = swim.new({uuid = uuid(1), uri = uri()}) +s1 = swim.new({uuid = uuid(1), uri = uri(), generation = 0}) --- ... s = s1:self() @@ -699,10 +699,10 @@ self:is_dropped() -- -- Check payload dissemination. -- -s1 = swim.new({uuid = uuid(1), uri = uri(), heartbeat_rate = 0.01}) +s1 = swim.new({uuid = uuid(1), uri = uri(), heartbeat_rate = 0.01, generation = 0}) --- ... -s2 = swim.new({uuid = uuid(2), uri = uri(), heartbeat_rate = 0.01}) +s2 = swim.new({uuid = uuid(2), uri = uri(), heartbeat_rate = 0.01, generation = 0}) --- ... s1:add_member({uuid = uuid(2), uri = s2:self():uri()}) @@ -757,7 +757,7 @@ s2:delete() function iterate() local t = {} for k, v in s:pairs() do table.insert(t, {k, v}) end return t end --- ... -s = swim.new() +s = swim.new({generation = 0}) --- ... iterate() @@ -832,10 +832,10 @@ s:delete() -- -- Payload caching. -- -s1 = swim.new({uuid = uuid(1), uri = uri(), heartbeat_rate = 0.01}) +s1 = swim.new({uuid = uuid(1), uri = uri(), heartbeat_rate = 0.01, generation = 0}) --- ... -s2 = swim.new({uuid = uuid(2), uri = uri(), heartbeat_rate = 0.01}) +s2 = swim.new({uuid = uuid(2), uri = uri(), heartbeat_rate = 0.01, generation = 0}) --- ... s1_self = s1:self() @@ -1014,10 +1014,10 @@ s:delete() -- -- Encryption. -- -s1 = swim.new({uuid = uuid(1), uri = uri()}) +s1 = swim.new({uuid = uuid(1), uri = uri(), generation = 0}) --- ... -s2 = swim.new({uuid = uuid(2), uri = uri()}) +s2 = swim.new({uuid = uuid(2), uri = uri(), generation = 0}) --- ... s1.set_codec() @@ -1224,7 +1224,7 @@ s2:delete() -- gh-4250: allow to set triggers on a new member appearance, old -- member drop, member update. -- -s1 = swim.new() +s1 = swim.new({generation = 0}) --- ... s1.on_member_event() @@ -1313,7 +1313,7 @@ t_yield_id = s1:on_member_event(t_yield, 'ctx2') f_need_sleep = true --- ... -s2 = swim.new({uuid = uuid(2), uri = uri(), heartbeat_rate = 0.01}) +s2 = swim.new({uuid = uuid(2), uri = uri(), heartbeat_rate = 0.01, generation = 0}) --- ... s2:add_member({uuid = s1:self():uuid(), uri = s1:self():uri()}) diff --git a/test/swim/swim.test.lua b/test/swim/swim.test.lua index 496beced5..c949b3be2 100644 --- a/test/swim/swim.test.lua +++ b/test/swim/swim.test.lua @@ -71,8 +71,8 @@ s:delete() -- -- Basic member table manipulations. -- -s1 = swim.new({uuid = uuid(1), uri = uri(), heartbeat_rate = 0.01}) -s2 = swim.new({uuid = uuid(2), uri = listen_uri, heartbeat_rate = 0.01}) +s1 = swim.new({uuid = uuid(1), uri = uri(), heartbeat_rate = 0.01, generation = 0}) +s2 = swim.new({uuid = uuid(2), uri = listen_uri, heartbeat_rate = 0.01, generation = 0}) s1.broadcast() s1:broadcast('wrong port') @@ -132,7 +132,7 @@ s2:delete() -- -- Member API. -- -s1 = swim.new({uuid = uuid(1), uri = uri()}) +s1 = swim.new({uuid = uuid(1), uri = uri(), generation = 0}) s = s1:self() s s:status() @@ -233,8 +233,8 @@ self:is_dropped() -- -- Check payload dissemination. -- -s1 = swim.new({uuid = uuid(1), uri = uri(), heartbeat_rate = 0.01}) -s2 = swim.new({uuid = uuid(2), uri = uri(), heartbeat_rate = 0.01}) +s1 = swim.new({uuid = uuid(1), uri = uri(), heartbeat_rate = 0.01, generation = 0}) +s2 = swim.new({uuid = uuid(2), uri = uri(), heartbeat_rate = 0.01, generation = 0}) s1:add_member({uuid = uuid(2), uri = s2:self():uri()}) while s2:size() ~= 2 do fiber.sleep(0.01) end s1_view = s2:member_by_uuid(uuid(1)) @@ -256,7 +256,7 @@ s2:delete() -- Iterators. -- function iterate() local t = {} for k, v in s:pairs() do table.insert(t, {k, v}) end return t end -s = swim.new() +s = swim.new({generation = 0}) iterate() s:cfg({uuid = uuid(1), uri = uri(), gc_mode = 'off'}) s.pairs() @@ -270,8 +270,8 @@ s:delete() -- -- Payload caching. -- -s1 = swim.new({uuid = uuid(1), uri = uri(), heartbeat_rate = 0.01}) -s2 = swim.new({uuid = uuid(2), uri = uri(), heartbeat_rate = 0.01}) +s1 = swim.new({uuid = uuid(1), uri = uri(), heartbeat_rate = 0.01, generation = 0}) +s2 = swim.new({uuid = uuid(2), uri = uri(), heartbeat_rate = 0.01, generation = 0}) s1_self = s1:self() _ = s1:add_member({uuid = s2:self():uuid(), uri = s2:self():uri()}) _ = s2:add_member({uuid = s1_self:uuid(), uri = s1_self:uri()}) @@ -344,8 +344,8 @@ s:delete() -- -- Encryption. -- -s1 = swim.new({uuid = uuid(1), uri = uri()}) -s2 = swim.new({uuid = uuid(2), uri = uri()}) +s1 = swim.new({uuid = uuid(1), uri = uri(), generation = 0}) +s2 = swim.new({uuid = uuid(2), uri = uri(), generation = 0}) s1.set_codec() s1:set_codec(100) @@ -418,7 +418,7 @@ s2:delete() -- gh-4250: allow to set triggers on a new member appearance, old -- member drop, member update. -- -s1 = swim.new() +s1 = swim.new({generation = 0}) s1.on_member_event() m_list = {} @@ -452,7 +452,7 @@ m_list = {} e_list = {} ctx_list = {} t_yield_id = s1:on_member_event(t_yield, 'ctx2') f_need_sleep = true -s2 = swim.new({uuid = uuid(2), uri = uri(), heartbeat_rate = 0.01}) +s2 = swim.new({uuid = uuid(2), uri = uri(), heartbeat_rate = 0.01, generation = 0}) s2:add_member({uuid = s1:self():uuid(), uri = s1:self():uri()}) while s1:size() ~= 2 do fiber.sleep(0.01) end -- Only first trigger worked. Second is waiting, because first -- 2.20.1 (Apple Git-117)
next prev parent reply other threads:[~2019-06-27 23:25 UTC|newest] Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-06-27 23:25 [tarantool-patches] [PATCH 0/4] SWIM amendments Vladislav Shpilevoy 2019-06-27 23:25 ` [tarantool-patches] [PATCH 1/4] swim: fix a leak when a trigger is installed Vladislav Shpilevoy 2019-06-27 23:25 ` [tarantool-patches] [PATCH 2/4] swim: fix a dangerous yield in ffi.gc Vladislav Shpilevoy 2019-06-27 23:25 ` [tarantool-patches] [PATCH 3/4] swim: fix inability to set generation only Vladislav Shpilevoy 2019-06-27 23:25 ` Vladislav Shpilevoy [this message] 2019-06-28 11:25 ` [tarantool-patches] Re: [PATCH 0/4] SWIM amendments Konstantin Osipov 2019-06-28 21:02 ` Vladislav Shpilevoy
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=10331a1cf299564445f145ccff4af4913c055454.1561677891.git.v.shpilevoy@tarantool.org \ --to=v.shpilevoy@tarantool.org \ --cc=kostja@tarantool.org \ --cc=tarantool-patches@freelists.org \ --subject='Re: [tarantool-patches] [PATCH 4/4] swim: default generation is timestamp' \ /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