From 438519cb71ec544fa87899f08222b761129646fd Mon Sep 17 00:00:00 2001 From: huangjikun <72253502+xiaomiusa87@users.noreply.github.com> Date: Mon, 15 Aug 2022 09:44:50 +0800 Subject: [PATCH 1/6] fixed ServiceBeanNameBuilder same version/group conflict (#10454) (#10455) * fixed ServiceBeanNameBuilder same version/group conflict (#10454) * fixed ServiceBeanNameBuilder same version/group conflict (#10454) --- .../factory/annotation/ServiceBeanNameBuilder.java | 3 ++- .../annotation/ServiceAnnotationPostProcessorTest.java | 2 +- .../factory/annotation/ServiceBeanNameBuilderTest.java | 10 ++++++++++ .../DubboEndpointAnnotationAutoConfigurationTest.java | 2 +- .../DubboEndpointAutoConfigurationTest.java | 2 +- 5 files changed, 15 insertions(+), 4 deletions(-) diff --git a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/ServiceBeanNameBuilder.java b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/ServiceBeanNameBuilder.java index d80bc97454..6bdddc9ed8 100644 --- a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/ServiceBeanNameBuilder.java +++ b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/ServiceBeanNameBuilder.java @@ -95,8 +95,9 @@ public class ServiceBeanNameBuilder { } private static void append(StringBuilder builder, String value) { + builder.append(SEPARATOR); if (StringUtils.hasText(value)) { - builder.append(SEPARATOR).append(value); + builder.append(value); } } diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/ServiceAnnotationPostProcessorTest.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/ServiceAnnotationPostProcessorTest.java index aba4c12229..a4d26bfce5 100644 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/ServiceAnnotationPostProcessorTest.java +++ b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/ServiceAnnotationPostProcessorTest.java @@ -95,7 +95,7 @@ public class ServiceAnnotationPostProcessorTest { Assertions.assertEquals(3, serviceBeansMap.size()); - ServiceBean demoServiceBean = serviceBeansMap.get("ServiceBean:org.apache.dubbo.config.spring.api.DemoService:2.5.7"); + ServiceBean demoServiceBean = serviceBeansMap.get("ServiceBean:org.apache.dubbo.config.spring.api.DemoService:2.5.7:"); Assertions.assertNotNull(demoServiceBean.getMethods()); diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/ServiceBeanNameBuilderTest.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/ServiceBeanNameBuilderTest.java index 07601a3d74..5bbbeaf80c 100644 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/ServiceBeanNameBuilderTest.java +++ b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/ServiceBeanNameBuilderTest.java @@ -72,4 +72,14 @@ public class ServiceBeanNameBuilderTest { builder.build()); } + @Test + public void testServiceNameBuild() { + ServiceBeanNameBuilder vBuilder = ServiceBeanNameBuilder.create(INTERFACE_CLASS, environment); + String vBeanName = vBuilder.version("DUBBO").build(); + + ServiceBeanNameBuilder gBuilder = ServiceBeanNameBuilder.create(INTERFACE_CLASS, environment); + String gBeanName = gBuilder.group("DUBBO").build(); + + Assertions.assertNotEquals(vBeanName, gBeanName); + } } diff --git a/dubbo-spring-boot/dubbo-spring-boot-actuator/src/test/java/org/apache/dubbo/spring/boot/actuate/autoconfigure/DubboEndpointAnnotationAutoConfigurationTest.java b/dubbo-spring-boot/dubbo-spring-boot-actuator/src/test/java/org/apache/dubbo/spring/boot/actuate/autoconfigure/DubboEndpointAnnotationAutoConfigurationTest.java index b72d2cfef3..2268b9d3f3 100644 --- a/dubbo-spring-boot/dubbo-spring-boot-actuator/src/test/java/org/apache/dubbo/spring/boot/actuate/autoconfigure/DubboEndpointAnnotationAutoConfigurationTest.java +++ b/dubbo-spring-boot/dubbo-spring-boot-actuator/src/test/java/org/apache/dubbo/spring/boot/actuate/autoconfigure/DubboEndpointAnnotationAutoConfigurationTest.java @@ -179,7 +179,7 @@ public class DubboEndpointAnnotationAutoConfigurationTest { Assert.assertEquals(1, services.size()); - Map demoServiceMeta = services.get("ServiceBean:org.apache.dubbo.spring.boot.actuate.autoconfigure.DubboEndpointAnnotationAutoConfigurationTest$DemoService:1.0.0"); + Map demoServiceMeta = services.get("ServiceBean:org.apache.dubbo.spring.boot.actuate.autoconfigure.DubboEndpointAnnotationAutoConfigurationTest$DemoService:1.0.0:"); Assert.assertEquals("1.0.0", demoServiceMeta.get("version")); diff --git a/dubbo-spring-boot/dubbo-spring-boot-compatible/actuator/src/test/java/org/apache/dubbo/spring/boot/actuate/autoconfigure/DubboEndpointAutoConfigurationTest.java b/dubbo-spring-boot/dubbo-spring-boot-compatible/actuator/src/test/java/org/apache/dubbo/spring/boot/actuate/autoconfigure/DubboEndpointAutoConfigurationTest.java index c4d62da487..e22741b872 100644 --- a/dubbo-spring-boot/dubbo-spring-boot-compatible/actuator/src/test/java/org/apache/dubbo/spring/boot/actuate/autoconfigure/DubboEndpointAutoConfigurationTest.java +++ b/dubbo-spring-boot/dubbo-spring-boot-compatible/actuator/src/test/java/org/apache/dubbo/spring/boot/actuate/autoconfigure/DubboEndpointAutoConfigurationTest.java @@ -166,7 +166,7 @@ public class DubboEndpointAutoConfigurationTest { Assert.assertEquals(1, services.size()); - Map demoServiceMeta = services.get("ServiceBean:org.apache.dubbo.spring.boot.actuate.autoconfigure.DubboEndpointAutoConfigurationTest$DemoService:1.0.0"); + Map demoServiceMeta = services.get("ServiceBean:org.apache.dubbo.spring.boot.actuate.autoconfigure.DubboEndpointAutoConfigurationTest$DemoService:1.0.0:"); Assert.assertEquals("1.0.0", demoServiceMeta.get("version")); From 6b095f1c68b546c9f0ce72dd91b9c1d2792c60be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=81=BC=E5=8D=8E?= <43363120+BurningCN@users.noreply.github.com> Date: Mon, 15 Aug 2022 09:45:35 +0800 Subject: [PATCH 2/6] Fix npe (#10457) --- .../support/zookeeper/ZookeeperDynamicConfiguration.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dubbo-configcenter/dubbo-configcenter-zookeeper/src/main/java/org/apache/dubbo/configcenter/support/zookeeper/ZookeeperDynamicConfiguration.java b/dubbo-configcenter/dubbo-configcenter-zookeeper/src/main/java/org/apache/dubbo/configcenter/support/zookeeper/ZookeeperDynamicConfiguration.java index b427709dc8..17daabb7b6 100644 --- a/dubbo-configcenter/dubbo-configcenter-zookeeper/src/main/java/org/apache/dubbo/configcenter/support/zookeeper/ZookeeperDynamicConfiguration.java +++ b/dubbo-configcenter/dubbo-configcenter-zookeeper/src/main/java/org/apache/dubbo/configcenter/support/zookeeper/ZookeeperDynamicConfiguration.java @@ -146,7 +146,7 @@ public class ZookeeperDynamicConfiguration extends TreePathDynamicConfiguration @Override protected void doRemoveListener(String pathKey, ConfigurationListener listener) { ZookeeperDataListener zookeeperDataListener = cacheListener.removeListener(pathKey, listener); - if (CollectionUtils.isEmpty(zookeeperDataListener.getListeners())) { + if (zookeeperDataListener != null && CollectionUtils.isEmpty(zookeeperDataListener.getListeners())) { zkClient.removeDataListener(pathKey, zookeeperDataListener); } } From 9b6c463598474e40bf0aec89e9a1c38ae14f83dd Mon Sep 17 00:00:00 2001 From: yshuoo <751308615@qq.com> Date: Mon, 15 Aug 2022 09:58:56 +0800 Subject: [PATCH 3/6] Up dev issue#10388 (#10414) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * issue#10388 * issue#10388 * 格式化 * 格式化 * 回退对readme的修改 * change to queue Co-authored-by: keshi.ys --- .../dubbo/common/concurrent/AbortPolicy.java | 32 ++++++++++ .../concurrent/DiscardOldestPolicy.java | 31 +++++++++ .../common/concurrent/DiscardPolicy.java | 31 +++++++++ .../common/concurrent/RejectException.java | 64 +++++++++++++++++++ .../dubbo/common/concurrent/Rejector.java | 43 +++++++++++++ .../MemorySafeLinkedBlockingQueue.java | 31 ++++++++- .../MemorySafeLinkedBlockingQueueTest.java | 11 ++++ 7 files changed, 241 insertions(+), 2 deletions(-) create mode 100644 dubbo-common/src/main/java/org/apache/dubbo/common/concurrent/AbortPolicy.java create mode 100644 dubbo-common/src/main/java/org/apache/dubbo/common/concurrent/DiscardOldestPolicy.java create mode 100644 dubbo-common/src/main/java/org/apache/dubbo/common/concurrent/DiscardPolicy.java create mode 100644 dubbo-common/src/main/java/org/apache/dubbo/common/concurrent/RejectException.java create mode 100644 dubbo-common/src/main/java/org/apache/dubbo/common/concurrent/Rejector.java diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/concurrent/AbortPolicy.java b/dubbo-common/src/main/java/org/apache/dubbo/common/concurrent/AbortPolicy.java new file mode 100644 index 0000000000..602ba6470d --- /dev/null +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/concurrent/AbortPolicy.java @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.dubbo.common.concurrent; + +import java.util.Queue; + +/** + * A handler for rejected element that throws a {@code RejectException}. + */ +public class AbortPolicy implements Rejector { + + @Override + public void reject(final E e, final Queue queue) { + throw new RejectException("no more memory can be used !"); + } + +} diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/concurrent/DiscardOldestPolicy.java b/dubbo-common/src/main/java/org/apache/dubbo/common/concurrent/DiscardOldestPolicy.java new file mode 100644 index 0000000000..26b5eaf391 --- /dev/null +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/concurrent/DiscardOldestPolicy.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.dubbo.common.concurrent; + +import java.util.Queue; + +/** + * A handler for rejected element that discards the oldest element. + */ +public class DiscardOldestPolicy implements Rejector { + + @Override + public void reject(final E e, final Queue queue) { + queue.poll(); + queue.offer(e); + } +} diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/concurrent/DiscardPolicy.java b/dubbo-common/src/main/java/org/apache/dubbo/common/concurrent/DiscardPolicy.java new file mode 100644 index 0000000000..4830b2aefd --- /dev/null +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/concurrent/DiscardPolicy.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.dubbo.common.concurrent; + + +import java.util.Queue; + +/** + * A handler for rejected element that silently discards the rejected element. + */ +public class DiscardPolicy implements Rejector { + + @Override + public void reject(final E e, final Queue queue) { + + } +} diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/concurrent/RejectException.java b/dubbo-common/src/main/java/org/apache/dubbo/common/concurrent/RejectException.java new file mode 100644 index 0000000000..1b7537b131 --- /dev/null +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/concurrent/RejectException.java @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.dubbo.common.concurrent; + +import org.apache.dubbo.common.threadpool.MemorySafeLinkedBlockingQueue; + +/** + * Exception thrown by an {@link MemorySafeLinkedBlockingQueue} when a element cannot be accepted. + */ +public class RejectException extends RuntimeException { + + private static final long serialVersionUID = -3240015871717170195L; + + /** + * Constructs a {@code RejectException} with no detail message. The cause is not initialized, and may subsequently be initialized by a + * call to {@link #initCause(Throwable) initCause}. + */ + public RejectException() { + } + + /** + * Constructs a {@code RejectException} with the specified detail message. The cause is not initialized, and may subsequently be + * initialized by a call to {@link #initCause(Throwable) initCause}. + * + * @param message the detail message + */ + public RejectException(final String message) { + super(message); + } + + /** + * Constructs a {@code RejectException} with the specified detail message and cause. + * + * @param message the detail message + * @param cause the cause (which is saved for later retrieval by the {@link #getCause()} method) + */ + public RejectException(final String message, final Throwable cause) { + super(message, cause); + } + + /** + * Constructs a {@code RejectException} with the specified cause. The detail message is set to {@code (cause == null ? null : + * cause.toString())} (which typically contains the class and detail message of {@code cause}). + * + * @param cause the cause (which is saved for later retrieval by the {@link #getCause()} method) + */ + public RejectException(final Throwable cause) { + super(cause); + } +} diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/concurrent/Rejector.java b/dubbo-common/src/main/java/org/apache/dubbo/common/concurrent/Rejector.java new file mode 100644 index 0000000000..1967f43821 --- /dev/null +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/concurrent/Rejector.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.dubbo.common.concurrent; + +import java.util.Queue; + +/** + * RejectHandler, it works when you need to custom reject action. + * + * @see AbortPolicy + * @see DiscardPolicy + * @see DiscardOldestPolicy + */ +public interface Rejector { + + /** + * Method that may be invoked by a Queue when Queue has remained memory + * return true. This may occur when no more memory are available because their bounds would be exceeded. + * + *

In the absence of other alternatives, the method may throw an unchecked + * {@link RejectException}, which will be propagated to the caller. + * + * @param e the element requested to be added + * @param queue the queue attempting to add this element + * + * @throws RejectException if there is no more memory + */ + void reject(E e, Queue queue); +} diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/threadpool/MemorySafeLinkedBlockingQueue.java b/dubbo-common/src/main/java/org/apache/dubbo/common/threadpool/MemorySafeLinkedBlockingQueue.java index aae67b618c..3c1ae2482c 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/threadpool/MemorySafeLinkedBlockingQueue.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/threadpool/MemorySafeLinkedBlockingQueue.java @@ -17,6 +17,9 @@ package org.apache.dubbo.common.threadpool; +import org.apache.dubbo.common.concurrent.DiscardPolicy; +import org.apache.dubbo.common.concurrent.Rejector; + import java.util.Collection; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.TimeUnit; @@ -36,6 +39,8 @@ public class MemorySafeLinkedBlockingQueue extends LinkedBlockingQueue { private int maxFreeMemory; + private Rejector rejector; + public MemorySafeLinkedBlockingQueue() { this(THE_256_MB); } @@ -43,12 +48,16 @@ public class MemorySafeLinkedBlockingQueue extends LinkedBlockingQueue { public MemorySafeLinkedBlockingQueue(final int maxFreeMemory) { super(Integer.MAX_VALUE); this.maxFreeMemory = maxFreeMemory; + //default as DiscardPolicy to ensure compatibility with the old version + this.rejector = new DiscardPolicy<>(); } public MemorySafeLinkedBlockingQueue(final Collection c, final int maxFreeMemory) { super(c); this.maxFreeMemory = maxFreeMemory; + //default as DiscardPolicy to ensure compatibility with the old version + this.rejector = new DiscardPolicy<>(); } /** @@ -69,6 +78,15 @@ public class MemorySafeLinkedBlockingQueue extends LinkedBlockingQueue { return maxFreeMemory; } + /** + * set the rejector. + * + * @param rejector the rejector + */ + public void setRejector(final Rejector rejector) { + this.rejector = rejector; + } + /** * determine if there is any remaining free memory. * @@ -83,15 +101,24 @@ public class MemorySafeLinkedBlockingQueue extends LinkedBlockingQueue { if (hasRemainedMemory()) { super.put(e); } + rejector.reject(e, this); } @Override public boolean offer(final E e, final long timeout, final TimeUnit unit) throws InterruptedException { - return hasRemainedMemory() && super.offer(e, timeout, unit); + if (!hasRemainedMemory()) { + rejector.reject(e, this); + return false; + } + return super.offer(e, timeout, unit); } @Override public boolean offer(final E e) { - return hasRemainedMemory() && super.offer(e); + if (!hasRemainedMemory()) { + rejector.reject(e, this); + return false; + } + return super.offer(e); } } diff --git a/dubbo-common/src/test/java/org/apache/dubbo/common/threadpool/MemorySafeLinkedBlockingQueueTest.java b/dubbo-common/src/test/java/org/apache/dubbo/common/threadpool/MemorySafeLinkedBlockingQueueTest.java index dd7f095b88..cb8b31b021 100644 --- a/dubbo-common/src/test/java/org/apache/dubbo/common/threadpool/MemorySafeLinkedBlockingQueueTest.java +++ b/dubbo-common/src/test/java/org/apache/dubbo/common/threadpool/MemorySafeLinkedBlockingQueueTest.java @@ -18,12 +18,15 @@ package org.apache.dubbo.common.threadpool; import net.bytebuddy.agent.ByteBuddyAgent; +import org.apache.dubbo.common.concurrent.AbortPolicy; +import org.apache.dubbo.common.concurrent.RejectException; import org.junit.jupiter.api.Test; import java.lang.instrument.Instrumentation; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; +import static org.junit.jupiter.api.Assertions.assertThrows; public class MemorySafeLinkedBlockingQueueTest { @Test @@ -43,4 +46,12 @@ public class MemorySafeLinkedBlockingQueueTest { assertThat(queue.offer(() -> { }), is(true)); } + + @Test + public void testCustomReject() throws Exception { + MemorySafeLinkedBlockingQueue queue = new MemorySafeLinkedBlockingQueue<>(Integer.MAX_VALUE); + queue.setRejector(new AbortPolicy<>()); + assertThrows(RejectException.class, () -> queue.offer(() -> { + })); + } } From af041d321f50f1c6ceba693090d843dffab8ec95 Mon Sep 17 00:00:00 2001 From: jk-tonycui <57054315+jk-tonycui@users.noreply.github.com> Date: Mon, 15 Aug 2022 09:59:32 +0800 Subject: [PATCH 4/6] add default interval for retries of saving properties (#10412) --- .../dubbo/registry/support/AbstractRegistry.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistry.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistry.java index f72aa5877f..516a974945 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistry.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistry.java @@ -49,7 +49,8 @@ import java.util.Properties; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; -import java.util.concurrent.ExecutorService; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicReference; @@ -79,12 +80,15 @@ public abstract class AbstractRegistry implements Registry { private static final String URL_SPLIT = "\\s+"; // Max times to retry to save properties to local cache file private static final int MAX_RETRY_TIMES_SAVE_PROPERTIES = 3; + // Default interval in millisecond for saving properties to local cache file + private static final long DEFAULT_INTERVAL_SAVE_PROPERTIES = 500L; + // Log output protected final Logger logger = LoggerFactory.getLogger(getClass()); // Local disk cache, where the special key value.registries records the list of registry centers, and the others are the list of notified service providers private final Properties properties = new Properties(); // File cache timing writing - private final ExecutorService registryCacheExecutor; + private final ScheduledExecutorService registryCacheExecutor; private final AtomicLong lastCacheChanged = new AtomicLong(); private final AtomicInteger savePropertiesRetryTimes = new AtomicInteger(); private final Set registered = new ConcurrentHashSet<>(); @@ -104,7 +108,7 @@ public abstract class AbstractRegistry implements Registry { registryManager = url.getOrDefaultApplicationModel().getBeanFactory().getBean(RegistryManager.class); localCacheEnabled = url.getParameter(REGISTRY_LOCAL_FILE_CACHE_ENABLED, true); registryCacheExecutor = url.getOrDefaultFrameworkModel().getBeanFactory() - .getBean(FrameworkExecutorRepository.class).getSharedExecutor(); + .getBean(FrameworkExecutorRepository.class).getSharedScheduledExecutor(); if (localCacheEnabled) { // Start file save timer syncSaveFile = url.getParameter(REGISTRY_FILESAVE_SYNC_KEY, false); @@ -238,7 +242,7 @@ public abstract class AbstractRegistry implements Registry { savePropertiesRetryTimes.set(0); return; } else { - registryCacheExecutor.execute(() -> doSaveProperties(lastCacheChanged.incrementAndGet())); + registryCacheExecutor.schedule(() -> doSaveProperties(lastCacheChanged.incrementAndGet()), DEFAULT_INTERVAL_SAVE_PROPERTIES, TimeUnit.MILLISECONDS); } if (!(e instanceof OverlappingFileLockException)) { logger.warn("Failed to save registry cache file, will retry, cause: " + e.getMessage(), e); @@ -495,7 +499,7 @@ public abstract class AbstractRegistry implements Registry { if (syncSaveFile) { doSaveProperties(version); } else { - registryCacheExecutor.execute(() -> doSaveProperties(version)); + registryCacheExecutor.schedule(() -> doSaveProperties(version), DEFAULT_INTERVAL_SAVE_PROPERTIES, TimeUnit.MILLISECONDS); } } catch (Throwable t) { logger.warn(t.getMessage(), t); From 6822b2301c3d58d4d31e631f187e1d7965b6006d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=81=BC=E5=8D=8E?= <43363120+BurningCN@users.noreply.github.com> Date: Mon, 15 Aug 2022 10:04:03 +0800 Subject: [PATCH 5/6] Try to get it from the cache before generating the referenceKey (#10173) --- .../reference/ReferenceBeanManager.java | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/reference/ReferenceBeanManager.java b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/reference/ReferenceBeanManager.java index 64d2a1b7d9..d565a48d68 100644 --- a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/reference/ReferenceBeanManager.java +++ b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/reference/ReferenceBeanManager.java @@ -17,6 +17,7 @@ package org.apache.dubbo.config.spring.reference; import org.apache.dubbo.common.utils.Assert; +import org.apache.dubbo.common.utils.StringUtils; import org.apache.dubbo.config.ReferenceConfig; import org.apache.dubbo.config.spring.ReferenceBean; import org.apache.dubbo.config.spring.util.DubboBeanUtils; @@ -34,6 +35,7 @@ import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.concurrent.ConcurrentHashMap; @@ -67,8 +69,10 @@ public class ReferenceBeanManager implements ApplicationContextAware { " the BeanPostProcessor has not been loaded at this time, which may cause abnormalities in some components (such as seata): " + referenceBeanName + " = " + ReferenceBeanSupport.generateReferenceKey(referenceBean, applicationContext)); } - - String referenceKey = ReferenceBeanSupport.generateReferenceKey(referenceBean, applicationContext); + String referenceKey = getReferenceKeyByBeanName(referenceBeanName); + if (StringUtils.isEmpty(referenceKey)) { + referenceKey = ReferenceBeanSupport.generateReferenceKey(referenceBean, applicationContext); + } ReferenceBean oldReferenceBean = referenceBeanMap.get(referenceBeanName); if (oldReferenceBean != null) { if (referenceBean != oldReferenceBean) { @@ -88,6 +92,16 @@ public class ReferenceBeanManager implements ApplicationContextAware { } } + private String getReferenceKeyByBeanName(String referenceBeanName){ + Set>> entries = referenceKeyMap.entrySet(); + for (Map.Entry> entry : entries) { + if (entry.getValue().contains(referenceBeanName)) { + return entry.getKey(); + } + } + return null; + } + public void registerReferenceKeyAndBeanName(String referenceKey, String referenceBeanNameOrAlias) { List list = referenceKeyMap.computeIfAbsent(referenceKey, (key) -> new ArrayList<>()); if (!list.contains(referenceBeanNameOrAlias)) { @@ -148,7 +162,10 @@ public class ReferenceBeanManager implements ApplicationContextAware { // TOTO check same unique service name but difference reference key (means difference attributes). // reference key - String referenceKey = ReferenceBeanSupport.generateReferenceKey(referenceBean, applicationContext); + String referenceKey = getReferenceKeyByBeanName(referenceBean.getId()); + if (StringUtils.isEmpty(referenceKey)) { + referenceKey = ReferenceBeanSupport.generateReferenceKey(referenceBean, applicationContext); + } ReferenceConfig referenceConfig = referenceConfigMap.get(referenceKey); if (referenceConfig == null) { From c84b745bb196f51cee304fa80c6821db9ea2d93d Mon Sep 17 00:00:00 2001 From: Albumen Kevin Date: Mon, 15 Aug 2022 11:11:56 +0800 Subject: [PATCH 6/6] DisableCircularReferenceDetect for fastjson impl (#10447) --- .../java/org/apache/dubbo/common/json/impl/FastJsonImpl.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/json/impl/FastJsonImpl.java b/dubbo-common/src/main/java/org/apache/dubbo/common/json/impl/FastJsonImpl.java index fff944e8aa..e5b440c044 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/json/impl/FastJsonImpl.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/json/impl/FastJsonImpl.java @@ -18,6 +18,8 @@ package org.apache.dubbo.common.json.impl; import org.apache.dubbo.common.utils.ClassUtils; +import com.alibaba.fastjson.serializer.SerializerFeature; + import java.lang.reflect.Type; import java.util.List; @@ -45,6 +47,6 @@ public class FastJsonImpl extends AbstractJSONImpl { @Override public String toJson(Object obj) { - return com.alibaba.fastjson.JSON.toJSONString(obj); + return com.alibaba.fastjson.JSON.toJSONString(obj, SerializerFeature.DisableCircularReferenceDetect); } }