Skip to content

Commit

Permalink
rpc sync v2
Browse files Browse the repository at this point in the history
  • Loading branch information
chronolaw committed Dec 17, 2024
1 parent eeded78 commit 195311b
Showing 1 changed file with 4 additions and 41 deletions.
45 changes: 4 additions & 41 deletions kong/clustering/services/sync/rpc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ function _M.new(strategy)
end


local function inc_sync_result(res)
return { default = { deltas = res, wipe = false, }, }
local function empty_sync_result()
return { default = { deltas = {}, wipe = false, }, }
end


Expand Down Expand Up @@ -107,47 +107,10 @@ function _M:init_cp(manager)
return nil, err
end

-- is the node empty? If so, just do a full sync to bring it up to date faster
if default_namespace_version == 0 or
latest_version - default_namespace_version > FULL_SYNC_THRESHOLD
then
-- we need to full sync because holes are found

ngx_log(ngx_INFO,
"[kong.sync.v2] database is empty or too far behind for node_id: ", node_id,
", current_version: ", default_namespace_version,
", forcing a full sync")

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
if default_namespace_version == latest_version then
return empty_sync_result()
end

if isempty(res) then
-- node is already up to date
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 inc_sync_result(res)
end

-- we need to full sync because holes are found
-- in the delta, meaning the oldest version is no longer
-- available

ngx_log(ngx_INFO,
"[kong.sync.v2] delta for node_id no longer available: ", node_id,
", current_version: ", default_namespace_version,
", forcing a full sync")

return full_sync_result()
end)
end
Expand Down

0 comments on commit 195311b

Please sign in to comment.