Skip to content

Commit

Permalink
style(db/declarative): simplify the logic of load_into_cache (#11384)
Browse files Browse the repository at this point in the history
  • Loading branch information
chronolaw authored Aug 30, 2023
1 parent 1f88607 commit e0d0a8a
Showing 1 changed file with 33 additions and 33 deletions.
66 changes: 33 additions & 33 deletions kong/db/declarative/import.lua
Original file line number Diff line number Diff line change
Expand Up @@ -453,47 +453,47 @@ do
local reconfigure_data

local ok, err, default_ws = load_into_cache(entities, meta, hash)
if ok then
local router_hash
local plugins_hash
local balancer_hash
if hashes then
if hashes.routes ~= DECLARATIVE_EMPTY_CONFIG_HASH then
router_hash = md5(hashes.services .. hashes.routes)
else
router_hash = DECLARATIVE_EMPTY_CONFIG_HASH
end

plugins_hash = hashes.plugins
if not ok then
if err:find("MDB_MAP_FULL", nil, true) then
return nil, "map full"
end

local upstreams_hash = hashes.upstreams
local targets_hash = hashes.targets
if upstreams_hash ~= DECLARATIVE_EMPTY_CONFIG_HASH or
targets_hash ~= DECLARATIVE_EMPTY_CONFIG_HASH
then
balancer_hash = md5(upstreams_hash .. targets_hash)
return nil, err
end

else
balancer_hash = DECLARATIVE_EMPTY_CONFIG_HASH
end
local router_hash
local plugins_hash
local balancer_hash
if hashes then
if hashes.routes ~= DECLARATIVE_EMPTY_CONFIG_HASH then
router_hash = md5(hashes.services .. hashes.routes)
else
router_hash = DECLARATIVE_EMPTY_CONFIG_HASH
end

reconfigure_data = {
default_ws,
router_hash,
plugins_hash,
balancer_hash,
}
plugins_hash = hashes.plugins

ok, err = events.declarative_reconfigure_notify(reconfigure_data)
if not ok then
return nil, err
local upstreams_hash = hashes.upstreams
local targets_hash = hashes.targets
if upstreams_hash ~= DECLARATIVE_EMPTY_CONFIG_HASH or
targets_hash ~= DECLARATIVE_EMPTY_CONFIG_HASH
then
balancer_hash = md5(upstreams_hash .. targets_hash)

else
balancer_hash = DECLARATIVE_EMPTY_CONFIG_HASH
end
end

elseif err:find("MDB_MAP_FULL", nil, true) then
return nil, "map full"
reconfigure_data = {
default_ws,
router_hash,
plugins_hash,
balancer_hash,
}

else
ok, err = events.declarative_reconfigure_notify(reconfigure_data)
if not ok then
return nil, err
end

Expand Down

1 comment on commit e0d0a8a

@khcp-gha-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bazel Build

Docker image available kong/kong:e0d0a8ad8aa3b26fe5a7b803873e2d6d578d938c
Artifacts available https://github.com/Kong/kong/actions/runs/6021692829

Please sign in to comment.