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]
if ct then
local co = coroutine.running()
table.insert(ct, co)
skynet.wait(co)
return assert(ct.channel)
local channel
while ct do
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
ct = {}
connecting[key] = ct
@@ -53,8 +59,17 @@ local function open_channel(t, key)
else
err = string.format("changenode [%s] (%s:%s) failed", key, host, port)
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
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
connecting[key] = nil
for _, co in ipairs(ct) do

View File

@@ -59,8 +59,13 @@ local function read_response(sock)
end
function command.changenode(host, port)
channel:changehost(host, tonumber(port))
channel:connect(true)
if not host then
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))
end