add cluster.reload(config)

This commit is contained in:
Cloud Wu
2017-03-13 17:24:39 +08:00
parent cb19ab54e9
commit 1cdc0d7558
4 changed files with 21 additions and 11 deletions

View File

@@ -3,6 +3,11 @@ local cluster = require "cluster"
local snax = require "snax"
skynet.start(function()
cluster.reload {
db = "127.0.0.1:2528",
db2 = "127.0.0.1:2529",
}
local sdb = skynet.newservice("simpledb")
-- register name "sdb" for simpledb, you can use cluster.query() later.
-- See cluster2.lua

View File

@@ -6,5 +6,6 @@ bootstrap = "snlua bootstrap" -- The service for bootstrap
luaservice = "./service/?.lua;./test/?.lua;./examples/?.lua"
lualoader = "lualib/loader.lua"
cpath = "./cservice/?.so"
cluster = "./examples/clustername.lua"
-- use cluster.reload instead, see cluster1.lua
-- cluster = "./examples/clustername.lua"
snax = "./test/?.lua"

View File

@@ -21,8 +21,8 @@ function cluster.open(port)
end
end
function cluster.reload()
skynet.call(clusterd, "lua", "reload")
function cluster.reload(config)
skynet.call(clusterd, "lua", "reload", config)
end
function cluster.proxy(node, name)

View File

@@ -29,12 +29,16 @@ end
local node_channel = setmetatable({}, { __index = open_channel })
local function loadconfig()
local f = assert(io.open(config_name))
local source = f:read "*a"
f:close()
local tmp = {}
assert(load(source, "@"..config_name, "t", tmp))()
local function loadconfig(tmp)
if tmp == nil then
tmp = {}
if config_name then
local f = assert(io.open(config_name))
local source = f:read "*a"
f:close()
assert(load(source, "@"..config_name, "t", tmp))()
end
end
for name,address in pairs(tmp) do
assert(type(address) == "string")
if node_address[name] ~= address then
@@ -47,8 +51,8 @@ local function loadconfig()
end
end
function command.reload()
loadconfig()
function command.reload(source, config)
loadconfig(config)
skynet.ret(skynet.pack(nil))
end