This commit is contained in:
云风
2021-07-15 09:35:31 +08:00
committed by GitHub
parent 39e0aaa27e
commit 72a6182601
2 changed files with 26 additions and 6 deletions

View File

@@ -15,9 +15,15 @@ local function open_channel(t, key)
local ct = connecting[key] local ct = connecting[key]
if ct then if ct then
local co = coroutine.running() local co = coroutine.running()
table.insert(ct, co) local channel
skynet.wait(co) while ct do
return assert(ct.channel) table.insert(ct, co)
skynet.wait(co)
channel = ct.channel
ct = connecting[key]
-- reload again if ct ~= nil
end
return assert(node_address[key] and channel)
end end
ct = {} ct = {}
connecting[key] = ct connecting[key] = ct
@@ -53,8 +59,17 @@ local function open_channel(t, key)
else else
err = string.format("changenode [%s] (%s:%s) failed", key, host, port) err = string.format("changenode [%s] (%s:%s) failed", key, host, port)
end end
elseif address == false then
c = node_sender[key]
if c == nil then
-- no sender, always succ
succ = true
else
-- trun off the sender
succ, err = pcall(skynet.call, c, "lua", "changenode", false)
end
else else
err = string.format("cluster node [%s] is %s.", key, address == false and "down" or "absent") err = string.format("cluster node [%s] is absent.", key)
end end
connecting[key] = nil connecting[key] = nil
for _, co in ipairs(ct) do for _, co in ipairs(ct) do

View File

@@ -59,8 +59,13 @@ local function read_response(sock)
end end
function command.changenode(host, port) function command.changenode(host, port)
channel:changehost(host, tonumber(port)) if not host then
channel:connect(true) skynet.error(string.format("Close cluster sender %s:%d", channel.__host, channel.__port))
channel:close()
else
channel:changehost(host, tonumber(port))
channel:connect(true)
end
skynet.ret(skynet.pack(nil)) skynet.ret(skynet.pack(nil))
end end