diff --git a/kong/global.lua b/kong/global.lua index be778b3f8906..aa0d8174e481 100644 --- a/kong/global.lua +++ b/kong/global.lua @@ -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, @@ -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, diff --git a/kong/init.lua b/kong/init.lua index aa57ccefd9b9..1dd06580f877 100644 --- a/kong/init.lua +++ b/kong/init.lua @@ -394,7 +394,6 @@ end local function load_declarative_config(kong_config, entities, meta) - print("load_declarative_config!!!") local opts = { name = "declarative_config", } @@ -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 @@ -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) diff --git a/spec/02-integration/04-admin_api/15-off_spec.lua b/spec/02-integration/04-admin_api/15-off_spec.lua index dc79e82292e5..6837dde500a1 100644 --- a/spec/02-integration/04-admin_api/15-off_spec.lua +++ b/spec/02-integration/04-admin_api/15-off_spec.lua @@ -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 @@ -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", })) @@ -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()) @@ -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)