Merge branch '3.2' into 3.3

# Conflicts:
#	dubbo-build-tools/pom.xml
#	dubbo-dependencies/dubbo-dependencies-zookeeper-curator5/pom.xml
#	dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleInvoker.java
#	pom.xml
This commit is contained in:
crazyhzm 2023-12-04 19:53:18 +08:00
commit c302fcccd8
18 changed files with 147 additions and 40 deletions

View File

@ -201,7 +201,7 @@
<portlet_version>2.0</portlet_version>
<maven_flatten_version>1.5.0</maven_flatten_version>
<commons_compress_version>1.23.0</commons_compress_version>
<spotless-maven-plugin.version>2.40.0</spotless-maven-plugin.version>
<spotless-maven-plugin.version>2.41.0</spotless-maven-plugin.version>
<spotless.action>check</spotless.action>
<dubbo-shared-resources.version>1.0.0</dubbo-shared-resources.version>
<palantirJavaFormat.version>2.38.0</palantirJavaFormat.version>

View File

@ -36,7 +36,7 @@
<slf4j_version>1.7.36</slf4j_version>
<curator5_version>5.1.0</curator5_version>
<zookeeper_version>3.8.3</zookeeper_version>
<spotless-maven-plugin.version>2.40.0</spotless-maven-plugin.version>
<spotless-maven-plugin.version>2.41.0</spotless-maven-plugin.version>
<spotless.action>check</spotless.action>
<dubbo-shared-resources.version>1.0.0</dubbo-shared-resources.version>
<palantirJavaFormat.version>2.38.0</palantirJavaFormat.version>

View File

@ -36,7 +36,7 @@
<slf4j_version>1.7.36</slf4j_version>
<curator_version>4.3.0</curator_version>
<zookeeper_version>3.4.14</zookeeper_version>
<spotless-maven-plugin.version>2.40.0</spotless-maven-plugin.version>
<spotless-maven-plugin.version>2.41.0</spotless-maven-plugin.version>
<spotless.action>check</spotless.action>
<dubbo-shared-resources.version>1.0.0</dubbo-shared-resources.version>
<palantirJavaFormat.version>2.38.0</palantirJavaFormat.version>

View File

@ -32,7 +32,7 @@
</modules>
<properties>
<spotless-maven-plugin.version>2.40.0</spotless-maven-plugin.version>
<spotless-maven-plugin.version>2.41.0</spotless-maven-plugin.version>
<spotless.action>check</spotless.action>
<dubbo-shared-resources.version>1.0.0</dubbo-shared-resources.version>
<palantirJavaFormat.version>2.38.0</palantirJavaFormat.version>

View File

@ -28,7 +28,7 @@
<packaging>pom</packaging>
<properties>
<spotless-maven-plugin.version>2.40.0</spotless-maven-plugin.version>
<spotless-maven-plugin.version>2.41.0</spotless-maven-plugin.version>
<spotless.action>check</spotless.action>
<dubbo-shared-resources.version>1.0.0</dubbo-shared-resources.version>
<palantirJavaFormat.version>2.38.0</palantirJavaFormat.version>

View File

@ -28,4 +28,6 @@ public interface MetadataConstants {
String REPORT_CONSUMER_URL_KEY = "report-consumer-definition";
String PATH_SEPARATOR = "/";
String NAMESPACE_KEY = "namespace";
}

View File

