Skip to content

Commit

Permalink
feat(dbless) use LMDB as DB-less backend
Browse files Browse the repository at this point in the history
This PR adds LMDB (Lightning Memory-Mapped Database) support for
DB-less. At the same time, the shdict based DB-less storage backend has
been retired and removed from the codebase.

LMDB has better concurrency characters and is generally much more stable
than shdict for storing config data. Because it can be natively accessed
from different processes, we also removed the hack that sends the full
DB-less config to the stream subsystem, which should improve the
stability of DB-less reload at runtime as well.

New config options `lmdb_environment_path` and `lmdb_map_size` has been
added.

Co-authored-by: Suika <xumin.zhou@konghq.com>
  • Loading branch information
dndx and StarlightIbuki authored Mar 31, 2022
1 parent 0ab534d commit 5b7676c
Show file tree
Hide file tree
Showing 21 changed files with 357 additions and 320 deletions.
2 changes: 2 additions & 0 deletions .ci/setup_env_github.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ OPENRESTY=$(dep_version RESTY_VERSION)
LUAROCKS=$(dep_version RESTY_LUAROCKS_VERSION)
OPENSSL=$(dep_version RESTY_OPENSSL_VERSION)
PCRE=$(dep_version RESTY_PCRE_VERSION)
RESTY_LMDB=$(dep_version RESTY_LMDB_VERSION)


#---------
Expand All @@ -32,6 +33,7 @@ kong-ngx-build \
--kong-nginx-module $KONG_NGINX_MODULE_BRANCH \
--luarocks $LUAROCKS \
--openssl $OPENSSL \
--resty-lmdb $RESTY_LMDB \
--pcre $PCRE \
--debug

Expand Down
1 change: 1 addition & 0 deletions .requirements
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ RESTY_VERSION=1.19.9.1
RESTY_LUAROCKS_VERSION=3.8.0
RESTY_OPENSSL_VERSION=1.1.1n
RESTY_PCRE_VERSION=8.45
RESTY_LMDB_VERSION=master
LIBYAML_VERSION=0.2.5
KONG_BUILD_TOOLS_VERSION=4.25.3
KONG_NGINX_MODULE_BRANCH=0.2.1
1 change: 1 addition & 0 deletions kong-2.8.0-0.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ build = {
["kong.db.dao.vaults"] = "kong/db/dao/vaults.lua",
["kong.db.dao.workspaces"] = "kong/db/dao/workspaces.lua",
["kong.db.declarative"] = "kong/db/declarative/init.lua",
["kong.db.declarative.marshaller"] = "kong/db/declarative/marshaller.lua",
["kong.db.schema"] = "kong/db/schema/init.lua",
["kong.db.schema.entities.consumers"] = "kong/db/schema/entities/consumers.lua",
["kong.db.schema.entities.routes"] = "kong/db/schema/entities/routes.lua",
Expand Down
7 changes: 4 additions & 3 deletions kong/api/routes/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,11 @@ return {
})
end

if err == "no memory" then
kong.log.err("not enough cache space for declarative config")
if err == "map full" then
kong.log.err("not enough space for declarative config")
return kong.response.exit(413, {
message = "Configuration does not fit in Kong cache"
message = "Configuration does not fit in LMDB database, " ..
"consider raising the \"lmdb_map_size\" config for Kong"
})
end

Expand Down
3 changes: 3 additions & 0 deletions kong/conf_loader/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,9 @@ local CONF_INFERENCES = {
untrusted_lua = { enum = { "on", "off", "sandbox" } },
untrusted_lua_sandbox_requires = { typ = "array" },
untrusted_lua_sandbox_environment = { typ = "array" },

lmdb_environment_path = { typ = "string" },
lmdb_map_size = { typ = "string" },
}


Expand Down
1 change: 0 additions & 1 deletion kong/constants.lua
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ local constants = {
PROTOCOLS = protocols,
PROTOCOLS_WITH_SUBSYSTEM = protocols_with_subsystem,

DECLARATIVE_PAGE_KEY = "declarative:page",
DECLARATIVE_LOAD_KEY = "declarative_config:loaded",
DECLARATIVE_HASH_KEY = "declarative_config:hash",
DECLARATIVE_EMPTY_CONFIG_HASH = string.rep("0", 32),
Expand Down
Loading

0 comments on commit 5b7676c

Please sign in to comment.