Skip to content

Commit a35af27

Browse files
authored
Remove duplicated invokers in registry notification (#15060)
1 parent fc5f066 commit a35af27

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceDiscoveryRegistryDirectory.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,17 @@ private void refreshInvoker(List<URL> invokerUrls) {
340340
return;
341341
}
342342

343+
int originSize = invokerUrls.size();
344+
invokerUrls = invokerUrls.stream().distinct().collect(Collectors.toList());
345+
if (invokerUrls.size() != originSize) {
346+
logger.info("Received duplicated invoker urls changed event from registry. "
347+
+ "Registry type: instance. "
348+
+ "Service Key: "
349+
+ getConsumerUrl().getServiceKey() + ". "
350+
+ "Notify Urls Size : " + originSize + ". "
351+
+ "Distinct Urls Size: " + invokerUrls.size() + ".");
352+
}
353+
343354
// use local reference to avoid NPE as this.urlInvokerMap will be set null concurrently at
344355
// destroyAllInvokers().
345356
Map<ProtocolServiceKeyWithAddress, Invoker<T>> localUrlInvokerMap = this.urlInvokerMap;

dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryDirectory.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,17 @@ private void refreshInvoker(List<URL> invokerUrls) {
305305
return;
306306
}
307307

308+
int originSize = invokerUrls.size();
309+
invokerUrls = invokerUrls.stream().distinct().collect(Collectors.toList());
310+
if (invokerUrls.size() != originSize) {
311+
logger.info("Received duplicated invoker urls changed event from registry. "
312+
+ "Registry type: interface. "
313+
+ "Service Key: "
314+
+ getConsumerUrl().getServiceKey() + ". "
315+
+ "Notify Urls Size : " + originSize + ". "
316+
+ "Distinct Urls Size: " + invokerUrls.size() + ".");
317+
}
318+
308319
// use local reference to avoid NPE as this.urlInvokerMap will be set null concurrently at
309320
// destroyAllInvokers().
310321
Map<URL, Invoker<T>> localUrlInvokerMap = this.urlInvokerMap;

0 commit comments

Comments
 (0)