fix(etcd): handle etcd compaction (#2687)

Close #2680
This commit is contained in:
罗泽轩 2020-11-15 19:38:29 +08:00 committed by GitHub
parent 0654687aed
commit f2655013b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 0 deletions

View File

@ -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

View File

@ -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