Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/3.2' into issue-11760
Browse files Browse the repository at this point in the history
* origin/3.2: (25 commits)
  Bump bytebuddy.version from 1.14.1 to 1.14.2 (apache#11814)
  Dynamically generate native image config (apache#11795)
  Remove redundant synchronized (apache#11811)
  fix remove unused param (apache#11787)
  Bump bytebuddy.version from 1.14.0 to 1.14.1 (apache#11808)
  Reuse qos port for metrics (apache#11719)
  🐛 fix thread pool metrics be gc recycle problem (apache#11793)
  Bump protobuf-java from 3.22.0 to 3.22.2 (apache#11802)
  Bump spring-security-bom from 5.8.1 to 5.8.2 (apache#11801)
  Bump byte-buddy from 1.14.0 to 1.14.1 (apache#11804)
  Cert npe bug fix (apache#11800)
  Fix uts
  Fix lock acquire blocked
  Fix hessian list
  Fix metrics publisher NPE
  Fix ut
  Fix bug apache#11767 (apache#11781)
  Fix uts
  Sync when destroy (apache#11783)
  Fix recreate client after destroy (apache#11780)
  ...
  • Loading branch information
mytang0 committed Mar 14, 2023
2 parents 84df59b + eeab34e commit c06b5fd
Show file tree
Hide file tree
Showing 88 changed files with 2,616 additions and 3,677 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,5 @@ dubbo-demo/dubbo-demo-triple/build/*
# global registry center
.tmp

.git.exec.error

3 changes: 3 additions & 0 deletions .licenserc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ header:
- 'dubbo-maven-plugin/src/main/java/org/apache/dubbo/maven/plugin/aot/MatchingGroupIdFilter.java'
- 'dubbo-maven-plugin/src/main/java/org/apache/dubbo/maven/plugin/aot/RunArguments.java'
- 'dubbo-maven-plugin/src/main/java/org/apache/dubbo/maven/plugin/aot/RunProcess.java'
- 'dubbo-native/src/main/java/org/apache/dubbo/aot/generate/BasicJsonWriter.java'
- 'dubbo-native/src/main/java/org/apache/dubbo/aot/generate/ExecutableMode.java'
- 'dubbo-native/src/main/java/org/apache/dubbo/aot/generate/MemberCategory.java'

comment: on-failure

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.apache.dubbo.common.utils.NetUtils;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.metrics.event.GlobalMetricsEventMulticaster;
import org.apache.dubbo.metrics.event.MetricsEvent;
import org.apache.dubbo.metrics.registry.event.RegistryEvent;
import org.apache.dubbo.rpc.Invocation;
import org.apache.dubbo.rpc.Invoker;
Expand Down Expand Up @@ -387,9 +388,15 @@ private void refreshInvokers(BitList<Invoker<T>> targetInvokers, Collection<Invo
invokersToRemove.removeAll(needToRemove);
}

private void publishMetricsEvent(MetricsEvent event) {
if (eventMulticaster != null) {
eventMulticaster.publishEvent(event);
}
}

@Override
public void addDisabledInvoker(Invoker<T> invoker) {
eventMulticaster.publishEvent(new RegistryEvent.MetricsDirectoryEvent(applicationModel, RegistryEvent.Type.D_DISABLE));
publishMetricsEvent(new RegistryEvent.MetricsDirectoryEvent(applicationModel, RegistryEvent.Type.D_DISABLE));
if (invokers.contains(invoker)) {
disabledInvokers.add(invoker);
removeValidInvoker(invoker);
Expand All @@ -399,7 +406,7 @@ public void addDisabledInvoker(Invoker<T> invoker) {

@Override
public void recoverDisabledInvoker(Invoker<T> invoker) {
eventMulticaster.publishEvent(new RegistryEvent.MetricsDirectoryEvent(applicationModel, RegistryEvent.Type.D_RECOVER_DISABLE));
publishMetricsEvent(new RegistryEvent.MetricsDirectoryEvent(applicationModel, RegistryEvent.Type.D_RECOVER_DISABLE));
if (disabledInvokers.remove(invoker)) {
try {
addValidInvoker(invoker);
Expand Down Expand Up @@ -463,7 +470,7 @@ protected void setInvokers(BitList<Invoker<T>> invokers) {
this.invokers = invokers;
refreshInvokerInternal();
this.invokersInitialized = true;
eventMulticaster.publishEvent(new RegistryEvent.MetricsDirectoryEvent(applicationModel, RegistryEvent.Type.D_CURRENT, invokers.size()));
publishMetricsEvent(new RegistryEvent.MetricsDirectoryEvent(applicationModel, RegistryEvent.Type.D_CURRENT, invokers.size()));
}

protected void destroyInvokers() {
Expand All @@ -474,14 +481,14 @@ protected void destroyInvokers() {
}

private boolean addValidInvoker(Invoker<T> invoker) {
eventMulticaster.publishEvent(new RegistryEvent.MetricsDirectoryEvent(applicationModel, RegistryEvent.Type.D_VALID));
publishMetricsEvent(new RegistryEvent.MetricsDirectoryEvent(applicationModel, RegistryEvent.Type.D_VALID));
synchronized (this.validInvokers) {
return this.validInvokers.add(invoker);
}
}

private boolean removeValidInvoker(Invoker<T> invoker) {
eventMulticaster.publishEvent(new RegistryEvent.MetricsDirectoryEvent(applicationModel, RegistryEvent.Type.D_UN_VALID));
publishMetricsEvent(new RegistryEvent.MetricsDirectoryEvent(applicationModel, RegistryEvent.Type.D_UN_VALID));
synchronized (this.validInvokers) {
return this.validInvokers.remove(invoker);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
* @param <E>
* @since 3.0
*/
public class BitList<E> extends AbstractList<E> {
public class BitList<E> extends AbstractList<E> implements Cloneable {
private final BitSet rootSet;
private volatile List<E> originList;
private final static BitList emptyList = new BitList(Collections.emptyList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ private static boolean addParam(String str, boolean isEncoded, int nameStart, in
String name = decodeComponent(str, nameStart, valueStart - 3, false, tempBuf);
String value;
if (valueStart >= valueEnd) {
value = name;
value = "";
} else {
value = decodeComponent(str, valueStart, valueEnd, false, tempBuf);
}
Expand All @@ -291,7 +291,7 @@ private static boolean addParam(String str, boolean isEncoded, int nameStart, in
String name = str.substring(nameStart, valueStart - 1);
String value;
if (valueStart >= valueEnd) {
value = name;
value = "";
} else {
value = str.substring(valueStart, valueEnd);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public class ScopeBeanFactory {
private final List<BeanInfo> registeredBeanInfos = new CopyOnWriteArrayList<>();
private InstantiationStrategy instantiationStrategy;
private final AtomicBoolean destroyed = new AtomicBoolean();
private List<Class<?>> registeredClasses = new ArrayList<>();

public ScopeBeanFactory(ScopeBeanFactory parent, ExtensionAccessor extensionAccessor) {
this.parent = parent;
Expand Down Expand Up @@ -131,6 +132,7 @@ public <T> T getOrRegisterBean(String name, Class<T> type) {
}
}
}
registeredClasses.add(type);
return bean;
}

Expand Down Expand Up @@ -281,4 +283,8 @@ public BeanInfo(String name, Object instance) {
this.instance = instance;
}
}

public List<Class<?>> getRegisteredClasses() {
return registeredClasses;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ public synchronized ExecutorService createExecutorIfAbsent(URL url) {
executor = createExecutor(url);
executors.put(executorCacheKey, executor);
}

dataStore.put(executorKey, executorCacheKey, executor);
return executor;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,5 +149,5 @@ public interface Constants {

String SERVER_THREAD_POOL_NAME = "DubboServerHandler";


String CLIENT_THREAD_POOL_NAME = "DubboClientHandler";
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.Lock;

/**
* {@link ExtensionLoader}, {@code DubboBootstrap} and this class are at present designed to be
Expand Down Expand Up @@ -344,6 +345,11 @@ public void setDeployer(ApplicationDeployer deployer) {
this.deployer = deployer;
}

@Override
protected Lock acquireDestroyLock() {
return frameworkModel.acquireDestroyLock();
}

// =============================== Deprecated Methods Start =======================================

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.stream.Collectors;

/**
Expand All @@ -48,7 +50,7 @@ public class FrameworkModel extends ScopeModel {
private static final AtomicLong index = new AtomicLong(1);

private static final Object globalLock = new Object();

private volatile static FrameworkModel defaultInstance;

private static final List<FrameworkModel> allInstances = new CopyOnWriteArrayList<>();
Expand All @@ -68,6 +70,8 @@ public class FrameworkModel extends ScopeModel {

private final ApplicationModel internalApplicationModel;

private final ReentrantLock destroyLock = new ReentrantLock();

/**
* Use {@link FrameworkModel#newModel()} to create a new model
*/
Expand Down Expand Up @@ -356,6 +360,12 @@ public FrameworkServiceRepository getServiceRepository() {
return serviceRepository;
}


@Override
protected Lock acquireDestroyLock() {
return destroyLock;
}

@Override
public Environment getModelEnvironment() {
throw new UnsupportedOperationException("Environment is inaccessible for FrameworkModel");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

import java.util.HashMap;
import java.util.Set;
import java.util.concurrent.locks.Lock;

/**
* Model of a service module
Expand Down Expand Up @@ -173,6 +174,11 @@ public void setDeployer(ModuleDeployer deployer) {
this.deployer = deployer;
}

@Override
protected Lock acquireDestroyLock() {
return getApplicationModel().getFrameworkModel().acquireDestroyLock();
}

/**
* for ut only
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.locks.Lock;

import static org.apache.dubbo.common.constants.LoggerCodeConstants.CONFIG_UNABLE_DESTROY_MODEL;

Expand Down Expand Up @@ -109,23 +110,31 @@ protected void initialize() {
}
}

protected abstract Lock acquireDestroyLock();

public void destroy() {
if (destroyed.compareAndSet(false, true)) {
try {
onDestroy();
HashSet<ClassLoader> copyOfClassLoaders = new HashSet<>(classLoaders);
for (ClassLoader classLoader : copyOfClassLoaders) {
removeClassLoader(classLoader);
}
if (beanFactory != null) {
beanFactory.destroy();
}
if (extensionDirector != null) {
extensionDirector.destroy();
Lock lock = acquireDestroyLock();
try {
lock.lock();
if (destroyed.compareAndSet(false, true)) {
try {
onDestroy();
HashSet<ClassLoader> copyOfClassLoaders = new HashSet<>(classLoaders);
for (ClassLoader classLoader : copyOfClassLoaders) {
removeClassLoader(classLoader);
}
if (beanFactory != null) {
beanFactory.destroy();
}
if (extensionDirector != null) {
extensionDirector.destroy();
}
} catch (Throwable t) {
LOGGER.error(CONFIG_UNABLE_DESTROY_MODEL, "", "", "Error happened when destroying ScopeModel.", t);
}
} catch (Throwable t) {
LOGGER.error(CONFIG_UNABLE_DESTROY_MODEL, "", "", "Error happened when destroying ScopeModel.", t);
}
} finally {
lock.unlock();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,4 @@ java.util.UUID
java.util.WeakHashMap
org.apache.dubbo
com.alibaba.dubbo
com.alibaba.com.caucho.hessian.io.java8
com.alibaba.com.caucho.hessian.io
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class URLStrParserTest {
testCases.add("file:/path/to/file.txt");
testCases.add("dubbo://fe80:0:0:0:894:aeec:f37d:23e1%en0/path?abc=abc");
testCases.add("dubbo://[fe80:0:0:0:894:aeec:f37d:23e1]:20880/path?abc=abc");
testCases.add("nacos://192.168.1.1:8848?username=&password=");

errorDecodedCases.add("dubbo:192.168.1.1");
errorDecodedCases.add("://192.168.1.1");
Expand Down Expand Up @@ -80,4 +81,4 @@ void testDecoded() {
});
}

}
}
10 changes: 5 additions & 5 deletions dubbo-common/src/test/java/org/apache/dubbo/common/URLTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ void test_valueOf_WithProtocolHost() throws Exception {
assertEquals(3, url.getParameters().size());
assertEquals("1.0.0", url.getVersion());
assertEquals("morgan", url.getParameter("application"));
assertEquals("noValue", url.getParameter("noValue"));
assertEquals("", url.getParameter("noValue"));
}

// TODO Do not want to use spaces? See: DUBBO-502, URL class handles special conventions for special characters.
Expand All @@ -325,10 +325,10 @@ void test_noValueKey() throws Exception {
URL url = URL.valueOf("http://1.2.3.4:8080/path?k0=&k1=v1");

assertURLStrDecoder(url);
assertTrue(url.hasParameter("k0"));
assertFalse(url.hasParameter("k0"));

// If a Key has no corresponding Value, then the Key also used as the Value.
assertEquals("k0", url.getParameter("k0"));
// If a Key has no corresponding Value, then empty string used as the Value.
assertEquals("", url.getParameter("k0"));
}

@Test
Expand Down Expand Up @@ -1047,7 +1047,7 @@ void testParameterContainPound() {
@Test
void test_valueOfHasNameWithoutValue() throws Exception {
URL url = URL.valueOf("dubbo://admin:hello1234@10.20.130.230:20880/context/path?version=1.0.0&application=morgan&noValue");
Assertions.assertEquals("noValue", url.getParameter("noValue"));
Assertions.assertEquals("", url.getParameter("noValue"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.util.concurrent.locks.Lock;

/**
* {@link ScopeModelUtil}
*/
Expand Down Expand Up @@ -109,6 +111,11 @@ protected void onDestroy() {
public Environment getModelEnvironment() {
return null;
}

@Override
protected Lock acquireDestroyLock() {
return null;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,7 @@ public T get() {
// ensure start module, compatible with old api usage
getScopeModel().getDeployer().start();

synchronized (this) {
if (ref == null) {
init();
}
}
init();
}

return ref;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ private void initMetricsReporter() {
MetricsReporterFactory metricsReporterFactory = getExtensionLoader(MetricsReporterFactory.class).getAdaptiveExtension();
MetricsReporter metricsReporter = metricsReporterFactory.createMetricsReporter(metricsConfig.toUrl());
metricsReporter.init();
applicationModel.getBeanFactory().registerBean(metricsReporter);
}
}
}
Expand Down Expand Up @@ -1088,6 +1089,7 @@ private void onStarted() {
return;
}
setStarted();
startMetricsCollector();
if (logger.isInfoEnabled()) {
logger.info(getIdentifier() + " is ready.");
}
Expand All @@ -1105,6 +1107,11 @@ private void onStarted() {
}
}

private void startMetricsCollector(){
DefaultMetricsCollector collector = applicationModel.getBeanFactory().getBean(DefaultMetricsCollector.class);
collector.registryDefaultSample();
}

private void completeStartFuture(boolean success) {
if (startFuture != null) {
startFuture.complete(success);
Expand Down
Loading

0 comments on commit c06b5fd

Please sign in to comment.