mirror of https://github.com/apache/cloudstack.git
framework-config: improve configkey caching (#10513)
Using a simple hyphen as a delimiter for config cache key can lead to ambiguity if the “name” field itself contains hyphens. To address this, a Ternary object of configkey name, scope and scope ID is used as the config cache keys. Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
This commit is contained in:
parent
653b973840
commit
8df1161f14
|
|
@ -85,7 +85,7 @@ public class ConfigDepotImpl implements ConfigDepot, ConfigDepotAdmin {
|
||||||
List<ScopedConfigStorage> _scopedStorages;
|
List<ScopedConfigStorage> _scopedStorages;
|
||||||
Set<Configurable> _configured = Collections.synchronizedSet(new HashSet<Configurable>());
|
Set<Configurable> _configured = Collections.synchronizedSet(new HashSet<Configurable>());
|
||||||
Set<String> newConfigs = Collections.synchronizedSet(new HashSet<>());
|
Set<String> newConfigs = Collections.synchronizedSet(new HashSet<>());
|
||||||
LazyCache<String, String> configCache;
|
LazyCache<Ternary<String, ConfigKey.Scope, Long>, String> configCache;
|
||||||
|
|
||||||
private HashMap<String, Pair<String, ConfigKey<?>>> _allKeys = new HashMap<String, Pair<String, ConfigKey<?>>>(1007);
|
private HashMap<String, Pair<String, ConfigKey<?>>> _allKeys = new HashMap<String, Pair<String, ConfigKey<?>>>(1007);
|
||||||
|
|
||||||
|
|
@ -273,15 +273,10 @@ public class ConfigDepotImpl implements ConfigDepot, ConfigDepotAdmin {
|
||||||
return _configDao;
|
return _configDao;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getConfigStringValueInternal(String cacheKey) {
|
protected String getConfigStringValueInternal(Ternary<String, ConfigKey.Scope, Long> cacheKey) {
|
||||||
String[] parts = cacheKey.split("-");
|
String key = cacheKey.first();
|
||||||
String key = parts[0];
|
ConfigKey.Scope scope = cacheKey.second();
|
||||||
ConfigKey.Scope scope = ConfigKey.Scope.Global;
|
Long scopeId = cacheKey.third();
|
||||||
Long scopeId = null;
|
|
||||||
try {
|
|
||||||
scope = ConfigKey.Scope.valueOf(parts[1]);
|
|
||||||
scopeId = Long.valueOf(parts[2]);
|
|
||||||
} catch (IllegalArgumentException ignored) {}
|
|
||||||
if (!ConfigKey.Scope.Global.equals(scope) && scopeId != null) {
|
if (!ConfigKey.Scope.Global.equals(scope) && scopeId != null) {
|
||||||
ScopedConfigStorage scopedConfigStorage = null;
|
ScopedConfigStorage scopedConfigStorage = null;
|
||||||
for (ScopedConfigStorage storage : _scopedStorages) {
|
for (ScopedConfigStorage storage : _scopedStorages) {
|
||||||
|
|
@ -301,8 +296,8 @@ public class ConfigDepotImpl implements ConfigDepot, ConfigDepotAdmin {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getConfigCacheKey(String key, ConfigKey.Scope scope, Long scopeId) {
|
protected Ternary<String, ConfigKey.Scope, Long> getConfigCacheKey(String key, ConfigKey.Scope scope, Long scopeId) {
|
||||||
return String.format("%s-%s-%d", key, scope, (scopeId == null ? 0 : scopeId));
|
return new Ternary<>(key, scope, scopeId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -81,6 +81,12 @@ public class ConfigDepotImplTest {
|
||||||
runTestGetConfigStringValue("test", "value");
|
runTestGetConfigStringValue("test", "value");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetConfigStringValue_nameWithCharacters() {
|
||||||
|
runTestGetConfigStringValue("test.1-1", "value");
|
||||||
|
runTestGetConfigStringValue("test_1#2", "value");
|
||||||
|
}
|
||||||
|
|
||||||
private void runTestGetConfigStringValueExpiry(long wait, int configDBRetrieval) {
|
private void runTestGetConfigStringValueExpiry(long wait, int configDBRetrieval) {
|
||||||
String key = "test1";
|
String key = "test1";
|
||||||
String value = "expiry";
|
String value = "expiry";
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue