Skip to content

Commit

Permalink
Add members.remove function
Browse files Browse the repository at this point in the history
  • Loading branch information
yngvar-antonsson committed Nov 23, 2023
1 parent 7a87816 commit cd76a5b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
26 changes: 25 additions & 1 deletion membership.lua
Original file line number Diff line number Diff line change
Expand Up @@ -478,13 +478,17 @@ local function _protocol_step()
local ack_data = wait_ack(uri, loop_now, opts.ACK_TIMEOUT_SECONDS * 1.0e6)
if ack_data ~= nil then
local member = members.get(uri)
if member == nil then
return
end
-- calculate time difference between local time and member time
local delta = _get_clock_delta(ack_data)
members.set(uri, member.status, member.incarnation, { clock_delta = delta }) -- update timstamp
return
end
end
if members.get(uri).status >= opts.DEAD then
local member = members.get(uri)
if member ~= nil and member.status >= opts.DEAD then
-- still dead, do nothing
return
end
Expand All @@ -509,6 +513,9 @@ local function _protocol_step()
end
if sent_indirect > 0 and ack_data ~= nil then
local member = members.get(uri)
if member == nil then
return
end
-- calculate time difference between local time and member time
local delta = _get_clock_delta(ack_data)
members.set(uri, member.status, member.incarnation, { clock_delta = delta })
Expand All @@ -529,9 +536,11 @@ local function _protocol_step()
end
end

local protocol_step_in_progress = fiber.cond()
local function protocol_step()
local t1 = fiber.clock()
local ok, res = xpcall(_protocol_step, debug.traceback)
protocol_step_in_progress:signal()
fiber.testcancel()

if not ok then
Expand Down Expand Up @@ -929,6 +938,20 @@ local function set_payload(key, value)
return true
end

--- Remove a member.
-- @function remove_member
-- @tparam uri string
local function remove_member(uri)
checks('string')
protocol_step_in_progress:wait(60)
local member = members.get(uri)
if member == nil then
return
end

members.remove(uri)
end

do -- finish module loading
opts.after_reload()
events.after_reload()
Expand All @@ -949,6 +972,7 @@ return {
probe_uri = probe_uri,
add_member = add_member,
get_member = get_member,
remove_member = remove_member,
set_payload = set_payload,

--- Encryption Functions.
Expand Down
7 changes: 7 additions & 0 deletions membership/members.lua
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,11 @@ function members.count()
return count
end

function members.remove(uri)
checks('string')

_all_members[uri] = nil
rawget(_G, '__membership_stash')['members._all_members'][uri] = nil
end

return members

0 comments on commit cd76a5b

Please sign in to comment.