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

perf(router): load service with route.ws_id while building routers #14057

Merged
merged 1 commit into from
Dec 30, 2024
Merged
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
12 changes: 7 additions & 5 deletions kong/runloop/handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,9 @@ local function should_process_route(route)
end


local function load_service_from_db(service_pk)
local service, err = kong.db.services:select(service_pk, GLOBAL_QUERY_OPTS)
local function load_service_from_db(service_pk, ws_id)
local options = ws_id and { workspace = ws_id, show_ws_id = true }
local service, err = kong.db.services:select(service_pk, options)
if service == nil then
-- the third value means "do not cache"
return nil, err, -1
Expand Down Expand Up @@ -299,20 +300,21 @@ local function get_service_for_route(db, route, services_init_cache)
end

local err
local ws_id = route.ws_id

-- kong.core_cache is available, not in init phase
if kong.core_cache and db.strategy ~= "off" then
local cache_key = db.services:cache_key(service_pk.id, nil, nil, nil, nil,
route.ws_id)
ws_id)
service, err = kong.core_cache:get(cache_key, TTL_ZERO,
load_service_from_db, service_pk)
load_service_from_db, service_pk, ws_id)

else -- dbless or init phase, kong.core_cache not needed/available

-- A new service/route has been inserted while the initial route
-- was being created, on init (perhaps by a different Kong node).
-- Load the service individually and update services_init_cache with it
service, err = load_service_from_db(service_pk)
service, err = load_service_from_db(service_pk, ws_id)
services_init_cache[id] = service
end

Expand Down
Loading