From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id D969D309E8 for ; Wed, 5 Jun 2019 17:54:02 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 43_RBDqkB118 for ; Wed, 5 Jun 2019 17:54:02 -0400 (EDT) Received: from smtp48.i.mail.ru (smtp48.i.mail.ru [94.100.177.108]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id 76EB22F64A for ; Wed, 5 Jun 2019 17:54:02 -0400 (EDT) Subject: [tarantool-patches] Re: [PATCH 5/5] swim: expose Lua triggers on member update From: Vladislav Shpilevoy References: <0c433f21-734a-c755-110a-9b71a7172c99@tarantool.org> Message-ID: <34f824f7-77fd-7865-de59-5bf9d990466d@tarantool.org> Date: Wed, 5 Jun 2019 23:54:00 +0200 MIME-Version: 1.0 In-Reply-To: <0c433f21-734a-c755-110a-9b71a7172c99@tarantool.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-Help: List-Unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-Subscribe: List-Owner: List-post: List-Archive: To: tarantool-patches@freelists.org Cc: kostja@tarantool.org There is names update: ======================================================================= diff --git a/src/lua/swim.c b/src/lua/swim.c index 17441e58c..c3a0a9911 100644 --- a/src/lua/swim.c +++ b/src/lua/swim.c @@ -36,26 +36,26 @@ static uint32_t ctid_swim_member_ptr; static uint32_t ctid_swim_ptr; -/** Push member update context into a Lua stack. */ +/** Push member event context into a Lua stack. */ static int -lua_swim_on_member_update_push(struct lua_State *L, void *event) +lua_swim_member_event_push(struct lua_State *L, void *event) { - struct swim_on_member_update_ctx *ctx = - (struct swim_on_member_update_ctx *) event; + struct swim_on_member_event_ctx *ctx = + (struct swim_on_member_event_ctx *) event; *(struct swim_member **) luaL_pushcdata(L, ctid_swim_member_ptr) = ctx->member; lua_pushinteger(L, ctx->events); return 2; } -/** Hang or/and delete a trigger on a SWIM member update. */ +/** Set or/and delete a trigger on a SWIM member event. */ static int -lua_swim_on_member_update(struct lua_State *L) +lua_swim_on_member_event(struct lua_State *L) { uint32_t ctypeid; struct swim *s = *(struct swim **) luaL_checkcdata(L, 1, &ctypeid); - return lbox_trigger_reset(L, 3, swim_trigger_list_on_member_update(s), - lua_swim_on_member_update_push, NULL); + return lbox_trigger_reset(L, 3, swim_trigger_list_on_member_event(s), + lua_swim_member_event_push, NULL); } /** @@ -98,7 +98,7 @@ tarantool_lua_swim_init(struct lua_State *L) static const struct luaL_Reg lua_swim_internal_methods [] = { {"swim_new", lua_swim_new}, {"swim_delete", lua_swim_delete}, - {"swim_on_member_update", lua_swim_on_member_update}, + {"swim_on_member_event", lua_swim_on_member_event}, {NULL, NULL} }; luaL_register_module(L, "swim", lua_swim_internal_methods); diff --git a/src/lua/swim.lua b/src/lua/swim.lua index 9b8ff1c29..a7d5caab3 100644 --- a/src/lua/swim.lua +++ b/src/lua/swim.lua @@ -699,7 +699,7 @@ local function swim_pairs(s) return swim_pairs_next, {swim = s, iterator = iterator}, nil end -local swim_on_member_update_index = { +local swim_member_event_index = { is_new = function(self) return bit.band(self[1], capi.SWIM_EV_NEW) ~= 0 end, @@ -723,11 +723,11 @@ local swim_on_member_update_index = { end, } -local swim_on_member_update_event_mt = { - __index = swim_on_member_update_index, +local swim_member_event_mt = { + __index = swim_member_event_index, __serialize = function(self) local res = {} - for k, v in pairs(swim_on_member_update_index) do + for k, v in pairs(swim_member_event_index) do v = v(self) if v then res[k] = v @@ -739,42 +739,42 @@ local swim_on_member_update_event_mt = { -- -- Create a closure function for preprocessing raw SWIM member --- update trigger parameters. +-- event trigger parameters. -- @param s SWIM instance. -- @param callback User functions to call. -- @param ctx An optional parameter for @a callback passed as is. -- @return A function to set as a trigger. -- -local function swim_on_member_update_new(s, callback, ctx) +local function swim_on_member_event_new(s, callback, ctx) return function(member_ptr, event_mask) local m = swim_wrap_member(s, member_ptr) - local event = setmetatable({event_mask}, swim_on_member_update_event_mt) + local event = setmetatable({event_mask}, swim_member_event_mt) return callback(m, event, ctx) end end -- --- Add or/and delete a trigger on member update. Possible usages: +-- Add or/and delete a trigger on member event. Possible usages: -- --- * on_member_update(new[, ctx]) - add a new trigger. It should +-- * on_member_event(new[, ctx]) - add a new trigger. It should -- accept 3 arguments: an updated member, an events object, an -- optional @a ctx parameter passed as is. -- --- * on_member_update(new, old[, ctx]) - add a new trigger @a new +-- * on_member_event(new, old[, ctx]) - add a new trigger @a new -- if not nil, in place of @a old trigger. -- --- * on_member_update() - get a list of triggers. +-- * on_member_event() - get a list of triggers. -- -local function swim_on_member_update(s, new, old, ctx) - local ptr = swim_check_instance(s, 'swim:on_member_update') +local function swim_on_member_event(s, new, old, ctx) + local ptr = swim_check_instance(s, 'swim:on_member_event') if type(old) ~= 'function' then ctx = old old = nil end if new ~= nil then - new = swim_on_member_update_new(s, new, ctx) + new = swim_on_member_event_new(s, new, ctx) end - return internal.swim_on_member_update(ptr, new, old) + return internal.swim_on_member_event(ptr, new, old) end -- @@ -796,7 +796,7 @@ local swim_mt = { set_payload = swim_set_payload, set_codec = swim_set_codec, pairs = swim_pairs, - on_member_update = swim_on_member_update, + on_member_event = swim_on_member_event, }, __serialize = swim_serialize } @@ -889,7 +889,7 @@ local swim_not_configured_mt = { delete = swim_delete, is_configured = swim_is_configured, set_codec = swim_set_codec, - on_member_update = swim_on_member_update, + on_member_event = swim_on_member_event, }, __serialize = swim_serialize } diff --git a/test/swim/swim.result b/test/swim/swim.result index 1de903b04..0196837c8 100644 --- a/test/swim/swim.result +++ b/test/swim/swim.result @@ -1223,9 +1223,9 @@ s2:delete() s1 = swim.new() --- ... -s1.on_member_update() +s1.on_member_event() --- -- error: 'builtin/swim.lua:: swim:on_member_update: first argument is not a SWIM +- error: 'builtin/swim.lua:: swim:on_member_event: first argument is not a SWIM instance' ... m_list = {} @@ -1263,7 +1263,7 @@ end; _ = test_run:cmd("setopt delimiter ''"); --- ... -t_save_event_id = s1:on_member_update(t_save_event, 'ctx') +t_save_event_id = s1:on_member_event(t_save_event, 'ctx') --- ... -- Not equal, because SWIM wraps user triggers with a closure for @@ -1301,7 +1301,7 @@ ctx_list m_list = {} e_list = {} ctx_list = {} --- ... -t_yield_id = s1:on_member_update(t_yield, 'ctx2') +t_yield_id = s1:on_member_event(t_yield, 'ctx2') --- ... f_need_sleep = true @@ -1400,11 +1400,11 @@ ctx_list m_list = {} e_list = {} ctx_list = {} --- ... -#s1:on_member_update() +#s1:on_member_event() --- - 2 ... -s1:on_member_update(nil, t_yield_id) +s1:on_member_event(nil, t_yield_id) --- ... s2:quit() @@ -1413,7 +1413,7 @@ s2:quit() while s1:size() ~= 1 do fiber.sleep(0.01) end --- ... --- Process update. +-- Process event. fiber.sleep(0) --- ... @@ -1453,7 +1453,7 @@ m_list[1] == m_list[2] m_list = {} e_list = {} ctx_list = {} --- ... -s1:on_member_update(nil, t_save_event_id) +s1:on_member_event(nil, t_save_event_id) --- ... s1:add_member({uuid = m:uuid(), uri = m:uri()}) @@ -1463,7 +1463,7 @@ s1:add_member({uuid = m:uuid(), uri = m:uri()}) fiber.sleep(0) --- ... --- No updates - all the triggers are dropped. +-- No events - all the triggers are dropped. m_list --- - [] diff --git a/test/swim/swim.test.lua b/test/swim/swim.test.lua index 25eb5a7d0..458e349e0 100644 --- a/test/swim/swim.test.lua +++ b/test/swim/swim.test.lua @@ -418,7 +418,7 @@ s2:delete() -- member drop, member update. -- s1 = swim.new() -s1.on_member_update() +s1.on_member_event() m_list = {} e_list = {} @@ -437,7 +437,7 @@ t_yield = function(m, e, ctx) while f_need_sleep do fiber.sleep(10000) end end; _ = test_run:cmd("setopt delimiter ''"); -t_save_event_id = s1:on_member_update(t_save_event, 'ctx') +t_save_event_id = s1:on_member_event(t_save_event, 'ctx') -- Not equal, because SWIM wraps user triggers with a closure for -- context preprocessing. t_save_event_id ~= t_save_event @@ -449,7 +449,7 @@ e_list ctx_list m_list = {} e_list = {} ctx_list = {} -t_yield_id = s1:on_member_update(t_yield, 'ctx2') +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:add_member({uuid = s1:self():uuid(), uri = s1:self():uri()}) @@ -472,12 +472,12 @@ m_list e_list ctx_list m_list = {} e_list = {} ctx_list = {} -#s1:on_member_update() +#s1:on_member_event() -s1:on_member_update(nil, t_yield_id) +s1:on_member_event(nil, t_yield_id) s2:quit() while s1:size() ~= 1 do fiber.sleep(0.01) end --- Process update. +-- Process event. fiber.sleep(0) -- Two events - status update to 'left', and 'drop'. m_list @@ -488,10 +488,10 @@ m = m_list[1] m_list[1] == m_list[2] m_list = {} e_list = {} ctx_list = {} -s1:on_member_update(nil, t_save_event_id) +s1:on_member_event(nil, t_save_event_id) s1:add_member({uuid = m:uuid(), uri = m:uri()}) fiber.sleep(0) --- No updates - all the triggers are dropped. +-- No events - all the triggers are dropped. m_list e_list ctx_list