Skip to content

Commit

Permalink
fix(etcd): handle etcd compaction
Browse files Browse the repository at this point in the history
  • Loading branch information
spacewander committed Nov 10, 2020
1 parent 3ba6629 commit 44a631e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions apisix/core/config_etcd.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 8 additions & 0 deletions apisix/core/etcd.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 44a631e

Please sign in to comment.