Skip to content

Commit

Permalink
check get_latest_version()
Browse files Browse the repository at this point in the history
  • Loading branch information
chronolaw committed Oct 11, 2024
1 parent ccf122a commit 2838ffd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
7 changes: 6 additions & 1 deletion kong/clustering/services/sync/hooks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ end


function _M:notify_all_nodes()
local latest_version = self.strategy:get_latest_version()
local latest_version, err = self.strategy:get_latest_version()
if not latest_version then
ngx_log(ngx_ERR, "can not get the latest version: ", err)
return
end

local msg = { default = { new_version = latest_version, }, }

for _, node in ipairs(get_all_nodes_with_sync_cap()) do
Expand Down
7 changes: 6 additions & 1 deletion kong/clustering/services/sync/rpc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,14 @@ function _M:init_cp(manager)
ngx_log(ngx_ERR, "unable to update clustering data plane status: ", err)
end

local latest_version, err = self.strategy:get_latest_version()
if not latest_version then
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
self.strategy:get_latest_version() - default_namespace_version > FULL_SYNC_THRESHOLD
latest_version - default_namespace_version > FULL_SYNC_THRESHOLD
then
-- we need to full sync because holes are found

Expand Down
8 changes: 7 additions & 1 deletion kong/clustering/services/sync/strategies/postgres.lua
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,13 @@ end

function _M:get_latest_version()
local sql = "SELECT MAX(version) AS max_version FROM clustering_sync_version"
return self.connector:query(sql)[1].max_version

local res, err = self.connector:query(sql)
if not res then
return nil, err
end

return res[1].max_version
end


Expand Down

0 comments on commit 2838ffd

Please sign in to comment.