Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: increase the delay before resync #2977

Merged
merged 3 commits into from
Dec 7, 2020
Merged
Show file tree
Hide file tree
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
12 changes: 10 additions & 2 deletions apisix/core/config_etcd.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ local tonumber = tonumber
local xpcall = xpcall
local debug = debug
local error = error
local rand = math.random
local created_obj = {}


Expand Down Expand Up @@ -518,8 +519,10 @@ local function _automatic_fetch(premature, self)
self.last_err = nil
end
end
ngx_sleep(0.5)

ngx_sleep(self.resync_delay + rand() * 0.5 * self.resync_delay)
elseif not ok then
-- no error. reentry the sync with different state
ngx_sleep(0.05)
end

Expand All @@ -528,7 +531,7 @@ local function _automatic_fetch(premature, self)
if not ok then
log.error("failed to fetch data from etcd: ", err, ", ",
tostring(self))
ngx_sleep(3)
ngx_sleep(self.resync_delay + rand() * 0.5 * self.resync_delay)
break
end
end
Expand Down Expand Up @@ -559,6 +562,10 @@ function _M.new(key, opts)
etcd_conf.ssl_verify = false
end

if not etcd_conf.resync_delay or etcd_conf.resync_delay < 0 then
etcd_conf.resync_delay = 5
end

local automatic = opts and opts.automatic
local item_schema = opts and opts.item_schema
local filter_fun = opts and opts.filter
Expand All @@ -582,6 +589,7 @@ function _M.new(key, opts)
prev_index = 0,
last_err = nil,
last_err_time = nil,
resync_delay = etcd_conf.resync_delay,
timeout = timeout,
single_item = single_item,
filter = filter_fun,
Expand Down
1 change: 1 addition & 0 deletions conf/config-default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ etcd:
# e.g. "https://127.0.0.1:2379".
prefix: "/apisix" # apisix configurations prefix
timeout: 30 # 30 seconds
# resync_delay: 5 # when sync failed and a rest is needed, resync after the configured seconds plus 50% random jitter
# user: root # root username for etcd
# password: 5tHkHhYkjr6cQY # root password for etcd
tls:
Expand Down
5 changes: 5 additions & 0 deletions t/core/etcd-sync.t
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ run_tests;
__DATA__

=== TEST 1: minus timeout to watch repeatedly
--- extra_yaml_config
etcd:
host:
- "http://127.0.0.1:2379"
resync_delay: 0.5 # resync after timeout
--- config
location /t {
content_by_lua_block {
Expand Down