This is an automated email from the ASF dual-hosted git repository.
xiaoyu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-shenyu.git
The following commit(s) were added to refs/heads/master by this push:
new 2f9627e12 [type:refactor] fix lost logic bug (#3428)
2f9627e12 is described below
commit 2f9627e125159cc619a69d08ee82f9d6be211018
Author: dragon-zhang <[email protected]>
AuthorDate: Tue May 24 11:35:50 2022 +0800
[type:refactor] fix lost logic bug (#3428)
---
.../apache/shenyu/plugin/base}/cache/MetaDataCache.java | 16 ++++++++++++----
.../plugin/divide/handler/DividePluginDataHandler.java | 9 +++++++++
shenyu-plugin/shenyu-plugin-global/pom.xml | 2 +-
.../plugin/global/DefaultShenyuContextBuilder.java | 2 +-
.../plugin/global/subsciber/MetaDataCacheSubscriber.java | 2 +-
.../shenyu/plugin/global/cache/MetaDataCacheTest.java | 1 +
.../global/subsciber/MetaDataCacheSubscriberTest.java | 2 +-
7 files changed, 26 insertions(+), 8 deletions(-)
diff --git
a/shenyu-plugin/shenyu-plugin-global/src/main/java/org/apache/shenyu/plugin/global/cache/MetaDataCache.java
b/shenyu-plugin/shenyu-plugin-base/src/main/java/org/apache/shenyu/plugin/base/cache/MetaDataCache.java
similarity index 92%
rename from
shenyu-plugin/shenyu-plugin-global/src/main/java/org/apache/shenyu/plugin/global/cache/MetaDataCache.java
rename to
shenyu-plugin/shenyu-plugin-base/src/main/java/org/apache/shenyu/plugin/base/cache/MetaDataCache.java
index 90948e017..6457903e7 100644
---
a/shenyu-plugin/shenyu-plugin-global/src/main/java/org/apache/shenyu/plugin/global/cache/MetaDataCache.java
+++
b/shenyu-plugin/shenyu-plugin-base/src/main/java/org/apache/shenyu/plugin/base/cache/MetaDataCache.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shenyu.plugin.global.cache;
+package org.apache.shenyu.plugin.base.cache;
import com.google.common.collect.Maps;
import org.apache.shenyu.common.cache.MemorySafeLRUMap;
@@ -34,6 +34,8 @@ import java.util.concurrent.ConcurrentSkipListSet;
*/
public final class MetaDataCache {
+ private static final String DIVIDE_CACHE_KEY = "";
+
private static final MetaData NULL = new MetaData();
private static final MetaDataCache INSTANCE = new MetaDataCache();
@@ -86,7 +88,7 @@ public final class MetaDataCache {
}
private void clean(final String key) {
- //only clean springCloud
+ // springCloud and divide are needs to be cleaned
Optional.ofNullable(MAPPING.get(key))
.ifPresent(paths -> {
for (String path : paths) {
@@ -95,6 +97,13 @@ public final class MetaDataCache {
});
}
+ /**
+ * clean cache for divide plugin.
+ */
+ public void clean() {
+ clean(DIVIDE_CACHE_KEY);
+ }
+
/**
* Obtain auth data meta data.
*
@@ -108,12 +117,11 @@ public final class MetaDataCache {
if (Objects.nonNull(exist)) {
return exist;
}
-
final String key = META_DATA_MAP.keySet()
.stream()
.filter(k -> PathMatchUtils.match(k, path))
.findFirst()
- .orElse("");
+ .orElse(DIVIDE_CACHE_KEY);
final MetaData value = META_DATA_MAP.get(key);
// The extreme case will lead to OOM, that's why use LRU
CACHE.put(path, Objects.isNull(value) ? NULL : value);
diff --git
a/shenyu-plugin/shenyu-plugin-divide/src/main/java/org/apache/shenyu/plugin/divide/handler/DividePluginDataHandler.java
b/shenyu-plugin/shenyu-plugin-divide/src/main/java/org/apache/shenyu/plugin/divide/handler/DividePluginDataHandler.java
index 39d190e9e..1deb7bbcf 100644
---
a/shenyu-plugin/shenyu-plugin-divide/src/main/java/org/apache/shenyu/plugin/divide/handler/DividePluginDataHandler.java
+++
b/shenyu-plugin/shenyu-plugin-divide/src/main/java/org/apache/shenyu/plugin/divide/handler/DividePluginDataHandler.java
@@ -27,6 +27,7 @@ import org.apache.shenyu.common.utils.GsonUtils;
import org.apache.shenyu.loadbalancer.cache.UpstreamCacheManager;
import org.apache.shenyu.loadbalancer.entity.Upstream;
import org.apache.shenyu.plugin.base.cache.CommonHandleCache;
+import org.apache.shenyu.plugin.base.cache.MetaDataCache;
import org.apache.shenyu.plugin.base.handler.PluginDataHandler;
import org.apache.shenyu.plugin.base.utils.BeanHolder;
import org.apache.shenyu.plugin.base.utils.CacheKeyUtils;
@@ -50,11 +51,15 @@ public class DividePluginDataHandler implements
PluginDataHandler {
return;
}
UpstreamCacheManager.getInstance().submit(selectorData.getId(),
convertUpstreamList(upstreamList));
+ // the update is also need to clean, but there is no way to
+ // distinguish between crate and update, so it is always clean
+ MetaDataCache.getInstance().clean();
}
@Override
public void removeSelector(final SelectorData selectorData) {
UpstreamCacheManager.getInstance().removeByKey(selectorData.getId());
+ MetaDataCache.getInstance().clean();
}
@Override
@@ -62,12 +67,16 @@ public class DividePluginDataHandler implements
PluginDataHandler {
Optional.ofNullable(ruleData.getHandle()).ifPresent(s -> {
DivideRuleHandle divideRuleHandle =
GsonUtils.getInstance().fromJson(s, DivideRuleHandle.class);
CACHED_HANDLE.get().cachedHandle(CacheKeyUtils.INST.getKey(ruleData),
divideRuleHandle);
+ // the update is also need to clean, but there is no way to
+ // distinguish between crate and update, so it is always clean
+ MetaDataCache.getInstance().clean();
});
}
@Override
public void removeRule(final RuleData ruleData) {
Optional.ofNullable(ruleData.getHandle()).ifPresent(s ->
CACHED_HANDLE.get().removeHandle(CacheKeyUtils.INST.getKey(ruleData)));
+ MetaDataCache.getInstance().clean();
}
@Override
diff --git a/shenyu-plugin/shenyu-plugin-global/pom.xml
b/shenyu-plugin/shenyu-plugin-global/pom.xml
index 686d32882..ec54d4a75 100644
--- a/shenyu-plugin/shenyu-plugin-global/pom.xml
+++ b/shenyu-plugin/shenyu-plugin-global/pom.xml
@@ -28,7 +28,7 @@
<dependencies>
<dependency>
<groupId>org.apache.shenyu</groupId>
- <artifactId>shenyu-plugin-api</artifactId>
+ <artifactId>shenyu-plugin-base</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
diff --git
a/shenyu-plugin/shenyu-plugin-global/src/main/java/org/apache/shenyu/plugin/global/DefaultShenyuContextBuilder.java
b/shenyu-plugin/shenyu-plugin-global/src/main/java/org/apache/shenyu/plugin/global/DefaultShenyuContextBuilder.java
index 8bd6a603d..50f139b15 100644
---
a/shenyu-plugin/shenyu-plugin-global/src/main/java/org/apache/shenyu/plugin/global/DefaultShenyuContextBuilder.java
+++
b/shenyu-plugin/shenyu-plugin-global/src/main/java/org/apache/shenyu/plugin/global/DefaultShenyuContextBuilder.java
@@ -25,7 +25,7 @@ import org.apache.shenyu.common.enums.RpcTypeEnum;
import org.apache.shenyu.plugin.api.context.ShenyuContext;
import org.apache.shenyu.plugin.api.context.ShenyuContextBuilder;
import org.apache.shenyu.plugin.api.context.ShenyuContextDecorator;
-import org.apache.shenyu.plugin.global.cache.MetaDataCache;
+import org.apache.shenyu.plugin.base.cache.MetaDataCache;
import org.springframework.http.HttpHeaders;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.web.server.ServerWebExchange;
diff --git
a/shenyu-plugin/shenyu-plugin-global/src/main/java/org/apache/shenyu/plugin/global/subsciber/MetaDataCacheSubscriber.java
b/shenyu-plugin/shenyu-plugin-global/src/main/java/org/apache/shenyu/plugin/global/subsciber/MetaDataCacheSubscriber.java
index e715c4ebf..7e94fde07 100644
---
a/shenyu-plugin/shenyu-plugin-global/src/main/java/org/apache/shenyu/plugin/global/subsciber/MetaDataCacheSubscriber.java
+++
b/shenyu-plugin/shenyu-plugin-global/src/main/java/org/apache/shenyu/plugin/global/subsciber/MetaDataCacheSubscriber.java
@@ -17,7 +17,7 @@
package org.apache.shenyu.plugin.global.subsciber;
-import org.apache.shenyu.plugin.global.cache.MetaDataCache;
+import org.apache.shenyu.plugin.base.cache.MetaDataCache;
import org.apache.shenyu.common.dto.MetaData;
import org.apache.shenyu.sync.data.api.MetaDataSubscriber;
diff --git
a/shenyu-plugin/shenyu-plugin-global/src/test/java/org/apache/shenyu/plugin/global/cache/MetaDataCacheTest.java
b/shenyu-plugin/shenyu-plugin-global/src/test/java/org/apache/shenyu/plugin/global/cache/MetaDataCacheTest.java
index b05d660d7..3f8bfde27 100644
---
a/shenyu-plugin/shenyu-plugin-global/src/test/java/org/apache/shenyu/plugin/global/cache/MetaDataCacheTest.java
+++
b/shenyu-plugin/shenyu-plugin-global/src/test/java/org/apache/shenyu/plugin/global/cache/MetaDataCacheTest.java
@@ -18,6 +18,7 @@
package org.apache.shenyu.plugin.global.cache;
import org.apache.shenyu.common.dto.MetaData;
+import org.apache.shenyu.plugin.base.cache.MetaDataCache;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
diff --git
a/shenyu-plugin/shenyu-plugin-global/src/test/java/org/apache/shenyu/plugin/global/subsciber/MetaDataCacheSubscriberTest.java
b/shenyu-plugin/shenyu-plugin-global/src/test/java/org/apache/shenyu/plugin/global/subsciber/MetaDataCacheSubscriberTest.java
index 22fdf432b..b3e03d5c2 100644
---
a/shenyu-plugin/shenyu-plugin-global/src/test/java/org/apache/shenyu/plugin/global/subsciber/MetaDataCacheSubscriberTest.java
+++
b/shenyu-plugin/shenyu-plugin-global/src/test/java/org/apache/shenyu/plugin/global/subsciber/MetaDataCacheSubscriberTest.java
@@ -18,7 +18,7 @@
package org.apache.shenyu.plugin.global.subsciber;
import org.apache.shenyu.common.dto.MetaData;
-import org.apache.shenyu.plugin.global.cache.MetaDataCache;
+import org.apache.shenyu.plugin.base.cache.MetaDataCache;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;