From 96b8ed44539f8e4fbc6c243ef2dec8b827782f10 Mon Sep 17 00:00:00 2001 From: chronolaw Date: Mon, 16 Dec 2024 10:30:58 +0800 Subject: [PATCH 1/2] refactor(clustering/sync): clean the logic of sync_once_impl() --- kong/clustering/services/sync/rpc.lua | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/kong/clustering/services/sync/rpc.lua b/kong/clustering/services/sync/rpc.lua index 4100afbb967..8c53899bdd0 100644 --- a/kong/clustering/services/sync/rpc.lua +++ b/kong/clustering/services/sync/rpc.lua @@ -422,26 +422,27 @@ 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 + 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 From 7526a1fc89d1c11763c897be1bad04bd6015208f Mon Sep 17 00:00:00 2001 From: chronolaw Date: Mon, 16 Dec 2024 10:45:51 +0800 Subject: [PATCH 2/2] debug log --- kong/clustering/services/sync/rpc.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/kong/clustering/services/sync/rpc.lua b/kong/clustering/services/sync/rpc.lua index 8c53899bdd0..006a8c4bb43 100644 --- a/kong/clustering/services/sync/rpc.lua +++ b/kong/clustering/services/sync/rpc.lua @@ -432,6 +432,7 @@ function sync_once_impl(premature, retry_count) 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