set node = false when node is down, see #803

This commit is contained in:
Cloud Wu
2018-02-24 21:26:14 +08:00
parent 9cf4525a8f
commit 1932d33b41
2 changed files with 23 additions and 14 deletions

View File

@@ -20,8 +20,10 @@ skynet.start(function()
-- test snax service
skynet.timeout(300,function()
cluster.reload {
db = false, -- db is down
db3 = "127.0.0.1:2529"
}
print(pcall(cluster.call, "db", sdb, "GET", "a")) -- db is down
end)
local pingserver = cluster.snax("db3", "pingserver")
print(pingserver.req.ping "hello")

View File

@@ -33,19 +33,25 @@ local function open_channel(t, key)
ct.namequery = co
skynet.error("Wating for cluster node [".. key.."]")
skynet.wait(co)
address = assert(node_address[key])
address = node_address[key]
assert(address ~= nil)
end
local host, port = string.match(address, "([^:]+):(.*)$")
local c = sc.channel {
host = host,
port = tonumber(port),
response = read_response,
nodelay = true,
}
local succ, err = pcall(c.connect, c, true)
if succ then
t[key] = c
ct.channel = c
local succ, err, c
if address then
local host, port = string.match(address, "([^:]+):(.*)$")
c = sc.channel {
host = host,
port = tonumber(port),
response = read_response,
nodelay = true,
}
succ, err = pcall(c.connect, c, true)
if succ then
t[key] = c
ct.channel = c
end
else
err = "cluster node [" .. key .. "] is down."
end
connecting[key] = nil
for _, co in ipairs(ct) do
@@ -68,7 +74,7 @@ local function loadconfig(tmp)
end
end
for name,address in pairs(tmp) do
assert(type(address) == "string")
assert(address == false or type(address) == "string")
if node_address[name] ~= address then
-- address changed
if rawget(node_channel, name) then
@@ -92,7 +98,8 @@ end
function command.listen(source, addr, port)
local gate = skynet.newservice("gate")
if port == nil then
addr, port = string.match(node_address[addr], "([^:]+):(.*)$")
local address = assert(node_address[addr], addr .. " is down")
addr, port = string.match(address, "([^:]+):(.*)$")
end
skynet.call(gate, "lua", "open", { address = addr, port = port })
skynet.ret(skynet.pack(nil))