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(cluster) quiet keepalive events #1660

Merged
merged 2 commits into from
Sep 20, 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
7 changes: 5 additions & 2 deletions kong/core/cluster.lua
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ local function send_keepalive(premature)
ngx_log(ngx.ERR, tostring(err))
elseif #nodes == 1 then
local node = nodes[1]
local _, err = singletons.dao.nodes:update(node, node, {ttl=singletons.configuration.cluster_ttl_on_failure})
local _, err = singletons.dao.nodes:update(node, node, {
ttl = singletons.configuration.cluster_ttl_on_failure,
quiet = true
})
if err then
ngx_log(ngx.ERR, tostring(err))
end
Expand All @@ -97,4 +100,4 @@ return {
create_timer(KEEPALIVE_INTERVAL, send_keepalive)
create_timer(ASYNC_AUTOJOIN_INTERVAL, async_autojoin) -- Only execute one time
end
}
}
23 changes: 15 additions & 8 deletions kong/dao/dao.lua
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,13 @@ end
--- Insert a row.
-- Insert a given Lua table as a row in the related table.
-- @param[type=table] tbl Table to insert as a row.
-- @param[type=table] options Options to use for this insertion. (`ttl`: Time-to-live for this row, in seconds)
-- @param[type=table] options Options to use for this insertion. (`ttl`: Time-to-live for this row, in seconds, `quiet`: does not send event)
-- @treturn table res A table representing the insert row (with fields created during the insertion).
-- @treturn table err If an error occured, a table describing the issue.
function DAO:insert(tbl, options)
options = options or {}
check_arg(tbl, 1, "table")
check_arg(options, 2, "table")

local model = self.model_mt(tbl)
local ok, err = model:validate {dao = self}
Expand All @@ -124,7 +126,7 @@ function DAO:insert(tbl, options)
end

local res, err = self.db:insert(self.table, self.schema, model, self.constraints, options)
if not err then
if not err and not options.quiet then
event(self, event_types.ENTITY_CREATED, self.table, self.schema, res)
end
return ret_error(self.db.db_type, res, err)
Expand Down Expand Up @@ -249,15 +251,16 @@ end
-- with the one specified in `tbl` at once.
-- @param[type=table] tbl A table containing the new values for this row.
-- @param[type=table] filter_keys A table which must contain the primary key(s) to select the row to be updated.
-- @param[type=table] options Options to use for this update. (`full`: performs a full update of the entity).
-- @param[type=table] options Options to use for this update. (`full`: performs a full update of the entity, `quiet`: does not send event).
-- @treturn table res A table representing the updated entity.
-- @treturn table err If an error occured, a table describing the issue.
function DAO:update(tbl, filter_keys, options)
options = options or {}
check_arg(tbl, 1, "table")
check_not_empty(tbl, 1)
check_arg(filter_keys, 2, "table")
check_not_empty(filter_keys, 2)
options = options or {}
check_arg(options, 3, "table")

for k, v in pairs(filter_keys) do
if tbl[k] == nil then
Expand Down Expand Up @@ -291,7 +294,9 @@ function DAO:update(tbl, filter_keys, options)
if err then
return ret_error(self.db.db_type, nil, err)
elseif res then
event(self, event_types.ENTITY_UPDATED, self.table, self.schema, old)
if not options.quiet then
event(self, event_types.ENTITY_UPDATED, self.table, self.schema, old)
end
return setmetatable(res, nil)
end
end
Expand All @@ -304,8 +309,10 @@ end
-- @param[type=table] tbl A table containing the primary key field(s) for this row.
-- @treturn table row A table representing the deleted row
-- @treturn table err If an error occured, a table describing the issue.
function DAO:delete(tbl)
function DAO:delete(tbl, options)
options = options or {}
check_arg(tbl, 1, "table")
check_arg(options, 2, "table")

local model = self.model_mt(tbl)
if not model:has_primary_keys() then
Expand Down Expand Up @@ -334,7 +341,7 @@ function DAO:delete(tbl)
end

local row, err = self.db:delete(self.table, self.schema, primary_keys, self.constraints)
if not err and row ~= nil then
if not err and row ~= nil and not options.quiet then
event(self, event_types.ENTITY_DELETED, self.table, self.schema, row)

-- Also propagate the deletion for the associated entities
Expand All @@ -351,4 +358,4 @@ function DAO:truncate()
return ret_error(self.db.db_type, self.db:truncate_table(self.table))
end

return DAO
return DAO