Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions apisix/core/config_etcd.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ local check_schema = require("apisix.core.schema").check
local exiting = ngx.worker.exiting
local worker_id = ngx.worker.id
local insert_tab = table.insert
local remove_tab = table.remove
local type = type
local ipairs = ipairs
local setmetatable = setmetatable
Expand Down Expand Up @@ -807,22 +808,23 @@ local function sync_data(self)

-- avoid space waste
if self.sync_times > 100 then
local values_original = table.clone(self.values)
table.clear(self.values)

for i = 1, #values_original do
local val = values_original[i]
local pre = 1
local cur = 1
table.clear(self.values_hash)
log.info("clear stale data in `values_hash` for key: ", key)
for _, val in ipairs(self.values) do
if val then
table.insert(self.values, val)
self.values[pre] = val
key = short_key(self, val.key)
self.values_hash[key] = pre
pre = pre + 1
end
end

table.clear(self.values_hash)
log.info("clear stale data in `values_hash` for key: ", key)
cur = cur + 1
end

for i = 1, #self.values do
key = short_key(self, self.values[i].key)
self.values_hash[key] = i
for i = cur - 1, pre, -1 do
remove_tab(self.values, i)
end

self.sync_times = 0
Expand Down
Loading