This is an automated email from the ASF dual-hosted git repository. guoqi pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/apisix.git
The following commit(s) were added to refs/heads/master by this push: new 47008afbf fix: resync etcd when a lower revision is found (#12015) 47008afbf is described below commit 47008afbf00f0612add2824d4694a379dfaae766 Author: Ashish Tiwari <ashishjaitiwari15112...@gmail.com> AuthorDate: Wed Mar 5 14:02:05 2025 +0530 fix: resync etcd when a lower revision is found (#12015) --- apisix/core/config_etcd.lua | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/apisix/core/config_etcd.lua b/apisix/core/config_etcd.lua index 76942adfe..1e5943e73 100644 --- a/apisix/core/config_etcd.lua +++ b/apisix/core/config_etcd.lua @@ -262,6 +262,14 @@ local function do_run_watch(premature) cancel_watch(http_cli) break end + + if rev < watch_ctx.rev then + log.error("received smaller revision, rev=", rev, ", watch_ctx.rev=", + watch_ctx.rev,". etcd may be restarted. resyncing....") + produce_res(nil, "restarted") + cancel_watch(http_cli) + break + end if rev > watch_ctx.rev then watch_ctx.rev = rev + 1 end @@ -569,6 +577,7 @@ local function load_full_data(self, dir_res, headers) end if headers then + self.prev_index = tonumber(headers["X-Etcd-Index"]) or 0 self:upgrade_version(headers["X-Etcd-Index"]) end @@ -633,7 +642,7 @@ local function sync_data(self) log.info("res: ", json.delay_encode(dir_res, true), ", err: ", err) if not dir_res then - if err == "compacted" then + if err == "compacted" or err == "restarted" then self.need_reload = true log.error("waitdir [", self.key, "] err: ", err, ", will read the configuration again via readdir")