From 4be3c796cc0be52daa21b70c4cbb48413f3fe481 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=80=E4=B8=AA=E4=B8=8D=E7=9F=A5=E5=90=8D=E7=9A=84Java?= =?UTF-8?q?=E9=9D=93=E4=BB=94?= Date: Mon, 27 Feb 2023 14:25:39 +0800 Subject: [PATCH 1/4] optimize the multi params request performance of triple in wrap mode (#11672) --- .../dubbo/rpc/protocol/tri/ReflectionPackableMethod.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/ReflectionPackableMethod.java b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/ReflectionPackableMethod.java index 8667beb87a7..52e6afc01fa 100644 --- a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/ReflectionPackableMethod.java +++ b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/ReflectionPackableMethod.java @@ -390,11 +390,12 @@ public byte[] pack(Object obj) throws IOException { for (String type : argumentsType) { builder.addArgTypes(type); } + ByteArrayOutputStream bos = new ByteArrayOutputStream(); for (int i = 0; i < arguments.length; i++) { Object argument = arguments[i]; - ByteArrayOutputStream bos = new ByteArrayOutputStream(); multipleSerialization.serialize(url, serialize, actualRequestTypes[i], argument, bos); builder.addArgs(bos.toByteArray()); + bos.reset(); } return builder.build().toByteArray(); } From f8f89f2a712b8cc61f542c19f24e410e650eb8da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=80=E4=B8=AA=E4=B8=8D=E7=9F=A5=E5=90=8D=E7=9A=84Java?= =?UTF-8?q?=E9=9D=93=E4=BB=94?= Date: Mon, 27 Feb 2023 14:38:57 +0800 Subject: [PATCH 2/4] replaced with EN assert (#11670) --- .../dubbo/rpc/protocol/tri/TripleCustomerProtocolWapper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleCustomerProtocolWapper.java b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleCustomerProtocolWapper.java index 78eb166f60a..e9479375f3e 100644 --- a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleCustomerProtocolWapper.java +++ b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleCustomerProtocolWapper.java @@ -344,7 +344,7 @@ public Builder setSerializeType(String serializeType) { } public Builder addArgTypes(String argsType) { - Assert.notEmptyString(argsType, "argsType不能为空"); + Assert.notEmptyString(argsType, "argsType cannot be empty."); argTypes.add(argsType); return this; } From a21d04255a9aae791b526a43c560b9645d063b18 Mon Sep 17 00:00:00 2001 From: Mengyang Tang Date: Mon, 6 Mar 2023 15:26:15 +0800 Subject: [PATCH 3/4] Fix issue 11708 (#11714) --- .../apache/dubbo/qos/pu/TelnetDetector.java | 19 ++++++++++++------- .../dubbo/remoting/buffer/ChannelBuffer.java | 8 ++++++++ .../remoting/buffer/DynamicChannelBuffer.java | 5 +++++ .../netty4/NettyBackedChannelBuffer.java | 6 ++++++ 4 files changed, 31 insertions(+), 7 deletions(-) diff --git a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/pu/TelnetDetector.java b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/pu/TelnetDetector.java index 84199937d47..a7b7c47ff7b 100644 --- a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/pu/TelnetDetector.java +++ b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/pu/TelnetDetector.java @@ -32,7 +32,7 @@ public class TelnetDetector implements ProtocolDetector { - private FrameworkModel frameworkModel; + private final FrameworkModel frameworkModel; private final int MaxSize = 2048; private final ChannelBuffer AytPreface = new HeapChannelBuffer(new byte[]{(byte) 0xff, (byte) 0xf6}); @@ -46,7 +46,7 @@ public Result detect(ChannelBuffer in) { return Result.UNRECOGNIZED; } Result resCommand = commandDetect(in); - if (resCommand.equals(Result.RECOGNIZED)){ + if (resCommand.equals(Result.RECOGNIZED)) { return resCommand; } Result resAyt = telnetAytDetect(in); @@ -62,14 +62,19 @@ public Result detect(ChannelBuffer in) { private Result commandDetect(ChannelBuffer in) { // detect if remote channel send a qos command to server ChannelBuffer back = in.copy(); - byte[] backBytes = new byte[back.readableBytes()]; - back.getBytes(back.readerIndex(), backBytes); + byte[] backBytes; + try { + backBytes = new byte[back.readableBytes()]; + back.getBytes(back.readerIndex(), backBytes); + } finally { + back.release(); + } String s = new String(backBytes, CharsetUtil.UTF_8); // trim /r/n to let parser work for input s = s.trim(); CommandContext commandContext = TelnetCommandDecoder.decode(s); - if(frameworkModel.getExtensionLoader(BaseCommand.class).hasExtension(commandContext.getCommandName())){ + if (frameworkModel.getExtensionLoader(BaseCommand.class).hasExtension(commandContext.getCommandName())) { return Result.RECOGNIZED; } return Result.UNRECOGNIZED; @@ -79,10 +84,10 @@ private Result telnetAytDetect(ChannelBuffer in) { // detect if remote channel send a telnet ayt command to server int prefaceLen = AytPreface.readableBytes(); int bytesRead = min(in.readableBytes(), prefaceLen); - if(bytesRead == 0 || !ChannelBuffers.prefixEquals(in, AytPreface, bytesRead)) { + if (bytesRead == 0 || !ChannelBuffers.prefixEquals(in, AytPreface, bytesRead)) { return Result.UNRECOGNIZED; } - if(bytesRead == prefaceLen) { + if (bytesRead == prefaceLen) { // we need to consume preface because it's not a qos command // consume and remember to mark, pu server handler reset reader index in.readBytes(AytPreface.readableBytes()); diff --git a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/buffer/ChannelBuffer.java b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/buffer/ChannelBuffer.java index fab35dd80ef..e77cf46ab2c 100644 --- a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/buffer/ChannelBuffer.java +++ b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/buffer/ChannelBuffer.java @@ -948,4 +948,12 @@ public interface ChannelBuffer extends Comparable { * array */ int arrayOffset(); + + /** + * If this buffer is backed by an NIO direct buffer, + * in some scenarios it may be necessary to manually release. + */ + default void release() { + + } } diff --git a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/buffer/DynamicChannelBuffer.java b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/buffer/DynamicChannelBuffer.java index dbd9677a76b..cfd7965ffec 100644 --- a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/buffer/DynamicChannelBuffer.java +++ b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/buffer/DynamicChannelBuffer.java @@ -200,4 +200,9 @@ public boolean hasArray() { public int arrayOffset() { return buffer.arrayOffset(); } + + @Override + public void release() { + buffer.release(); + } } diff --git a/dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/NettyBackedChannelBuffer.java b/dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/NettyBackedChannelBuffer.java index a64a646721e..fd1f9c7c527 100644 --- a/dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/NettyBackedChannelBuffer.java +++ b/dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/NettyBackedChannelBuffer.java @@ -22,6 +22,7 @@ import org.apache.dubbo.remoting.buffer.ChannelBuffers; import io.netty.buffer.ByteBuf; +import io.netty.util.ReferenceCountUtil; import java.io.IOException; import java.io.InputStream; @@ -447,4 +448,9 @@ public void writerIndex(int writerIndex) { public int compareTo(ChannelBuffer o) { return ChannelBuffers.compare(this, o); } + + @Override + public void release() { + ReferenceCountUtil.safeRelease(buffer); + } } From 7277c159cf6cc614e7ef8d7a48067e9a57d88885 Mon Sep 17 00:00:00 2001 From: liufeiyu1002 <32605119+liufeiyu1002@users.noreply.github.com> Date: Fri, 3 Mar 2023 07:15:26 +0800 Subject: [PATCH 4/4] fix reference bean name conflicts (#11699) * fix reference bean name conflicts * add ut case --- .../ReferenceAnnotationBeanPostProcessor.java | 19 ++++++++++-- ...erenceAnnotationBeanPostProcessorTest.java | 29 +++++++++++++++---- 2 files changed, 40 insertions(+), 8 deletions(-) diff --git a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/ReferenceAnnotationBeanPostProcessor.java b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/ReferenceAnnotationBeanPostProcessor.java index be855881bce..de7e6cc0fc9 100644 --- a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/ReferenceAnnotationBeanPostProcessor.java +++ b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/ReferenceAnnotationBeanPostProcessor.java @@ -19,6 +19,7 @@ import org.apache.dubbo.common.logger.ErrorTypeAwareLogger; import org.apache.dubbo.common.logger.LoggerFactory; +import org.apache.dubbo.common.utils.ArrayUtils; import org.apache.dubbo.common.utils.Assert; import org.apache.dubbo.common.utils.ClassUtils; import org.apache.dubbo.common.utils.StringUtils; @@ -399,8 +400,22 @@ public String registerReferenceBean(String propertyName, Class injectedType, } //check bean definition - if (beanDefinitionRegistry.containsBeanDefinition(referenceBeanName)) { - BeanDefinition prevBeanDefinition = beanDefinitionRegistry.getBeanDefinition(referenceBeanName); + boolean isContains; + if ((isContains = beanDefinitionRegistry.containsBeanDefinition(referenceBeanName)) || beanDefinitionRegistry.isAlias(referenceBeanName)) { + String preReferenceBeanName = referenceBeanName; + if (!isContains){ + // Look in the alias for the origin bean name + String[] aliases = beanDefinitionRegistry.getAliases(referenceBeanName); + if (ArrayUtils.isNotEmpty(aliases)) { + for (String alias : aliases) { + if (beanDefinitionRegistry.containsBeanDefinition(alias)) { + preReferenceBeanName = alias; + break; + } + } + } + } + BeanDefinition prevBeanDefinition = beanDefinitionRegistry.getBeanDefinition(preReferenceBeanName); String prevBeanType = prevBeanDefinition.getBeanClassName(); String prevBeanDesc = referenceBeanName + "[" + prevBeanType + "]"; String newBeanDesc = referenceBeanName + "[" + referenceKey + "]"; diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/ReferenceAnnotationBeanPostProcessorTest.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/ReferenceAnnotationBeanPostProcessorTest.java index 06d0592668a..a4fbcff02d2 100644 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/ReferenceAnnotationBeanPostProcessorTest.java +++ b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/ReferenceAnnotationBeanPostProcessorTest.java @@ -128,15 +128,30 @@ public Object aroundHelloService(ProceedingJoinPoint pjp) throws Throwable { @DubboReference(version = "2", url = "dubbo://127.0.0.1:12345?version=2", tag = "demo_tag") private HelloService helloService2; - // #7 ReferenceBean (Method Injection #3) + // #7 ReferenceBean (Field Injection #5) + // The HelloService is the same as above service(#6 ReferenceBean (Field Injection #4)), helloService3 will be registered as an alias of helloService2 + @DubboReference(version = "2", url = "dubbo://127.0.0.1:12345?version=2", tag = "demo_tag") + private HelloService helloService3; + + // #8 ReferenceBean (Method Injection #3) @DubboReference(version = "3", url = "dubbo://127.0.0.1:12345?version=2", tag = "demo_tag") public void setHelloService2(HelloService helloService2) { // The helloService2 beanName is the same as above(#6 ReferenceBean (Field Injection #4)), and this will rename to helloService2#2 renamedHelloService2 = helloService2; } + // #9 ReferenceBean (Method Injection #4) + @DubboReference(version = "4", url = "dubbo://127.0.0.1:12345?version=2") + public void setHelloService3(DemoService helloService3){ + // The helloService3 beanName is the same as above(#7 ReferenceBean (Field Injection #5) is an alias), + // The current beanName(helloService3) is not registered in the beanDefinitionMap, but it is already an alias. so this will rename to helloService3#2 + this.renamedHelloService3 = helloService3; + } + private HelloService renamedHelloService2; + private DemoService renamedHelloService3; + @Test void testAop() throws Exception { @@ -150,7 +165,7 @@ void testAop() throws Exception { Assertions.assertNotNull(testBean.getDemoServiceFromParent()); Assertions.assertNotNull(testBean.getDemoService()); Assertions.assertNotNull(testBean.myDemoService); - Assertions.assertEquals(2, demoServicesMap.size()); + Assertions.assertEquals(3, demoServicesMap.size()); Assertions.assertNotNull(context.getBean("demoServiceImpl")); Assertions.assertNotNull(context.getBean("myDemoService")); @@ -189,12 +204,13 @@ void testGetInjectedFieldReferenceBeanMap() { Map> referenceBeanMap = beanPostProcessor.getInjectedFieldReferenceBeanMap(); - Assertions.assertEquals(4, referenceBeanMap.size()); + Assertions.assertEquals(5, referenceBeanMap.size()); Map checkingFieldNames = new HashMap<>(); checkingFieldNames.put("private org.apache.dubbo.config.spring.api.HelloService org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessorTest$MyConfiguration.helloService", 0); checkingFieldNames.put("private org.apache.dubbo.config.spring.api.HelloService org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessorTest.helloService", 0); checkingFieldNames.put("private org.apache.dubbo.config.spring.api.HelloService org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessorTest.helloService2", 0); + checkingFieldNames.put("private org.apache.dubbo.config.spring.api.HelloService org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessorTest.helloService3", 0); checkingFieldNames.put("private org.apache.dubbo.config.spring.api.DemoService org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessorTest$ParentBean.demoServiceFromParent", 0); for (Map.Entry> entry : referenceBeanMap.entrySet()) { @@ -222,12 +238,13 @@ void testGetInjectedMethodReferenceBeanMap() { Map> referenceBeanMap = beanPostProcessor.getInjectedMethodReferenceBeanMap(); - Assertions.assertEquals(3, referenceBeanMap.size()); + Assertions.assertEquals(4, referenceBeanMap.size()); Map checkingMethodNames = new HashMap<>(); checkingMethodNames.put("setDemoServiceFromAncestor", 0); checkingMethodNames.put("setDemoService", 0); checkingMethodNames.put("setHelloService2", 0); + checkingMethodNames.put("setHelloService3", 0); for (Map.Entry> entry : referenceBeanMap.entrySet()) { @@ -252,7 +269,7 @@ void testReferenceBeansMethodAnnotation() { Collection referenceBeans = referenceBeanManager.getReferences(); - Assertions.assertEquals(4, referenceBeans.size()); + Assertions.assertEquals(5, referenceBeans.size()); for (ReferenceBean referenceBean : referenceBeans) { ReferenceConfig referenceConfig = referenceBean.getReferenceConfig(); @@ -350,4 +367,4 @@ public TestBean testBean() { } } -} \ No newline at end of file +}