Skip to content
Closed
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
19 changes: 12 additions & 7 deletions apisix/core/config_etcd.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
-- See the License for the specific language governing permissions and
-- limitations under the License.
--

local table = require("apisix.core.table")
local config_local = require("apisix.core.config_local")
local log = require("apisix.core.log")
local json = require("apisix.core.json")
Expand Down Expand Up @@ -318,6 +320,7 @@ local function sync_data(self)
else
self.sync_times = self.sync_times + 1
self.values[pre_index] = false
self.values_hash[key] = nil
end

elseif res.value then
Expand All @@ -330,20 +333,22 @@ local function sync_data(self)
-- avoid space waste
-- todo: need to cover this path, it is important.
if self.sync_times > 100 then
local count = 0
for i = 1, #self.values do
local val = self.values[i]
self.values[i] = nil
local values_org = table.clone(self.values)
table.clear(self.values)

for i = 1, #values_org do
local val = values_org[i]
if val then
count = count + 1
self.values[count] = val
table.insert(self.values, val)
end
end

for i = 1, count do
table.clear(self.values_hash)
for i = 1, #self.values do
key = short_key(self, self.values[i].key)
self.values_hash[key] = i
end

self.sync_times = 0
end

Expand Down