Skip to content

Commit 47008af

Browse files
authored
fix: resync etcd when a lower revision is found (#12015)
1 parent 381595e commit 47008af

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

apisix/core/config_etcd.lua

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,14 @@ local function do_run_watch(premature)
262262
cancel_watch(http_cli)
263263
break
264264
end
265+
266+
if rev < watch_ctx.rev then
267+
log.error("received smaller revision, rev=", rev, ", watch_ctx.rev=",
268+
watch_ctx.rev,". etcd may be restarted. resyncing....")
269+
produce_res(nil, "restarted")
270+
cancel_watch(http_cli)
271+
break
272+
end
265273
if rev > watch_ctx.rev then
266274
watch_ctx.rev = rev + 1
267275
end
@@ -569,6 +577,7 @@ local function load_full_data(self, dir_res, headers)
569577
end
570578

571579
if headers then
580+
self.prev_index = tonumber(headers["X-Etcd-Index"]) or 0
572581
self:upgrade_version(headers["X-Etcd-Index"])
573582
end
574583

@@ -633,7 +642,7 @@ local function sync_data(self)
633642
log.info("res: ", json.delay_encode(dir_res, true), ", err: ", err)
634643

635644
if not dir_res then
636-
if err == "compacted" then
645+
if err == "compacted" or err == "restarted" then
637646
self.need_reload = true
638647
log.error("waitdir [", self.key, "] err: ", err,
639648
", will read the configuration again via readdir")

0 commit comments

Comments
 (0)