@ -19,6 +19,7 @@ package org.apache.dubbo.metadata.report;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.URLBuilder;
import org.apache.dubbo.common.resource.Disposable;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.config.MetadataReportConfig;
import org.apache.dubbo.metadata.report.support.NopMetadataReport;
import org.apache.dubbo.rpc.model.ApplicationModel;
@ -35,6 +36,7 @@ import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_METADATA
import static org.apache.dubbo.common.constants.CommonConstants.PORT_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.REGISTRY_LOCAL_FILE_CACHE_ENABLED;
import static org.apache.dubbo.common.utils.StringUtils.isEmpty;
import static org.apache.dubbo.metadata.MetadataConstants.NAMESPACE_KEY;
import static org.apache.dubbo.metadata.report.support.Constants.METADATA_REPORT_KEY;
/**
@ -102,18 +104,26 @@ public class MetadataReportInstance implements Disposable {
url = url.addParameterIfAbsent(
REGISTRY_LOCAL_FILE_CACHE_ENABLED,
String.valueOf(applicationModel.getCurrentConfig().getEnableFileCache()));
String relatedRegistryId = isEmpty(config.getRegistry())
? (isEmpty(config.getId()) ? DEFAULT_KEY : config.getId())
: config.getRegistry();
// RegistryConfig registryConfig = applicationModel.getConfigManager().getRegistry(relatedRegistryId)
// .orElseThrow(() -> new IllegalStateException("Registry id " + relatedRegistryId + " does not
// exist."));
MetadataReport metadataReport = metadataReportFactory.getMetadataReport(url);
if (metadataReport != null) {
metadataReports.put(relatedRegistryId, metadataReport);
metadataReports.put(getRelatedRegistryId(config, url), metadataReport);
}
}
private String getRelatedRegistryId(MetadataReportConfig config, URL url) {
String relatedRegistryId = isEmpty(config.getRegistry())
? (isEmpty(config.getId()) ? DEFAULT_KEY : config.getId())
: config.getRegistry();
String namespace = url.getParameter(NAMESPACE_KEY);
if (!StringUtils.isEmpty(namespace)) {
relatedRegistryId += ":" + namespace;
}
return relatedRegistryId;
}
public Map<String, MetadataReport> getMetadataReports(boolean checked) {
return metadataReports;
}

View File

@ -50,7 +50,7 @@ public abstract class AbstractMetadataReportFactory implements MetadataReportFac
@Override
public MetadataReport getMetadataReport(URL url) {
url = url.setPath(MetadataReport.class.getName()).removeParameters(EXPORT_KEY, REFER_KEY);
String key = url.toServiceString();
String key = toMetadataReportKey(url);
MetadataReport metadataReport = serviceStoreMap.get(key);
if (metadataReport != null) {
@ -88,6 +88,10 @@ public abstract class AbstractMetadataReportFactory implements MetadataReportFac
}
}
protected String toMetadataReportKey(URL url) {
return url.toServiceString();
}
@Override
public void destroy() {
lock.lock();

View File

@ -17,9 +17,12 @@
package org.apache.dubbo.metadata.store.nacos;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.metadata.report.MetadataReport;
import org.apache.dubbo.metadata.report.support.AbstractMetadataReportFactory;
import static org.apache.dubbo.metadata.MetadataConstants.NAMESPACE_KEY;
/**
* metadata report factory impl for nacos
*/
@ -28,4 +31,15 @@ public class NacosMetadataReportFactory extends AbstractMetadataReportFactory {
protected MetadataReport createMetadataReport(URL url) {
return new NacosMetadataReport(url);
}
@Override
protected String toMetadataReportKey(URL url) {
String namespace = url.getParameter(NAMESPACE_KEY);
if (!StringUtils.isEmpty(namespace)) {
return URL.valueOf(url.toServiceString())
.addParameter(NAMESPACE_KEY, namespace)
.toString();
}
return super.toMetadataReportKey(url);
}
}

View File

