@@ -108,7 +108,8 @@ local function create_checker(upstream)
108
108
end
109
109
110
110
local healthcheck_parent = upstream .parent
111
- if healthcheck_parent .checker and healthcheck_parent .checker_upstream == upstream then
111
+ if healthcheck_parent .checker and healthcheck_parent .checker_upstream == upstream
112
+ and healthcheck_parent .checker_nodes_ver == upstream ._nodes_ver then
112
113
return healthcheck_parent .checker
113
114
end
114
115
@@ -175,6 +176,7 @@ local function create_checker(upstream)
175
176
176
177
healthcheck_parent .checker = checker
177
178
healthcheck_parent .checker_upstream = upstream
179
+ healthcheck_parent .checker_nodes_ver = upstream ._nodes_ver
178
180
healthcheck_parent .checker_idx = check_idx
179
181
180
182
upstream .is_creating_checker = nil
@@ -302,35 +304,30 @@ function _M.set_by_route(route, api_ctx)
302
304
303
305
local same = upstream_util .compare_upstream_node (up_conf , new_nodes )
304
306
if not same then
307
+ if not up_conf ._nodes_ver then
308
+ up_conf ._nodes_ver = 0
309
+ end
310
+ up_conf ._nodes_ver = up_conf ._nodes_ver + 1
311
+
305
312
local pass , err = core .schema .check (core .schema .discovery_nodes , new_nodes )
306
313
if not pass then
307
314
return HTTP_CODE_UPSTREAM_UNAVAILABLE , " invalid nodes format: " .. err
308
315
end
309
316
310
- local new_up_conf = core .table .clone (up_conf )
311
- new_up_conf .nodes = new_nodes
312
- new_up_conf .original_nodes = up_conf .nodes
317
+ up_conf .nodes = new_nodes
313
318
314
319
core .log .info (" discover new upstream from " , up_conf .service_name , " , type " ,
315
320
up_conf .discovery_type , " : " ,
316
- core .json .delay_encode (new_up_conf , true ))
317
-
318
- local parent = up_conf .parent
319
- if parent .value .upstream then
320
- -- the up_conf comes from route or service
321
- parent .value .upstream = new_up_conf
322
- else
323
- parent .value = new_up_conf
324
- end
325
- up_conf = new_up_conf
321
+ core .json .delay_encode (up_conf , true ))
326
322
end
327
323
end
328
324
329
325
local id = up_conf .parent .value .id
330
326
local conf_version = up_conf .parent .modifiedIndex
331
327
-- include the upstream object as part of the version, because the upstream will be changed
332
328
-- by service discovery or dns resolver.
333
- set_directly (api_ctx , id , conf_version .. " #" .. tostring (up_conf ), up_conf )
329
+ set_directly (api_ctx , id , conf_version .. " #" .. tostring (up_conf ) .. " #"
330
+ .. tostring (up_conf ._nodes_ver or ' ' ), up_conf )
334
331
335
332
local nodes_count = up_conf .nodes and # up_conf .nodes or 0
336
333
if nodes_count == 0 then
0 commit comments