From 44a631eab991b985e2990c63571c4d49a6722b58 Mon Sep 17 00:00:00 2001 From: spacewander Date: Tue, 10 Nov 2020 14:55:00 +0800 Subject: [PATCH] fix(etcd): handle etcd compaction Close #2680. --- apisix/core/config_etcd.lua | 7 +++++++ apisix/core/etcd.lua | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/apisix/core/config_etcd.lua b/apisix/core/config_etcd.lua index 6a8094fea101e..e63c16bdd750f 100644 --- a/apisix/core/config_etcd.lua +++ b/apisix/core/config_etcd.lua @@ -290,6 +290,13 @@ local function sync_data(self) log.info("res: ", json.delay_encode(dir_res, true)) if not dir_res then + if err == "compacted" then + self.need_reload = true + log.warn("waitdir [", self.key, "] err: ", err, + ", need to fully reload") + return false + end + return false, err end diff --git a/apisix/core/etcd.lua b/apisix/core/etcd.lua index c28eb58f1630f..18a0394a2fa79 100644 --- a/apisix/core/etcd.lua +++ b/apisix/core/etcd.lua @@ -118,6 +118,14 @@ function _M.watch_format(v3res) v2res.body = { node = {} } + + local compact_revision = v3res.result.compact_revision + if compact_revision and tonumber(compact_revision) > 0 then + -- When the revisions are compacted, there might be compacted changes + -- which are unsynced. So we need to do a fully sync. + return nil, "compacted" + end + for i, event in ipairs(v3res.result.events) do v2res.body.node[i] = kvs_to_node(event.kv) if event.type == "DELETE" then