Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 9 additions & 23 deletions src/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,11 @@ function connmethods:ismaster()
if not r then
return nil, err
end
return r.ismaster, r.hosts
return r.ismaster, r.primary
end

function connmethods:getprimary(searched)

if not searched then
searched = {
[self.host .. ":" .. self.port] = true
}
end
-- searched is not nessary for now

local db = self:new_db_handle("admin")

Expand All @@ -39,25 +34,16 @@ function connmethods:getprimary(searched)

else

for i, v in ipairs ( r.hosts ) do

if not searched[v] then
local host, port = parse_host(r.primary)
local conn = new()

searched[v] = true
local host, port = parse_host(v)
local conn = new()
local ok, err = conn:connect(host, port)
if not ok then
return nil, "connect failed: "..err
end

local ok, err = conn:connect(host, port)
if not ok then
return nil, "connect failed: "..err..v
end
return conn

local found = conn:getprimary(searched)
if found then
return found
end
end
end
end

return nil , "No master server found"
Expand Down