Skip to content

Commit

Permalink
解决服务元数据清理逻辑导致的反注册失败问题 alibaba#9586
Browse files Browse the repository at this point in the history
  • Loading branch information
hujun-w-2 committed Nov 16, 2022
1 parent fcf633a commit 2d2e43e
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

package com.alibaba.nacos.naming.core.v2;

import com.alibaba.nacos.common.notify.NotifyCenter;
import com.alibaba.nacos.common.utils.ConcurrentHashSet;
import com.alibaba.nacos.naming.core.v2.event.metadata.MetadataEvent;
import com.alibaba.nacos.naming.core.v2.pojo.Service;

import java.util.HashSet;
Expand Down Expand Up @@ -57,7 +59,10 @@ public Set<Service> getSingletons(String namespace) {
* @return if service is exist, return exist service, otherwise return new service
*/
public Service getSingleton(Service service) {
singletonRepository.putIfAbsent(service, service);
singletonRepository.computeIfAbsent(service, (key) -> {
NotifyCenter.publishEvent(new MetadataEvent.ServiceMetadataEvent(service, false));
return service;
});
Service result = singletonRepository.get(service);
namespaceSingletonMaps.computeIfAbsent(result.getNamespace(), (namespace) -> new ConcurrentHashSet<>());
namespaceSingletonMaps.get(result.getNamespace()).add(result);
Expand Down

0 comments on commit 2d2e43e

Please sign in to comment.