This is an automated email from the ASF dual-hosted git repository.

membphis 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 f265501  fix(etcd): handle etcd compaction (#2687)
f265501 is described below

commit f2655013b16d37c8f6086f517351aeba401072a6
Author: 罗泽轩 <[email protected]>
AuthorDate: Sun Nov 15 19:38:29 2020 +0800

    fix(etcd): handle etcd compaction (#2687)
    
    Close #2680
---
 apisix/core/config_etcd.lua | 7 +++++++
 apisix/core/etcd.lua        | 9 +++++++++
 2 files changed, 16 insertions(+)

diff --git a/apisix/core/config_etcd.lua b/apisix/core/config_etcd.lua
index 6a8094f..e63c16b 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 c28eb58..310bdb6 100644
--- a/apisix/core/etcd.lua
+++ b/apisix/core/etcd.lua
@@ -118,6 +118,15 @@ 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.
+        -- TODO: cover this branch in CI
+        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

Reply via email to