Skip to content

Commit

Permalink
fix(dao): page size 1 now works correctly for DB-less (#13908)
Browse files Browse the repository at this point in the history
  • Loading branch information
StarlightIbuki authored Nov 22, 2024
1 parent 251665a commit c924a23
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 8 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
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

1 comment on commit c924a23

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bazel Build

Docker image available kong/kong:c924a236da35b26ab4401b9c700d46fea95972da
Artifacts available https://github.com/Kong/kong/actions/runs/11967938187

Please sign in to comment.