Skip to content

Commit

Permalink
Merge branch 'refs/heads/3.3' into feat/remove_unused_plugin
Browse files Browse the repository at this point in the history
# Conflicts:
#	pom.xml
  • Loading branch information
CrazyHZM committed Feb 7, 2025
2 parents 0b1bae5 + 49ede4f commit 579ede9
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,10 @@ public final <T extends AbstractConfig> T addConfig(AbstractConfig config) {
config.setScopeModel(scopeModel);
}

Class<? extends AbstractConfig> targetConfigType = getTargetConfigType(config.getClass());

Map<String, AbstractConfig> configsMap =
configsCache.computeIfAbsent(getTagName(config.getClass()), type -> new ConcurrentHashMap<>());
configsCache.computeIfAbsent(getTagName(targetConfigType), type -> new ConcurrentHashMap<>());

// fast check duplicated equivalent config before write lock
if (!(config instanceof ReferenceConfigBase || config instanceof ServiceConfigBase)) {
Expand All @@ -175,17 +177,21 @@ public final <T extends AbstractConfig> T addConfig(AbstractConfig config) {

// lock by config type
synchronized (configsMap) {
return (T) addIfAbsent(config, configsMap);
return (T) addIfAbsent(config, configsMap, targetConfigType);
}
}

protected boolean isSupportConfigType(Class<? extends AbstractConfig> type) {
return getTargetConfigType(type) != null;
}

protected Class<? extends AbstractConfig> getTargetConfigType(Class<? extends AbstractConfig> type) {
for (Class<? extends AbstractConfig> supportedConfigType : supportedConfigTypes) {
if (supportedConfigType.isAssignableFrom(type)) {
return true;
return supportedConfigType;
}
}
return false;
return null;
}

/**
Expand All @@ -196,7 +202,9 @@ protected boolean isSupportConfigType(Class<? extends AbstractConfig> type) {
* @return the existing equivalent config or the new adding config
* @throws IllegalStateException
*/
private <C extends AbstractConfig> C addIfAbsent(C config, Map<String, C> configsMap) throws IllegalStateException {
private <C extends AbstractConfig> C addIfAbsent(
C config, Map<String, C> configsMap, Class<? extends AbstractConfig> targetConfigType)
throws IllegalStateException {

if (config == null || configsMap == null) {
return config;
Expand All @@ -218,7 +226,7 @@ private <C extends AbstractConfig> C addIfAbsent(C config, Map<String, C> config

C existedConfig = configsMap.get(key);
if (existedConfig != null && !isEquals(existedConfig, config)) {
String type = config.getClass().getSimpleName();
String type = targetConfigType.getSimpleName();
logger.warn(
COMMON_UNEXPECTED_EXCEPTION,
"",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,21 @@ void testAddConfig() {
assertFalse(moduleConfigManager.getProviders().isEmpty());
}

@Test
void testAddCustomConfig() {
configManager.addConfig(new CustomRegistryConfig("CustomConfigManagerTest"));

assertTrue(configManager.getRegistry("CustomConfigManagerTest").isPresent());
}

static class CustomRegistryConfig extends RegistryConfig {

CustomRegistryConfig(String id) {
super();
this.setId(id);
}
}

@Test
void testRefreshAll() {
configManager.refreshAll();
Expand Down
2 changes: 1 addition & 1 deletion dubbo-demo/dubbo-demo-spring-boot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<skip_maven_deploy>true</skip_maven_deploy>
<spring-boot.version>2.7.18</spring-boot.version>
<spring-boot-maven-plugin.version>2.7.18</spring-boot-maven-plugin.version>
<micrometer-core.version>1.14.2</micrometer-core.version>
<micrometer-core.version>1.14.3</micrometer-core.version>
</properties>

<dependencyManagement>
Expand Down
34 changes: 17 additions & 17 deletions dubbo-dependencies-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,26 +93,26 @@
<spring_boot_version>2.7.18</spring_boot_version>
<spring_security_version>5.8.16</spring_security_version>
<javassist_version>3.30.2-GA</javassist_version>
<byte-buddy_version>1.15.11</byte-buddy_version>
<byte-buddy_version>1.17.0</byte-buddy_version>
<netty_version>3.2.10.Final</netty_version>
<netty4_version>4.1.116.Final</netty4_version>
<netty4_version>4.1.117.Final</netty4_version>
<netty_http3_version>0.0.28.Final</netty_http3_version>
<httpclient_version>4.5.14</httpclient_version>
<httpcore_version>4.4.16</httpcore_version>
<fastjson_version>1.2.83_noneautotype</fastjson_version>
<fastjson2_version>2.0.53</fastjson2_version>
<fastjson2_version>2.0.54</fastjson2_version>
<zookeeper_version>3.7.2</zookeeper_version>
<curator_version>5.7.1</curator_version>
<curator_test_version>2.12.0</curator_test_version>
<hessian_version>4.0.66</hessian_version>
<protobuf-java_version>3.25.5</protobuf-java_version>
<protobuf-java_version>3.25.6</protobuf-java_version>
<jsr305_version>3.0.2</jsr305_version>
<javax_annotation-api_version>1.3.2</javax_annotation-api_version>
<servlet_version>3.1.0</servlet_version>
<jakarta_websocket_version>2.2.0</jakarta_websocket_version>
<jakarta_servlet_version>6.1.0</jakarta_servlet_version>
<jetty_version>9.4.56.v20240826</jetty_version>
<validation_new_version>3.1.0</validation_new_version>
<jetty_version>9.4.57.v20241219</jetty_version>
<validation_new_version>3.1.1</validation_new_version>
<validation_version>1.1.0.Final</validation_version>
<hibernate_validator_version>5.4.3.Final</hibernate_validator_version>
<hibernate_validator_new_version>7.0.5.Final</hibernate_validator_new_version>
Expand All @@ -122,25 +122,25 @@
<snakeyaml_version>2.3</snakeyaml_version>
<commons_lang3_version>3.17.0</commons_lang3_version>
<envoy_api_version>0.1.35</envoy_api_version>
<micrometer.version>1.13.6</micrometer.version>
<opentelemetry.version>1.45.0</opentelemetry.version>
<micrometer.version>1.14.3</micrometer.version>
<opentelemetry.version>1.46.0</opentelemetry.version>
<zipkin-reporter.version>3.4.3</zipkin-reporter.version>
<micrometer-tracing.version>1.4.1</micrometer-tracing.version>
<micrometer-tracing.version>1.4.2</micrometer-tracing.version>
<t_digest.version>3.3</t_digest.version>
<prometheus_client.version>0.16.0</prometheus_client.version>
<reactive.version>1.0.4</reactive.version>
<reactor.version>3.7.1</reactor.version>
<reactor.version>3.7.2</reactor.version>
<rxjava.version>2.2.21</rxjava.version>
<okhttp_version>3.14.9</okhttp_version>

<rs_api_version>2.1.1</rs_api_version>
<resteasy_version>3.15.6.Final</resteasy_version>
<codehaus-jackson_version>1.9.13</codehaus-jackson_version>
<tomcat_embed_version>8.5.100</tomcat_embed_version>
<nacos_version>2.4.3</nacos_version>
<nacos_version>2.5.0</nacos_version>
<sentinel.version>1.8.8</sentinel.version>
<seata.version>1.8.0</seata.version>
<grpc.version>1.69.0</grpc.version>
<grpc.version>1.70.0</grpc.version>
<grpc_contrib_verdion>0.8.1</grpc_contrib_verdion>
<jprotoc_version>1.2.2</jprotoc_version>
<mustache_version>0.9.14</mustache_version>
Expand All @@ -152,7 +152,7 @@
<!-- Fix the bug of log4j refer:https://github.com/apache/logging-log4j2/pull/608 -->
<log4j2_version>2.24.3</log4j2_version>
<commons_io_version>2.18.0</commons_io_version>
<commons-codec_version>1.17.1</commons-codec_version>
<commons-codec_version>1.18.0</commons-codec_version>
<groovy_version>4.0.24</groovy_version>

<!-- Test libs -->
Expand All @@ -168,18 +168,18 @@
<activation_version>1.2.0</activation_version>
<test_container_version>1.20.4</test_container_version>
<hessian_lite_version>4.0.3</hessian_lite_version>
<swagger_version>1.6.14</swagger_version>
<swagger_version>1.6.15</swagger_version>

<snappy_java_version>1.1.10.7</snappy_java_version>
<bouncycastle-bcprov_version>1.70</bouncycastle-bcprov_version>
<metrics_version>2.0.6</metrics_version>
<gson_version>2.11.0</gson_version>
<gson_version>2.12.1</gson_version>
<jackson_version>2.18.2</jackson_version>
<mortbay_jetty_version>6.1.26</mortbay_jetty_version>
<portlet_version>2.0</portlet_version>
<maven_flatten_version>1.6.0</maven_flatten_version>
<commons_compress_version>1.27.1</commons_compress_version>
<spotless-maven-plugin.version>2.43.0</spotless-maven-plugin.version>
<spotless-maven-plugin.version>2.44.2</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>
Expand All @@ -189,7 +189,7 @@
<byte-buddy.version>1.15.1</byte-buddy.version>
<prometheus-client.version>0.16.0</prometheus-client.version>

<revision>3.3.3-SNAPSHOT</revision>
<revision>3.3.4-SNAPSHOT</revision>
</properties>

<dependencyManagement>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static Invoker<?> getMockInvokerWithUrl() {

public static String getValueForKey(KeyValues keyValues, Object key)
throws NoSuchFieldException, IllegalAccessException {
Field f = KeyValues.class.getDeclaredField("keyValues");
Field f = KeyValues.class.getDeclaredField("sortedSet");
f.setAccessible(true);
KeyValue[] kv = (KeyValue[]) f.get(keyValues);
for (KeyValue keyValue : kv) {
Expand Down
6 changes: 3 additions & 3 deletions dubbo-plugin/dubbo-rest-openapi/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
<artifactId>dubbo-rest-openapi</artifactId>

<properties>
<swagger-annotations.version>2.2.27</swagger-annotations.version>
<swagger-ui.version>5.18.2</swagger-ui.version>
<swagger-annotations.version>2.2.28</swagger-annotations.version>
<swagger-ui.version>5.18.3</swagger-ui.version>
<redoc.version>2.2.0</redoc.version>
<webjars-locator.version>1.0.1</webjars-locator.version>
<therapi.version>0.15.0</therapi.version>
Expand All @@ -54,7 +54,7 @@
<dependency>
<groupId>org.webjars</groupId>
<artifactId>redoc</artifactId>
<version>2.1.5</version>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@
import org.apache.dubbo.registry.client.metadata.store.MetaCacheManager;
import org.apache.dubbo.rpc.model.ApplicationModel;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;

import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_METADATA_INFO_CACHE_EXPIRE;
import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_METADATA_INFO_CACHE_SIZE;
Expand All @@ -50,7 +51,6 @@
import static org.apache.dubbo.common.constants.CommonConstants.METADATA_INFO_CACHE_SIZE_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.REGISTRY_LOCAL_FILE_CACHE_ENABLED;
import static org.apache.dubbo.common.constants.CommonConstants.REMOTE_METADATA_STORAGE_TYPE;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.INTERNAL_ERROR;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.REGISTRY_FAILED_LOAD_METADATA;
import static org.apache.dubbo.common.constants.RegistryConstants.REGISTRY_CLUSTER_KEY;
import static org.apache.dubbo.metadata.RevisionResolver.EMPTY_REVISION;
Expand All @@ -70,7 +70,7 @@ public abstract class AbstractServiceDiscovery implements ServiceDiscovery {
protected volatile ServiceInstance serviceInstance;
protected volatile MetadataInfo metadataInfo;
protected final ConcurrentHashMap<String, MetadataInfoStat> metadataInfos = new ConcurrentHashMap<>();
protected final ScheduledFuture<?> refreshCacheFuture;
protected volatile ScheduledFuture<?> refreshCacheFuture;
protected MetadataReport metadataReport;
protected String metadataType;
protected final MetaCacheManager metaCacheManager;
Expand Down Expand Up @@ -110,36 +110,44 @@ private AbstractServiceDiscovery(ApplicationModel applicationModel, String servi
registryURL.getParameter(METADATA_INFO_CACHE_EXPIRE_KEY, DEFAULT_METADATA_INFO_CACHE_EXPIRE);
int metadataInfoCacheSize =
registryURL.getParameter(METADATA_INFO_CACHE_SIZE_KEY, DEFAULT_METADATA_INFO_CACHE_SIZE);
startRefreshCache(metadataInfoCacheExpireTime / 2, metadataInfoCacheSize, metadataInfoCacheExpireTime);
}

private void removeExpiredMetadataInfo(int metadataInfoCacheSize, int metadataInfoCacheExpireTime) {
Long nextTime = null;
// Cache cleanup is only required when the cache size exceeds the cache limit.
if (metadataInfos.size() > metadataInfoCacheSize) {
List<MetadataInfoStat> values = new ArrayList<>(metadataInfos.values());
// Place the earliest data at the front
values.sort(Comparator.comparingLong(MetadataInfoStat::getUpdateTime));
for (MetadataInfoStat v : values) {
long time = System.currentTimeMillis() - v.getUpdateTime();
if (time > metadataInfoCacheExpireTime) {
metadataInfos.remove(v.metadataInfo.getRevision(), v);
} else {
// Calculate how long it will take for the next task to start
nextTime = metadataInfoCacheExpireTime - time;
break;
}
}
}
// If there is no metadata to clean up this time, the next task will start within half of the cache expiration
// time.
startRefreshCache(
nextTime == null ? metadataInfoCacheExpireTime / 2 : nextTime,
metadataInfoCacheSize,
metadataInfoCacheExpireTime);
}

private void startRefreshCache(long nextTime, int metadataInfoCacheSize, int metadataInfoCacheExpireTime) {
this.refreshCacheFuture = applicationModel
.getFrameworkModel()
.getBeanFactory()
.getBean(FrameworkExecutorRepository.class)
.getSharedScheduledExecutor()
.scheduleAtFixedRate(
() -> {
try {
while (metadataInfos.size() > metadataInfoCacheSize) {
AtomicReference<String> oldestRevision = new AtomicReference<>();
AtomicReference<MetadataInfoStat> oldestStat = new AtomicReference<>();
metadataInfos.forEach((k, v) -> {
if (System.currentTimeMillis() - v.getUpdateTime() > metadataInfoCacheExpireTime
&& (oldestStat.get() == null
|| oldestStat.get().getUpdateTime() > v.getUpdateTime())) {
oldestRevision.set(k);
oldestStat.set(v);
}
});
if (oldestStat.get() != null) {
metadataInfos.remove(oldestRevision.get(), oldestStat.get());
}
}
} catch (Throwable t) {
logger.error(
INTERNAL_ERROR, "", "", "Error occurred when clean up metadata info cache.", t);
}
},
metadataInfoCacheExpireTime / 2,
metadataInfoCacheExpireTime / 2,
.schedule(
() -> removeExpiredMetadataInfo(metadataInfoCacheSize, metadataInfoCacheExpireTime),
nextTime,
TimeUnit.MILLISECONDS);
}

Expand Down
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,15 @@
<maven_gmavenplus_version>3.0.2</maven_gmavenplus_version>

<!-- For unify spring boot 3 version -->
<spring-6.version>6.2.1</spring-6.version>
<spring-boot-3.version>3.4.1</spring-boot-3.version>
<spring-6.version>6.2.2</spring-6.version>
<spring-boot-3.version>3.4.2</spring-boot-3.version>

<protobuf-protoc_version>3.22.3</protobuf-protoc_version>
<grpc_version>1.54.0</grpc_version>
<spotless-maven-plugin.version>2.43.0</spotless-maven-plugin.version>
<spotless-maven-plugin.version>2.44.2</spotless-maven-plugin.version>
<dubbo-shared-resources.version>1.0.0</dubbo-shared-resources.version>
<palantirJavaFormat.version>2.38.0</palantirJavaFormat.version>
<revision>3.3.3-SNAPSHOT</revision>
<revision>3.3.4-SNAPSHOT</revision>
</properties>

<dependencyManagement>
Expand Down

0 comments on commit 579ede9

Please sign in to comment.