Skip to content

Commit

Permalink
clean the logic of load_into_cache
Browse files Browse the repository at this point in the history
  • Loading branch information
chronolaw authored and vm-001 committed Aug 29, 2023
1 parent 1f88607 commit a74b437
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

0 comments on commit a74b437

Please sign in to comment.