Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the issue of case sensitivity when matching keys with cache enabled #4820

Merged
merged 102 commits into from
Apr 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
102 commits
Select commit Hold shift + click to select a range
fe75b4d
add tech-support-qq-4.png
klboke May 16, 2019
99bf97a
Update README.md
klboke May 16, 2019
1579f41
Merge remote-tracking branch 'upstream/master'
klboke Nov 11, 2020
9f65eed
Merge remote-tracking branch 'upstream/master'
klboke Dec 9, 2020
d7d3fd9
Enhance the user experience in the scenario of submitting duplicate keys
klboke Dec 11, 2020
7329fab
Merge branch 'master' into master
nobodyiam Dec 12, 2020
5def448
Modify the key-value conflict exception prompt, adjust the code style
klboke Dec 12, 2020
6942564
Merge branch 'master' into master
nobodyiam Dec 12, 2020
0fc1f91
Merge remote-tracking branch 'upstream/master'
klboke Dec 19, 2020
61ad016
Merge remote-tracking branch 'origin/master'
klboke Dec 19, 2020
587ce33
rge remote-tracking branch 'upstream/master'
klboke Mar 1, 2021
9de6563
Merge remote-tracking branch 'upstream/master'
klboke Mar 8, 2021
9aab632
Merge remote-tracking branch 'upstream/master'
klboke Mar 25, 2021
050dd0a
Merge branch 'ctripcorp:master' into master
klboke May 10, 2021
5a64035
Merge branch 'master' of github.com:klboke/apollo
klboke May 10, 2021
0648fbd
Merge branch 'ctripcorp:master' into master
klboke May 19, 2021
35bd3a6
Merge branch 'master' of github.com:klboke/apollo
klboke May 19, 2021
bc8149b
Merge branch 'ctripcorp:master' into master
klboke Jun 8, 2021
e771bdd
Merge branch 'master' of github.com:klboke/apollo
klboke Jun 8, 2021
9a1ad83
Merge branch 'ctripcorp:master' into master
klboke Jun 25, 2021
3efef37
Merge branch 'master' of github.com:klboke/apollo
klboke Jun 25, 2021
1274281
Merge branch 'apolloconfig:master' into master
klboke Sep 1, 2021
a968932
Merge branch 'master' of github.com:klboke/apollo
klboke Sep 1, 2021
df8942c
Merge branch 'apolloconfig:master' into master
klboke Jan 7, 2022
f98175a
Merge branch 'master' of github.com:klboke/apollo
klboke Jan 7, 2022
710cdd6
Merge branch 'apolloconfig:master' into master
klboke Feb 18, 2022
3c162b6
Merge branch 'master' of github.com:klboke/apollo
klboke Feb 18, 2022
0101a3f
Merge branch 'apolloconfig:master' into master
klboke Jun 17, 2022
cc6f568
Merge branch 'master' of github.com:klboke/apollo
klboke Jun 17, 2022
21dd30c
Merge branch 'apolloconfig:master' into master
klboke Jun 21, 2022
c1eeb41
Merge branch 'master' of github.com:klboke/apollo
klboke Jun 21, 2022
e85d645
Merge branch 'apolloconfig:master' into master
klboke Jun 27, 2022
8b0056d
Merge branch 'master' of github.com:klboke/apollo
klboke Jun 27, 2022
347e07b
Merge branch 'apolloconfig:master' into master
klboke Jul 1, 2022
d8eb437
Merge branch 'master' of github.com:klboke/apollo
klboke Jul 1, 2022
19bae52
Merge branch 'apolloconfig:master' into master
klboke Jul 4, 2022
7e40fa1
Merge branch 'master' of github.com:klboke/apollo
klboke Jul 4, 2022
fbbb02d
Merge branch 'apolloconfig:master' into master
klboke Jul 6, 2022
19cee24
Merge branch 'master' of github.com:klboke/apollo
klboke Jul 6, 2022
91ba3b7
Merge branch 'apolloconfig:master' into master
klboke Jul 8, 2022
94ad542
Merge branch 'master' of github.com:klboke/apollo
klboke Jul 8, 2022
64e1b0b
Merge branch 'apolloconfig:master' into master
klboke Jul 19, 2022
36ce5e2
Merge branch 'master' of github.com:klboke/apollo
klboke Jul 19, 2022
c1364c2
Merge branch 'apolloconfig:master' into master
klboke Jul 22, 2022
76ed2ea
Merge branch 'master' of github.com:klboke/apollo
klboke Jul 22, 2022
db8cf3d
Merge branch 'apolloconfig:master' into master
klboke Jul 26, 2022
3e4616d
Merge branch 'master' of github.com:klboke/apollo
klboke Jul 26, 2022
47297cc
Merge branch 'apolloconfig:master' into master
klboke Jul 30, 2022
1c320e7
Merge branch 'apolloconfig:master' into master
klboke Aug 2, 2022
e723db5
Merge branch 'master' of github.com:klboke/apollo
klboke Aug 2, 2022
6be6a8b
Merge branch 'apolloconfig:master' into master
klboke Aug 8, 2022
014657d
Merge branch 'apolloconfig:master' into master
klboke Aug 12, 2022
370eec9
Merge branch 'master' of github.com:klboke/apollo
klboke Aug 12, 2022
dfa6c54
Merge branch 'apolloconfig:master' into master
klboke Sep 8, 2022
1a66d08
Merge branch 'master' of github.com:klboke/apollo
klboke Sep 8, 2022
cb2c22e
Merge branch 'apolloconfig:master' into master
klboke Sep 14, 2022
74af869
Merge branch 'master' of github.com:klboke/apollo
klboke Sep 14, 2022
a349f2e
Merge branch 'apolloconfig:master' into master
klboke Sep 22, 2022
7238296
Merge branch 'master' of github.com:klboke/apollo
klboke Sep 22, 2022
c38d00d
Merge branch 'apolloconfig:master' into master
klboke Oct 8, 2022
10cbbed
Merge branch 'master' of github.com:klboke/apollo
klboke Oct 8, 2022
601e17b
Merge branch 'apolloconfig:master' into master
klboke Oct 11, 2022
8fe2ce5
Merge branch 'master' of github.com:klboke/apollo
klboke Oct 11, 2022
04ea7ff
Merge branch 'apolloconfig:master' into master
klboke Dec 12, 2022
cfe577c
Merge branch 'master' of github.com:klboke/apollo
klboke Dec 12, 2022
4e9ba79
Merge branch 'apolloconfig:master' into master
klboke Dec 15, 2022
53d033a
Merge branch 'master' of github.com:klboke/apollo
klboke Dec 15, 2022
3789a6d
Merge branch 'apolloconfig:master' into master
klboke Jan 4, 2023
2a1f3bc
Merge branch 'master' of github.com:klboke/apollo
klboke Jan 10, 2023
0c7c63f
Merge branch 'apolloconfig:master' into master
klboke Mar 9, 2023
eaf3b3d
Merge branch 'master' of github.com:klboke/apollo
klboke Mar 9, 2023
312abaa
Merge branch 'apolloconfig:master' into master
klboke Mar 13, 2023
f7c95f2
Merge branch 'master' of github.com:klboke/apollo
klboke Mar 13, 2023
39cc719
Merge branch 'apolloconfig:master' into master
klboke Mar 15, 2023
e410062
Merge branch 'master' of github.com:klboke/apollo
klboke Mar 15, 2023
bb2bf94
Merge branch 'apolloconfig:master' into master
klboke Mar 17, 2023
95cf566
Merge branch 'master' of github.com:klboke/apollo
klboke Mar 17, 2023
0c10b9d
Merge branch 'apolloconfig:master' into master
klboke Mar 20, 2023
aa95cdd
Merge branch 'master' of github.com:klboke/apollo
klboke Mar 20, 2023
3441587
Merge branch 'apolloconfig:master' into master
klboke Mar 21, 2023
a09b174
Merge branch 'master' of github.com:klboke/apollo
klboke Mar 21, 2023
8419fca
Merge branch 'apolloconfig:master' into master
klboke Mar 23, 2023
d8d0664
Merge branch 'master' of github.com:klboke/apollo
klboke Mar 23, 2023
0af7aa2
Merge branch 'apolloconfig:master' into master
klboke Mar 27, 2023
b353db3
Merge branch 'master' of github.com:klboke/apollo
klboke Mar 27, 2023
8d05a82
fix(apollo-configService): Fix the issue of case sensitivity when mat…
klboke Mar 27, 2023
0ba755c
fix(apollo-configService): Adding test cases
klboke Mar 28, 2023
4ee5df8
fix(apollo-configService): Adding test cases
klboke Mar 28, 2023
3e89474
doc(CHANGES.md): Update CHANGES.md
klboke Mar 28, 2023
dfd3fce
test(apollo-biz): Optimize the test case
klboke Mar 30, 2023
c31c388
Merge branch 'apolloconfig:master' into master
klboke Mar 31, 2023
d652657
Merge branch 'master' of github.com:klboke/apollo
klboke Mar 31, 2023
d0e1f94
Merge branch 'apolloconfig:master' into master
klboke Apr 3, 2023
d95a534
Merge branch 'master' of github.com:klboke/apollo
klboke Apr 3, 2023
c5cae91
Merge branch 'apolloconfig:master' into master
klboke Apr 4, 2023
17714de
Merge branch 'master' of github.com:klboke/apollo
klboke Apr 4, 2023
c9ce610
fix(apollo-configService): Fix the issue of case sensitivity when mat…
klboke Mar 27, 2023
aad16cd
fix(apollo-configService): Adding test cases
klboke Mar 28, 2023
28d2d69
fix(apollo-configService): Adding test cases
klboke Mar 28, 2023
c7ac0f9
doc(CHANGES.md): Update CHANGES.md
klboke Mar 28, 2023
63fee52
test(apollo-biz): Optimize the test case
klboke Mar 30, 2023
c274197
Merge branch 'kl-cache' of github.com:klboke/apollo into kl-cache
klboke Apr 4, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Apollo 2.2.0
* [Fix the issue of the system permission management page retrieving non-existent users](https://github.com/apolloconfig/apollo/pull/4802)
* [Add release history cleaning function](https://github.com/apolloconfig/apollo/pull/4813)
* [[Multi-Database Support][pg] Make JdbcUserDetailsManager compat with postgre](https://github.com/apolloconfig/apollo/pull/4790)
* [Add a configuration config-service.cache.key.ignore-case to control whether the cache key is case-sensitive](https://github.com/apolloconfig/apollo/pull/4820)

------------------
All issues and pull requests are [here](https://github.com/apolloconfig/apollo/milestone/13?closed=1)
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,10 @@ public boolean isConfigServiceCacheEnabled() {
return getBooleanProperty("config-service.cache.enabled", false);
}

public boolean isConfigServiceCacheKeyIgnoreCase() {
return getBooleanProperty("config-service.cache.key.ignore-case", false);
}

int checkInt(int value, int min, int max, int defaultValue) {
if (value >= min && value <= max) {
return value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import org.springframework.test.util.ReflectionTestUtils;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;

/**
Expand Down Expand Up @@ -124,4 +126,11 @@ public void testCheckInt() throws Exception {
assertEquals(someValidValue, bizConfig.checkInt(someValidValue, Integer.MIN_VALUE, Integer.MAX_VALUE,
someDefaultValue));
}

@Test
public void testIsConfigServiceCacheKeyIgnoreCase() {
assertFalse(bizConfig.isConfigServiceCacheKeyIgnoreCase());
when(environment.getProperty("config-service.cache.key.ignore-case")).thenReturn("true");
assertTrue(bizConfig.isConfigServiceCacheKeyIgnoreCase());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public GrayReleaseRulesHolder grayReleaseRulesHolder() {
public ConfigService configService() {
if (bizConfig.isConfigServiceCacheEnabled()) {
return new ConfigServiceWithCache(releaseService, releaseMessageService,
grayReleaseRulesHolder());
grayReleaseRulesHolder(), bizConfig);
}
return new DefaultConfigService(releaseService, grayReleaseRulesHolder());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.ctrip.framework.apollo.configservice.service.config;

import com.ctrip.framework.apollo.biz.grayReleaseRule.GrayReleaseRulesHolder;
import com.ctrip.framework.apollo.biz.config.BizConfig;
import com.google.common.base.Strings;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
Expand Down Expand Up @@ -61,6 +62,7 @@ public class ConfigServiceWithCache extends AbstractConfigService {

private final ReleaseService releaseService;
private final ReleaseMessageService releaseMessageService;
private final BizConfig bizConfig;

private LoadingCache<String, ConfigCacheEntry> configCache;

Expand All @@ -70,10 +72,12 @@ public class ConfigServiceWithCache extends AbstractConfigService {

public ConfigServiceWithCache(final ReleaseService releaseService,
final ReleaseMessageService releaseMessageService,
final GrayReleaseRulesHolder grayReleaseRulesHolder) {
final GrayReleaseRulesHolder grayReleaseRulesHolder,
final BizConfig bizConfig) {
super(grayReleaseRulesHolder);
this.releaseService = releaseService;
this.releaseMessageService = releaseMessageService;
this.bizConfig = bizConfig;
nullConfigCacheEntry = new ConfigCacheEntry(ConfigConsts.NOTIFICATION_ID_PLACEHOLDER, null);
}

Expand Down Expand Up @@ -147,18 +151,23 @@ protected Release findActiveOne(long id, ApolloNotificationMessages clientMessag
@Override
protected Release findLatestActiveRelease(String appId, String clusterName, String namespaceName,
ApolloNotificationMessages clientMessages) {
String key = ReleaseMessageKeyGenerator.generate(appId, clusterName, namespaceName);
String messageKey = ReleaseMessageKeyGenerator.generate(appId, clusterName, namespaceName);
String cacheKey = messageKey;

Tracer.logEvent(TRACER_EVENT_CACHE_GET, key);
if (bizConfig.isConfigServiceCacheKeyIgnoreCase()) {
cacheKey = cacheKey.toLowerCase();
}

Tracer.logEvent(TRACER_EVENT_CACHE_GET, cacheKey);

ConfigCacheEntry cacheEntry = configCache.getUnchecked(key);
ConfigCacheEntry cacheEntry = configCache.getUnchecked(cacheKey);

//cache is out-dated
if (clientMessages != null && clientMessages.has(key) &&
clientMessages.get(key) > cacheEntry.getNotificationId()) {
if (clientMessages != null && clientMessages.has(messageKey) &&
clientMessages.get(messageKey) > cacheEntry.getNotificationId()) {
//invalidate the cache and try to load from db again
invalidate(key);
cacheEntry = configCache.getUnchecked(key);
invalidate(cacheKey);
cacheEntry = configCache.getUnchecked(cacheKey);
}

return cacheEntry.getRelease();
Expand All @@ -177,10 +186,14 @@ public void handleMessage(ReleaseMessage message, String channel) {
}

try {
invalidate(message.getMessage());
String messageKey = message.getMessage();
if (bizConfig.isConfigServiceCacheKeyIgnoreCase()) {
messageKey = messageKey.toLowerCase();
}
invalidate(messageKey);

//warm up the cache
configCache.getUnchecked(message.getMessage());
configCache.getUnchecked(messageKey);
} catch (Throwable ex) {
//ignore
}
Expand Down
Loading