Skip to content

Commit

Permalink
addressed more comments from Wangchong
Browse files Browse the repository at this point in the history
  • Loading branch information
dndx committed Dec 24, 2021
1 parent cfbf8f6 commit 2516980
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
10 changes: 10 additions & 0 deletions kong/global.lua
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,11 @@ function _GLOBAL.init_cache(kong_config, cluster_events, worker_events)
local page = 1
local cache_pages = 1

if kong_config.database == "off" then
db_cache_ttl = 0
db_cache_neg_ttl = 0
end

return kong_cache.new {
shm_name = "kong_db_cache",
cluster_events = cluster_events,
Expand All @@ -224,6 +229,11 @@ function _GLOBAL.init_core_cache(kong_config, cluster_events, worker_events)
local page = 1
local cache_pages = 1

if kong_config.database == "off" then
db_cache_ttl = 0
db_cache_neg_ttl = 0
end

return kong_cache.new {
shm_name = "kong_core_db_cache",
cluster_events = cluster_events,
Expand Down
12 changes: 9 additions & 3 deletions kong/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,6 @@ end


local function load_declarative_config(kong_config, entities, meta)
print("load_declarative_config!!!")
local opts = {
name = "declarative_config",
}
Expand Down Expand Up @@ -521,7 +520,11 @@ function Kong.init()
end

if config.database == "off" then
if is_http_module or #config.proxy_listeners == 0 then
if is_http_module or
(#config.proxy_listeners == 0 and
#config.admin_listeners == 0 and
#config.status_listeners == 0)
then
local err
declarative_entities, err, declarative_meta = parse_declarative_config(kong.configuration)
if not declarative_entities then
Expand Down Expand Up @@ -630,11 +633,14 @@ function Kong.init_worker()
kong.db:set_events_handler(worker_events)

if kong.configuration.database == "off" then
-- databases in LMDB need to be explicitly created, otherwise `get`
-- operations will return error instead of `nil`. This ensures the default
-- namespace always exists in the
local t = lmdb_txn.begin(1)
t:db_open(true)
assert(t:commit())

if is_http_module or #kong.configuration.proxy_listeners == 0 then
if declarative_entities then
ok, err = load_declarative_config(kong.configuration,
declarative_entities,
declarative_meta)
Expand Down
8 changes: 4 additions & 4 deletions spec/02-integration/04-admin_api/15-off_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ local mocker = require("spec.fixtures.mocker")


local WORKER_SYNC_TIMEOUT = 10
local MEM_CACHE_SIZE = "10m"
local LMDB_MAP_SIZE = "10m"
local TEST_CONF = helpers.test_conf


Expand All @@ -28,7 +28,7 @@ describe("Admin API #off", function()
lazy_setup(function()
assert(helpers.start_kong({
database = "off",
lmdb_map_size = MEM_CACHE_SIZE,
lmdb_map_size = LMDB_MAP_SIZE,
stream_listen = "127.0.0.1:9011",
nginx_conf = "spec/fixtures/custom_nginx.template",
}))
Expand Down Expand Up @@ -858,7 +858,7 @@ describe("Admin API (concurrency tests) #off", function()
assert(helpers.start_kong({
database = "off",
nginx_worker_processes = 8,
lmdb_map_size = MEM_CACHE_SIZE,
lmdb_map_size = LMDB_MAP_SIZE,
}))

client = assert(helpers.admin_client())
Expand Down Expand Up @@ -981,7 +981,7 @@ describe("Admin API #off with Unique Foreign #unique", function()
database = "off",
plugins = "unique-foreign",
nginx_worker_processes = 1,
lmdb_map_size = MEM_CACHE_SIZE,
lmdb_map_size = LMDB_MAP_SIZE,
}))
end)

Expand Down

0 comments on commit 2516980

Please sign in to comment.