Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/1160 fix clustering #1437

Merged
merged 7 commits into from
Jul 27, 2016
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions kong/cmd/utils/serf_signals.lua
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ function _M.start(kong_config, dao)
return nil, "could not start Serf: "..err
end

-- cleanup current node from cluster to prevent inconsistency of data
local ok, err = serf:cleanup()
if not ok then return nil, err end

log.verbose("auto-joining Serf cluster...")
local ok, err = serf:autojoin()
if not ok then return nil, err end
Expand Down
8 changes: 5 additions & 3 deletions kong/serf.lua
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,14 @@ function Serf:reachability()
return self:invoke_signal("reachability")
end

function Serf:autojoin()
function Serf:cleanup()
-- Delete current node just in case it was there
-- (due to an inconsistency caused by a crash)
local _, err = self.dao.nodes:delete {name = self.node_name}
if err then return nil, tostring(err) end
local ok, err = self.dao.nodes:delete {name = self.node_name }
return ok, tostring(err)
end

function Serf:autojoin()
local nodes, err = self.dao.nodes:find_all()
if err then return nil, tostring(err)
elseif #nodes == 0 then
Expand Down