mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-24 20:23:06 +00:00
Merge pull request #525 from zxfishhack/master
auto determine primary host
This commit is contained in:
@@ -105,12 +105,38 @@ local function mongo_auth(mongoc)
|
|||||||
mongoc.__sock:changebackup(backup)
|
mongoc.__sock:changebackup(backup)
|
||||||
end
|
end
|
||||||
if rs_data.ismaster then
|
if rs_data.ismaster then
|
||||||
|
if rawget(mongoc, "__pickserver") then
|
||||||
|
rawset(mongoc, "__pickserver", nil)
|
||||||
|
end
|
||||||
return
|
return
|
||||||
else
|
else
|
||||||
local host, port = __parse_addr(rs_data.primary)
|
if rs_data.primary then
|
||||||
mongoc.host = host
|
local host, port = __parse_addr(rs_data.primary)
|
||||||
mongoc.port = port
|
mongoc.host = host
|
||||||
mongoc.__sock:changehost(host, port)
|
mongoc.port = port
|
||||||
|
mongoc.__sock:changehost(host, port)
|
||||||
|
else
|
||||||
|
skynet.error("WARNING: NO PRIMARY RETURN " .. rs_data.me)
|
||||||
|
-- determine the primary db using hosts
|
||||||
|
local pickserver = {}
|
||||||
|
if rawget(mongoc, "__pickserver") == nil then
|
||||||
|
for _, v in ipairs(rs_data.hosts) do
|
||||||
|
if v ~= rs_data.me then
|
||||||
|
table.insert(pickserver, v)
|
||||||
|
end
|
||||||
|
rawset(mongoc, "__pickserver", pickserver)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if #mongoc.__pickserver <= 0 then
|
||||||
|
error("CAN NOT DETERMINE THE PRIMARY DB")
|
||||||
|
end
|
||||||
|
skynet.error("INFO: TRY TO CONNECT " .. mongoc.__pickserver[1])
|
||||||
|
local host, port = __parse_addr(mongoc.__pickserver[1])
|
||||||
|
table.remove(mongoc.__pickserver, 1)
|
||||||
|
mongoc.host = host
|
||||||
|
mongoc.port = port
|
||||||
|
mongoc.__sock:changehost(host, port)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user