Skip to content

Commit

Permalink
refactor(clustering/sync): clean the logic of sync_once_impl() (#14024)
Browse files Browse the repository at this point in the history
  • Loading branch information
chronolaw authored Dec 16, 2024
1 parent f10cd09 commit eeded78
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions kong/clustering/services/sync/rpc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -422,26 +422,28 @@ function sync_once_impl(premature, retry_count)
return
end

sync_handler()

local latest_notified_version = ngx.shared.kong:get(CLUSTERING_DATA_PLANES_LATEST_VERSION_KEY)
local current_version = tonumber(declarative.get_current_hash()) or 0
sync_handler()

local latest_notified_version = ngx.shared.kong:get(CLUSTERING_DATA_PLANES_LATEST_VERSION_KEY)
if not latest_notified_version then
ngx_log(ngx_DEBUG, "no version notified yet")
return
end

-- retry if the version is not updated
if current_version < latest_notified_version then
retry_count = retry_count or 0
if retry_count > MAX_RETRY then
ngx_log(ngx_ERR, "sync_once retry count exceeded. retry_count: ", retry_count)
return
end
local current_version = tonumber(declarative.get_current_hash()) or 0
if current_version >= latest_notified_version then
ngx_log(ngx_DEBUG, "version already updated")
return
end

return start_sync_once_timer(retry_count + 1)
-- retry if the version is not updated
retry_count = retry_count or 0
if retry_count > MAX_RETRY then
ngx_log(ngx_ERR, "sync_once retry count exceeded. retry_count: ", retry_count)
return
end

return start_sync_once_timer(retry_count + 1)
end


Expand Down

1 comment on commit eeded78

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bazel Build

Docker image available kong/kong:eeded7874b46099b8ea19ca0e768c857a09068d7
Artifacts available https://github.com/Kong/kong/actions/runs/12358971927

Please sign in to comment.