Sentinel GatewayApiMatcherManager BUG: legacy API definitions will not be removed

fdx2calv  于 2021-11-29  发布在  Java
关注(0)|答案(3)|浏览(316)

Issue Description

Type: bug report or feature request

Describe what happened (or what feature you want)

网关流控API
当我添加一个API 定义之后,会同时更新GatewayApiMatcherManager
但是当我再将这个API 定义删除之后,也会更新GatewayApiMatcherManager,不过它只会添加不会删除。
具体代码如下:

static synchronized void loadApiDefinitions(/*@Valid*/ Set<ApiDefinition> definitions) {
        if (definitions == null || definitions.isEmpty()) {
            API_MATCHER_MAP.clear();
            return;
        }
        definitions.forEach(GatewayApiMatcherManager::addApiDefinition);
    }

我做了一些小的修改,就可以处理这个问题了。

// 去除final 修饰
    // private static final Map<String, WebExchangeApiMatcher> API_MATCHER_MAP = new ConcurrentHashMap<>();
    private static Map<String, WebExchangeApiMatcher> API_MATCHER_MAP = new ConcurrentHashMap<>();
// 修改loadApiDefinitions() 方法的逻辑
    static synchronized void loadApiDefinitions(/*@Valid*/ Set<ApiDefinition> definitions) {
        Map<String, WebExchangeApiMatcher> apiMatcherMap = new ConcurrentHashMap<>();
        for (ApiDefinition definition : definitions) {
            apiMatcherMap.put(definition.getApiName(), new WebExchangeApiMatcher(definition));
        }
        API_MATCHER_MAP = apiMatcherMap;
    }

Describe what you expected to happen

How to reproduce it (as minimally and precisely as possible)

Tell us your environment

我这边使用的依赖包以及版本

<dependency>
	<groupId>com.alibaba.csp</groupId>
	<artifactId>sentinel-spring-cloud-gateway-adapter</artifactId>
	<version>1.8.1</version>
</dependency>

Anything else we need to know?

3z6pesqy

3z6pesqy1#

Hi, thanks for reporting. Would you like to contribute a PR to fix it?

s2j5cfk0

s2j5cfk02#

没弄过,有没有博客讲这方面的呀。
一会儿我也去百度一下

相关问题