From a74b437fdbc3c994d90d0887db96f77ccea5fa32 Mon Sep 17 00:00:00 2001 From: chronolaw Date: Thu, 10 Aug 2023 14:21:41 +0800 Subject: [PATCH] clean the logic of load_into_cache --- kong/db/declarative/import.lua | 66 +++++++++++++++++----------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/kong/db/declarative/import.lua b/kong/db/declarative/import.lua index 5b23317f32f8..2ede32c984fd 100644 --- a/kong/db/declarative/import.lua +++ b/kong/db/declarative/import.lua @@ -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