Skip to content

Commit

Permalink
fix(sync): notify declarative:reconfigure events for full sync (#13860)
Browse files Browse the repository at this point in the history
With full sync (`wipe = true` in `do_sync()`), if we dont notify other workers with `declarative:reconfigure`, the registered callbacks in other workers will not be called, like updating `kong.default_workerspace`.

Note that when an empty-configured CP and DP start with incremental sync enabled, the DP will rebuild routers, plugins, and the balancer twice. This occurs because the DP currently calls do_sync() twice during a single sync operation. With incremental sync disabled, it rebuilds these components only once.

https://konghq.atlassian.net/browse/KAG-5812
(cherry picked from commit 945d333)
  • Loading branch information
chobits authored and bungle committed Nov 18, 2024
1 parent 94ea5c8 commit 90e648d
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions kong/clustering/services/sync/rpc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ local declarative = require("kong.db.declarative")
local constants = require("kong.constants")
local concurrency = require("kong.concurrency")
local isempty = require("table.isempty")
local events = require("kong.runloop.events")


local insert_entity_for_txn = declarative.insert_entity_for_txn
Expand Down Expand Up @@ -341,6 +342,16 @@ local function do_sync()
kong.core_cache:purge()
kong.cache:purge()

-- Trigger other workers' callbacks like reconfigure_handler.
--
-- Full sync could rebuild route, plugins and balancer route, so their
-- hashes are nil.
local reconfigure_data = { kong.default_workspace, nil, nil, nil, }
local ok, err = events.declarative_reconfigure_notify(reconfigure_data)
if not ok then
return nil, err
end

else
for _, event in ipairs(crud_events) do
-- delta_type, crud_event_type, delta.entity, old_entity
Expand Down

0 comments on commit 90e648d

Please sign in to comment.