@ -29,6 +29,8 @@ import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.lang.reflect.Parameter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.LinkedList;
@ -207,20 +209,41 @@ public abstract class AbstractServiceRestMetadataResolver implements ServiceRest
sort(declaredServiceMethods, MethodComparator.INSTANCE);
sort(serviceMethods, MethodComparator.INSTANCE);
// prevent from repeat method (impl proxy) & leaving out method(interface proxy)
HashSet<String> methodComparators = new HashSet<>();
// TODO Map key: method desc & value: Set<Method> for accelerate loop speed
for (Method declaredServiceMethod : declaredServiceMethods) {
for (Method serviceMethod : serviceMethods) {
if (overrides(serviceMethod, declaredServiceMethod)) {
serviceMethodsMap.put(serviceMethod, declaredServiceMethod);
// override method count > 1
// // once method match ,break for decrease loop times
// break;
if (!overrides(serviceMethod, declaredServiceMethod)) {
continue;
}
String methodDesc = getMethodDesc(serviceMethod);
if (!methodComparators.add(methodDesc)) {
continue;
}
serviceMethodsMap.put(serviceMethod, declaredServiceMethod);
}
}
// make them to be read-only
return unmodifiableMap(serviceMethodsMap);
}
/**
* For simple method desc
*
* @param serviceMethod
* @return
*/
private String getMethodDesc(Method serviceMethod) {
return serviceMethod.getName() + Arrays.toString(serviceMethod.getParameterTypes());
}
private void putServiceMethodToMap(Map<Method, Method> serviceMethodsMap, List<Method> declaredServiceMethods) {
declaredServiceMethods.stream().forEach(method -> {

View File

@ -41,13 +41,11 @@ import java.util.concurrent.atomic.AtomicLong;
* the key will not be displayed when exporting (to be optimized)
*/
public class MethodStatComposite extends AbstractMetricsExport {
private boolean serviceLevel;
private final AtomicBoolean samplesChanged = new AtomicBoolean(true);
public MethodStatComposite(ApplicationModel applicationModel) {
super(applicationModel);
this.serviceLevel = MethodMetric.isServiceLevel(getApplicationModel());
}
private final Map<MetricsKeyWrapper, Map<MethodMetric, AtomicLong>> methodNumStats = new ConcurrentHashMap<>();
@ -70,7 +68,8 @@ public class MethodStatComposite extends AbstractMetricsExport {
methodNumStats
.get(wrapper)
.computeIfAbsent(
new MethodMetric(getApplicationModel(), invocation, serviceLevel), k -> new AtomicLong(0L));
new MethodMetric(getApplicationModel(), invocation, getServiceLevel()),
k -> new AtomicLong(0L));
samplesChanged.set(true);
}

View File

@ -50,13 +50,11 @@ import java.util.stream.Collectors;
*/
@SuppressWarnings({"rawtypes", "unchecked"})
public class RtStatComposite extends AbstractMetricsExport {
private boolean serviceLevel;
private final AtomicBoolean samplesChanged = new AtomicBoolean(true);
public RtStatComposite(ApplicationModel applicationModel) {
super(applicationModel);
this.serviceLevel = MethodMetric.isServiceLevel(getApplicationModel());
}
private final Map<String, List<LongContainer<? extends Number>>> rtStats = new ConcurrentHashMap<>();
@ -190,7 +188,7 @@ public class RtStatComposite extends AbstractMetricsExport {
List<Action> actions;
actions = new LinkedList<>();
for (LongContainer container : rtStats.get(registryOpType)) {
MethodMetric key = new MethodMetric(getApplicationModel(), invocation, serviceLevel);
MethodMetric key = new MethodMetric(getApplicationModel(), invocation, getServiceLevel());
Number current = (Number) container.get(key);
if (current == null) {
container.putIfAbsent(key, container.getInitFunc().apply(key));

View File

@ -16,6 +16,7 @@
*/
package org.apache.dubbo.metrics.report;
import org.apache.dubbo.metrics.model.MethodMetric;
import org.apache.dubbo.rpc.model.ApplicationModel;
/**
@ -23,6 +24,8 @@ import org.apache.dubbo.rpc.model.ApplicationModel;
*/
public abstract class AbstractMetricsExport implements MetricsExport {
private volatile Boolean serviceLevel;
private final ApplicationModel applicationModel;
public AbstractMetricsExport(ApplicationModel applicationModel) {
@ -36,4 +39,19 @@ public abstract class AbstractMetricsExport implements MetricsExport {
public String getAppName() {
return getApplicationModel().getApplicationName();
}
protected boolean getServiceLevel() {
initServiceLevelConfig();
return this.serviceLevel;
}
private void initServiceLevelConfig() {
if (serviceLevel == null) {
synchronized (this) {
if (serviceLevel == null) {
this.serviceLevel = MethodMetric.isServiceLevel(getApplicationModel());
}
}
}
}
}

View File

@ -47,6 +47,9 @@ import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.aop.framework.AdvisedSupport;
import org.springframework.aop.framework.AopProxy;
import org.springframework.aop.framework.ProxyCreatorSupport;
import org.springframework.util.LinkedMultiValueMap;
import static org.apache.dubbo.remoting.Constants.SERVER_KEY;
@ -398,6 +401,35 @@ public class SpringMvcRestProtocolTest {
exporter.unexport();
}
@Test
void testProxyDoubleCheck() {
ProxyCreatorSupport proxyCreatorSupport = new ProxyCreatorSupport();
AdvisedSupport advisedSupport = new AdvisedSupport();
advisedSupport.setTarget(getServerImpl());
AopProxy aopProxy = proxyCreatorSupport.getAopProxyFactory().createAopProxy(advisedSupport);
Object proxy = aopProxy.getProxy();
SpringRestDemoService server = (SpringRestDemoService) proxy;
URL nettyUrl = this.registerProvider(exportUrl, server, SpringRestDemoService.class);
Exporter<SpringRestDemoService> exporter = getExport(nettyUrl, server);
SpringRestDemoService demoService = this.proxy.getProxy(protocol.refer(SpringRestDemoService.class, nettyUrl));
Integer result = demoService.primitiveInt(1, 2);
Long resultLong = demoService.primitiveLong(1, 2l);
long resultByte = demoService.primitiveByte((byte) 1, 2l);
long resultShort = demoService.primitiveShort((short) 1, 2l, 1);
assertThat(result, is(3));
assertThat(resultShort, is(3l));
assertThat(resultLong, is(3l));
assertThat(resultByte, is(3l));
exporter.unexport();
}
public static class TestExceptionMapper implements ExceptionHandler<RuntimeException> {
@Override

View File

@ -19,6 +19,8 @@ package org.apache.dubbo.rpc;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.remoting.TimeoutException;
import java.io.Serializable;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.netty.handler.codec.http.QueryStringDecoder;
import io.netty.handler.codec.http.QueryStringEncoder;
@ -35,7 +37,7 @@ import static org.apache.dubbo.rpc.RpcException.UNKNOWN_EXCEPTION;
/**
* See https://github.com/grpc/grpc/blob/master/doc/statuscodes.md
*/
public class TriRpcStatus {
public class TriRpcStatus implements Serializable {
public static final TriRpcStatus OK = fromCode(Code.OK);
public static final TriRpcStatus UNKNOWN = fromCode(Code.UNKNOWN);

View File

@ -144,12 +144,12 @@ public class TripleInvoker<T> extends AbstractInvoker<T> {
ConsumerModel consumerModel = (ConsumerModel)
(invocation.getServiceModel() != null ? invocation.getServiceModel() : getUrl().getServiceModel());
ServiceDescriptor serviceDescriptor = consumerModel.getServiceModel();
final MethodDescriptor methodDescriptor;
boolean genericCall = RpcUtils.isGenericCall(
ReflectUtils.getDesc(invocation.getParameterTypes()), invocation.getMethodName());
if (!genericCall) {
methodDescriptor = serviceDescriptor.getMethod(invocation.getMethodName(), invocation.getParameterTypes());
} else {
MethodDescriptor methodDescriptor =
serviceDescriptor.getMethod(invocation.getMethodName(), invocation.getParameterTypes());
if (methodDescriptor == null
&& RpcUtils.isGenericCall(
((RpcInvocation) invocation).getParameterTypesDesc(), invocation.getMethodName())) {
// Only reach when server generic
methodDescriptor = ServiceDescriptorInternalCache.genericService()
.getMethod(invocation.getMethodName(), invocation.getParameterTypes());
}
@ -262,17 +262,7 @@ public class TripleInvoker<T> extends AbstractInvoker<T> {
if (methodDescriptor instanceof StubMethodDescriptor) {
pureArgument = invocation.getArguments()[0];
} else {
if (methodDescriptor.isGeneric()) {
Object[] args = new Object[3];
args[0] = RpcUtils.getMethodName(invocation);
args[1] = Arrays.stream(RpcUtils.getParameterTypes(invocation))
.map(Class::getName)
.toArray(String[]::new);
args[2] = RpcUtils.getArguments(invocation);
pureArgument = args;
} else {
pureArgument = invocation.getArguments();
}
pureArgument = invocation.getArguments();
}
result = new AsyncRpcResult(future, invocation);
if (setFutureWhenSync || ((RpcInvocation) invocation).getInvokeMode() != InvokeMode.SYNC) {

View File

@ -19,6 +19,8 @@ package org.apache.dubbo.rpc;
import org.apache.dubbo.remoting.TimeoutException;
import org.apache.dubbo.rpc.TriRpcStatus.Code;
import java.io.Serializable;
import io.netty.handler.codec.http.HttpResponseStatus;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
@ -214,4 +216,11 @@ class TriRpcStatusTest {
Assertions.assertEquals(METHOD_NOT_FOUND, TriRpcStatus.triCodeToDubboCode(Code.UNIMPLEMENTED));
Assertions.assertEquals(UNKNOWN_EXCEPTION, TriRpcStatus.triCodeToDubboCode(Code.UNKNOWN));
}
@Test
void testSerializable() {
TriRpcStatus status = TriRpcStatus.INTERNAL.withDescription("test");
Assertions.assertInstanceOf(Serializable.class, status.asException());
Assertions.assertInstanceOf(Serializable.class, status.asException().getStatus());
}
}

View File

@ -150,7 +150,7 @@
<protobuf-protoc_version>3.22.3</protobuf-protoc_version>
<grpc_version>1.54.0</grpc_version>
<spotless-maven-plugin.version>2.40.0</spotless-maven-plugin.version>
<spotless-maven-plugin.version>2.41.0</spotless-maven-plugin.version>
<spotless.action>check</spotless.action>
<dubbo-shared-resources.version>1.0.0</dubbo-shared-resources.version>
<palantirJavaFormat.version>2.38.0</palantirJavaFormat.version>
@ -869,6 +869,12 @@
<exclude>src/main/java/org/apache/dubbo/common/logger/helpers/MessageFormatter.java</exclude>
<exclude>src/main/java/org/apache/dubbo/maven/plugin/protoc/DubboProtocCompilerMojo.java</exclude>
<exclude>src/main/java/org/apache/dubbo/gen/utils/ProtoTypeMap.java</exclude>
<exclude>**/TripleWrapper.java</exclude>
<exclude>**/com/google/rpc/**</exclude>
<exclude>**/io/grpc/**</exclude>
<exclude>**/istio/**</exclude>
<exclude>**/org/apache/dubbo/auth/v1alpha1/**</exclude>
<exclude>**/demo/hello/**</exclude>
</excludes>
<palantirJavaFormat>
<version>${palantirJavaFormat.version}</version>