You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by al...@apache.org on 2021/05/23 08:23:37 UTC
[dubbo] branch 3.0 updated: fix addr cache bug (#7833)
This is an automated email from the ASF dual-hosted git repository.
albumenj pushed a commit to branch 3.0
in repository https://gitbox.apache.org/repos/asf/dubbo.git
The following commit(s) were added to refs/heads/3.0 by this push:
new 97aec36 fix addr cache bug (#7833)
97aec36 is described below
commit 97aec3671e4829c07b6a7c7e91436e4818321e04
Author: panxiaojun233 <43...@users.noreply.github.com>
AuthorDate: Sun May 23 16:23:24 2021 +0800
fix addr cache bug (#7833)
---
.../main/java/org/apache/dubbo/rpc/cluster/RouterChain.java | 9 ++++++---
.../org/apache/dubbo/rpc/cluster/router/state/AddrCache.java | 11 +++++------
2 files changed, 11 insertions(+), 9 deletions(-)
diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/RouterChain.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/RouterChain.java
index eb92945..29a7be5 100644
--- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/RouterChain.java
+++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/RouterChain.java
@@ -18,7 +18,9 @@ package org.apache.dubbo.rpc.cluster;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Semaphore;
import java.util.concurrent.atomic.AtomicReference;
@@ -209,19 +211,20 @@ public class RouterChain<T> {
AddrCache<T> origin = cache.get();
List<Invoker<T>> copyInvokers = new ArrayList<>(this.invokers);
AddrCache<T> newCache = new AddrCache<T>();
+ Map<String, RouterCache<T>> routerCacheMap = new HashMap<>((int) (stateRouters.size() / 0.75f) + 1);
newCache.setInvokers(invokers);
for (StateRouter stateRouter : stateRouters) {
- RouterCache routerCache;
try {
- routerCache = poolRouter(stateRouter, origin, copyInvokers, notify);
+ RouterCache routerCache = poolRouter(stateRouter, origin, copyInvokers, notify);
//file cache
- newCache.getCache().put(stateRouter.getName(), routerCache);
+ routerCacheMap.put(stateRouter.getName(), routerCache);
} catch (Throwable t) {
logger.error("Failed to pool router: " + stateRouter.getUrl() + ", cause: " + t.getMessage(), t);
return;
}
}
+ newCache.setCache(routerCacheMap);
this.cache.set(newCache);
}
diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/state/AddrCache.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/state/AddrCache.java
index 9d1e9b3..c11fbbb 100644
--- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/state/AddrCache.java
+++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/state/AddrCache.java
@@ -16,9 +16,9 @@
*/
package org.apache.dubbo.rpc.cluster.router.state;
+import java.util.Collections;
import java.util.List;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
+import java.util.Map;
import org.apache.dubbo.rpc.Invoker;
@@ -29,10 +29,9 @@ import org.apache.dubbo.rpc.Invoker;
* @since 3.0
*/
public class AddrCache<T> {
- private final static ConcurrentHashMap EMPTY_MAP = new ConcurrentHashMap<>();
protected List<Invoker<T>> invokers;
- protected ConcurrentMap<String, RouterCache<T>> cache = EMPTY_MAP;
+ protected Map<String, RouterCache<T>> cache = Collections.emptyMap();
public List<Invoker<T>> getInvokers() {
return invokers;
@@ -42,11 +41,11 @@ public class AddrCache<T> {
this.invokers = invokers;
}
- public ConcurrentMap<String, RouterCache<T>> getCache() {
+ public Map<String, RouterCache<T>> getCache() {
return cache;
}
- public void setCache(ConcurrentHashMap<String, RouterCache<T>> cache) {
+ public void setCache(Map<String, RouterCache<T>> cache) {
this.cache = cache;
}
}