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 2023/06/08 08:20:59 UTC
[dubbo] branch 3.2 updated: Fix injvm invoker check (#12479)
This is an automated email from the ASF dual-hosted git repository.
albumenj pushed a commit to branch 3.2
in repository https://gitbox.apache.org/repos/asf/dubbo.git
The following commit(s) were added to refs/heads/3.2 by this push:
new f95111029b Fix injvm invoker check (#12479)
f95111029b is described below
commit f95111029bb36b671021583f567213c99d65538a
Author: Albumen Kevin <jh...@gmail.com>
AuthorDate: Thu Jun 8 16:20:51 2023 +0800
Fix injvm invoker check (#12479)
* Fix injvm invoker check
* Fix injvm invoker check
* Fix injvm invoker check
---
.../support/wrapper/ScopeClusterInvoker.java | 36 +++++++++++++++++-----
.../support/wrapper/ScopeClusterInvokerTest.java | 3 +-
2 files changed, 29 insertions(+), 10 deletions(-)
diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/wrapper/ScopeClusterInvoker.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/wrapper/ScopeClusterInvoker.java
index 7ac76c2ac3..71b7ddf95d 100644
--- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/wrapper/ScopeClusterInvoker.java
+++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/wrapper/ScopeClusterInvoker.java
@@ -40,14 +40,14 @@ import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
+import static org.apache.dubbo.common.constants.CommonConstants.BROADCAST_CLUSTER;
import static org.apache.dubbo.common.constants.CommonConstants.CLUSTER_KEY;
import static org.apache.dubbo.rpc.Constants.GENERIC_KEY;
import static org.apache.dubbo.rpc.Constants.LOCAL_PROTOCOL;
import static org.apache.dubbo.rpc.Constants.SCOPE_KEY;
-import static org.apache.dubbo.rpc.Constants.SCOPE_REMOTE;
import static org.apache.dubbo.rpc.Constants.SCOPE_LOCAL;
+import static org.apache.dubbo.rpc.Constants.SCOPE_REMOTE;
import static org.apache.dubbo.rpc.cluster.Constants.PEER_KEY;
-import static org.apache.dubbo.common.constants.CommonConstants.BROADCAST_CLUSTER;
/**
* ScopeClusterInvoker is a cluster invoker which handles the invocation logic of a single service in a specific scope.
@@ -100,7 +100,19 @@ public class ScopeClusterInvoker<T> implements ClusterInvoker<T>, ExporterChange
@Override
public boolean isAvailable() {
- return isExported.get() || directory.isAvailable();
+ if (peerFlag || isBroadcast()) {
+ // If it's a point-to-point direct connection or broadcasting, it should be called remotely.
+ return invoker.isAvailable();
+ }
+ if (injvmFlag && isForceLocal()) {
+ // If it's a local call, it should be called locally.
+ return isExported.get();
+ }
+ if (injvmFlag && isExported.get()) {
+ // If allow local call, check if local exported first
+ return true;
+ }
+ return invoker.isAvailable();
}
@Override
@@ -128,7 +140,7 @@ public class ScopeClusterInvoker<T> implements ClusterInvoker<T>, ExporterChange
@Override
public Result invoke(Invocation invocation) throws RpcException {
// When broadcasting, it should be called remotely.
- if (BROADCAST_CLUSTER.equalsIgnoreCase(getUrl().getParameter(CLUSTER_KEY))) {
+ if (isBroadcast()) {
if (logger.isDebugEnabled()) {
logger.debug("Performing broadcast call for method: " + invocation.getMethodName() + " of service: " + getUrl().getServiceKey());
}
@@ -155,6 +167,10 @@ public class ScopeClusterInvoker<T> implements ClusterInvoker<T>, ExporterChange
return invoker.invoke(invocation);
}
+ private boolean isBroadcast() {
+ return BROADCAST_CLUSTER.equalsIgnoreCase(getUrl().getParameter(CLUSTER_KEY));
+ }
+
@Override
public void onExporterChangeExport(Exporter<?> exporter) {
if (isExported.get()) {
@@ -230,9 +246,9 @@ public class ScopeClusterInvoker<T> implements ClusterInvoker<T>, ExporterChange
private boolean isInjvmExported() {
Boolean localInvoke = RpcContext.getServiceContext().getLocalInvoke();
boolean isExportedValue = isExported.get();
- boolean local = (localInvoke != null && localInvoke);
+ boolean localOnce = (localInvoke != null && localInvoke);
// Determine whether this call is local
- if (isExportedValue && local) {
+ if (isExportedValue && localOnce) {
return true;
}
@@ -242,8 +258,7 @@ public class ScopeClusterInvoker<T> implements ClusterInvoker<T>, ExporterChange
}
// When calling locally, determine whether it does not meet the requirements
- if (!isExportedValue && (SCOPE_LOCAL.equalsIgnoreCase(getUrl().getParameter(SCOPE_KEY)) ||
- Boolean.TRUE.toString().equalsIgnoreCase(getUrl().getParameter(LOCAL_PROTOCOL)) || local)) {
+ if (!isExportedValue && (isForceLocal() || localOnce)) {
// If it's supposed to be exported to the local JVM ,but it's not, throw an exception
throw new RpcException("Local service for " + getUrl().getServiceInterface() + " has not been exposed yet!");
}
@@ -251,6 +266,11 @@ public class ScopeClusterInvoker<T> implements ClusterInvoker<T>, ExporterChange
return isExportedValue && injvmFlag;
}
+ private boolean isForceLocal() {
+ return SCOPE_LOCAL.equalsIgnoreCase(getUrl().getParameter(SCOPE_KEY)) ||
+ Boolean.TRUE.toString().equalsIgnoreCase(getUrl().getParameter(LOCAL_PROTOCOL));
+ }
+
/**
* Creates a new Invoker for the current ScopeClusterInvoker and exports it to the local JVM.
*/
diff --git a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/support/wrapper/ScopeClusterInvokerTest.java b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/support/wrapper/ScopeClusterInvokerTest.java
index 2d54ba72e8..389aab4d4d 100644
--- a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/support/wrapper/ScopeClusterInvokerTest.java
+++ b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/support/wrapper/ScopeClusterInvokerTest.java
@@ -19,7 +19,6 @@ package org.apache.dubbo.rpc.cluster.support.wrapper;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.ExtensionLoader;
-
import org.apache.dubbo.metrics.event.MetricsDispatcher;
import org.apache.dubbo.rpc.Exporter;
import org.apache.dubbo.rpc.Invocation;
@@ -165,7 +164,7 @@ class ScopeClusterInvokerTest {
RpcInvocation invocation = new RpcInvocation();
invocation.setMethodName("doSomething4");
invocation.setParameterTypes(new Class[]{});
- Assertions.assertTrue(cluster.isAvailable(), "");
+ Assertions.assertFalse(cluster.isAvailable(), "");
RpcInvocation finalInvocation = invocation;
Assertions.assertThrows(RpcException.class, () -> cluster.invoke(finalInvocation));