diff --git a/examples/cluster2.lua b/examples/cluster2.lua index f356357c..69f67438 100644 --- a/examples/cluster2.lua +++ b/examples/cluster2.lua @@ -18,6 +18,11 @@ skynet.start(function() cluster.send("db2", sdb, "PING", "db2:longstring" .. largevalue) -- test snax service - local pingserver = cluster.snax("db", "pingserver") + skynet.timeout(300,function() + cluster.reload { + db3 = "127.0.0.1:2529" + } + end) + local pingserver = cluster.snax("db3", "pingserver") print(pingserver.req.ping "hello") end) diff --git a/service/clusterd.lua b/service/clusterd.lua index 559317ae..8d971e9e 100644 --- a/service/clusterd.lua +++ b/service/clusterd.lua @@ -26,7 +26,16 @@ local function open_channel(t, key) end ct = {} connecting[key] = ct - local host, port = string.match(node_address[key], "([^:]+):(.*)$") + local address = node_address[key] + if address == nil then + local co = coroutine.running() + assert(ct.namequery == nil) + ct.namequery = co + skynet.error("Wating for cluster node [".. key.."]") + skynet.wait(co) + address = assert(node_address[key]) + end + local host, port = string.match(address, "([^:]+):(.*)$") local c = sc.channel { host = host, port = tonumber(port), @@ -67,6 +76,11 @@ local function loadconfig(tmp) end node_address[name] = address end + local ct = connecting[name] + if ct and ct.namequery then + skynet.error(string.format("Cluster node [%s] resloved : %s", name, address)) + skynet.wakeup(ct.namequery) + end end end