Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(dao): page size 1 does not work for lmdb #13908

Merged
merged 1 commit into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .requirements
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ LIBEXPAT_SHA256=d4cf38d26e21a56654ffe4acd9cd5481164619626802328506a2869afab29ab3
# Note: git repositories can be loaded from local path if path is set as value

LUA_KONG_NGINX_MODULE=3eb89666f84348fa0599d4e0a29ccf89511e8b75 # 0.13.0
LUA_RESTY_LMDB=890b3caf45bd052e319e48349ef393ec93e08ac4 # 1.5.0
LUA_RESTY_LMDB=9da0e9f3313960d06e2d8e718b7ac494faa500f1 # 1.6.0
LUA_RESTY_EVENTS=bc85295b7c23eda2dbf2b4acec35c93f77b26787 # 0.3.1
LUA_RESTY_SIMDJSON=7e6466ce91b2bc763b45701a4f055e94b1e8143b # 1.1.0
LUA_RESTY_WEBSOCKET=966c69c39f03029b9b42ec0f8e55aaed7d6eebc0 # 0.4.0.1
Expand Down
3 changes: 3 additions & 0 deletions changelog/unreleased/kong/bump-lua-resty-lmdb-2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
message: Bumped lua-resty-lmdb to 1.6.0. Allowing page_size to be 1.
type: dependency
scope: Core
7 changes: 0 additions & 7 deletions kong/db/strategies/off/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,11 @@ local function select_by_key(schema, key, follow)
end


local LMDB_MIN_PAGE_SIZE = 2


local function page_for_prefix(self, prefix, size, offset, options, follow)
if not size then
size = self.connector:get_page_size(options)
end

-- LMDB 'page_size' can not be less than 2
-- see: https://github.com/Kong/lua-resty-lmdb?tab=readme-ov-file#page
size = math.max(size, LMDB_MIN_PAGE_SIZE)

offset = offset or prefix

local res, err_or_more = lmdb_prefix.page(offset, prefix, nil, size)
Expand Down
61 changes: 61 additions & 0 deletions spec/02-integration/04-admin_api/07-upstreams_routes_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -835,3 +835,64 @@ describe("Admin API: #" .. strategy, function()
end)

end

for _, strategy in helpers.all_strategies() do
describe("#regression #" .. strategy, function()
local client
lazy_setup(function()
local bp, _ = helpers.get_db_utils(strategy)
bp.upstreams:insert {
name = "my-upstream",
slots = 100,
}
bp.upstreams:insert {
name = "my-upstream-2",
slots = 100,
}
bp.upstreams:insert {
name = "my-upstream-3",
slots = 100,
}

assert(helpers.start_kong{
database = strategy
})
client = assert(helpers.admin_client())
end)

lazy_teardown(function()
if client then client:close() end
helpers.stop_kong()
end)

it("page size 1", function()
local res = assert(client:send {
method = "GET",
path = "/upstreams?size=1"
})
assert.response(res).has.status(200)
local json = assert.response(res).has.jsonbody()
assert.equal(1, #json.data)
assert.truthy(json.offset)

res = assert(client:send {
method = "GET",
path = "/upstreams",
query = {size = 1, offset = json.offset}
})
assert.response(res).has.status(200)
local json = assert.response(res).has.jsonbody()
assert.equal(1, #json.data)
assert.truthy(json.offset)

res = assert(client:send {
method = "GET",
path = "/upstreams?size=2"
})
assert.response(res).has.status(200)
local json = assert.response(res).has.jsonbody()
assert.equal(2, #json.data)
assert.truthy(json.offset)
end)
end)
end
Loading