nic-6443 commented on code in PR #12353:
URL: https://github.com/apache/apisix/pull/12353#discussion_r2158602660
##########
apisix/discovery/nacos/init.lua:
##########
@@ -318,50 +310,35 @@ local function fetch_full_registry(premature)
goto CONTINUE
end
- if not up_apps[namespace_id] then
- up_apps[namespace_id] = {}
- end
-
- if not up_apps[namespace_id][group_name] then
- up_apps[namespace_id][group_name] = {}
- end
-
+ local nodes = {}
+ local key = get_key(namespace_id, group_name,
service_info.service_name)
+ service_names[key] = true
for _, host in ipairs(data.hosts) do
- local nodes = up_apps[namespace_id]
- [group_name][service_info.service_name]
- if not nodes then
- nodes = {}
- up_apps[namespace_id]
- [group_name][service_info.service_name] = nodes
- end
-
local node = {
host = host.ip,
port = host.port,
weight = host.weight or default_weight,
}
-
-- docs:
https://github.com/yidongnan/grpc-spring-boot-starter/pull/496
if is_grpc(scheme) and host.metadata and host.metadata.gRPC_port
then
node.port = host.metadata.gRPC_port
end
core.table.insert(nodes, node)
end
-
+ if #nodes > 0 then
+ local content = core.json.encode(nodes)
+ nacos_dict:set(key, content)
+ end
::CONTINUE::
end
- local new_apps_md5sum = ngx.md5(core.json.encode(up_apps))
- local old_apps_md5sum = ngx.md5(core.json.encode(applications))
- if new_apps_md5sum == old_apps_md5sum then
- return
- end
- applications = up_apps
- local ok, err = events:post(events_list._source, events_list.updating,
- applications)
- if not ok then
- log.error("post_event failure with ", events_list._source,
- ", update application error: ", err)
+ local old_curr_service_in_use = curr_service_in_use
+ curr_service_in_use = service_names
+ -- remove services that are not in use anymore
+ for key, _ in pairs(old_curr_service_in_use) do
+ if not service_names[key] then
+ nacos_dict:delete(key)
+ end
end
Review Comment:
```suggestion
-- remove services that are not in use anymore
for key, _ in pairs(curr_service_in_use) do
if not service_names[key] then
nacos_dict:delete(key)
end
end
curr_service_in_use = service_names
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]