Skip to content

Commit

Permalink
fix(dao): page size 1 does not work for lmdb
Browse files Browse the repository at this point in the history
  • Loading branch information
StarlightIbuki committed Nov 22, 2024
1 parent 251665a commit e31169e
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 5 deletions.
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
4 changes: 0 additions & 4 deletions kong/db/strategies/off/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,6 @@ local function page_for_prefix(self, prefix, size, offset, options, follow)
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
39 changes: 39 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,42 @@ describe("Admin API: #" .. strategy, function()
end)

end

for _, strategy in helpers.all_strategy() do
describe("#regression", function()
lazy_setup(function()
bp, db = helpers.get_db_utils(strategy, {})

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)
end)
end)
end

0 comments on commit e31169e

Please sign in to comment.