From 9ad5262fed16e9ab1a7e7c00023af9b3f325e7b2 Mon Sep 17 00:00:00 2001 From: chronolaw Date: Sun, 3 Nov 2024 13:33:22 +0800 Subject: [PATCH] inc_sync_result --- kong/clustering/services/sync/rpc.lua | 32 +++++++++++++++------------ 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/kong/clustering/services/sync/rpc.lua b/kong/clustering/services/sync/rpc.lua index 71653b402100..e29b899ef332 100644 --- a/kong/clustering/services/sync/rpc.lua +++ b/kong/clustering/services/sync/rpc.lua @@ -39,22 +39,24 @@ function _M.new(strategy) end -function _M:init_cp(manager) - local purge_delay = manager.conf.cluster_data_plane_purge_delay +local function inc_sync_result(res) + return { default = { deltas = res, wipe = false, }, } +end + - local function gen_delta_result(res, wipe) - return { default = { deltas = res, wipe = wipe, }, } +local function full_sync_result() + local deltas, err = declarative.export_config_sync() + if not deltas then + return nil, err end - local function full_sync_result() - local deltas, err = declarative.export_config_sync() - if not deltas then - return nil, err - end + -- wipe dp lmdb, full sync + return { default = { deltas = deltas, wipe = true, }, } +end - -- wipe dp lmdb, full sync - return gen_delta_result(deltas, true) - end + +function _M:init_cp(manager) + local purge_delay = manager.conf.cluster_data_plane_purge_delay -- CP -- Method: kong.sync.v2.get_delta @@ -110,6 +112,8 @@ function _M:init_cp(manager) return full_sync_result() end + -- do we need an incremental sync? + local res, err = self.strategy:get_delta(default_namespace_version) if not res then return nil, err @@ -120,13 +124,13 @@ function _M:init_cp(manager) "[kong.sync.v2] no delta for node_id: ", node_id, ", current_version: ", default_namespace_version, ", node is already up to date" ) - return gen_delta_result(res, false) + return inc_sync_result(res) end -- some deltas are returned, are they contiguous? if res[1].version == default_namespace_version + 1 then -- doesn't wipe dp lmdb, incremental sync - return gen_delta_result(res, false) + return inc_sync_result(res) end -- we need to full sync because holes are found