You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by cl...@apache.org on 2020/04/17 20:33:45 UTC
[activemq-artemis] 01/04: ARTEMIS-2720 optimize cache clearing
This is an automated email from the ASF dual-hosted git repository.
clebertsuconic pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git
commit c841b84b3e0e503aa0be34daad3b93496c991c1a
Author: Justin Bertram <jb...@apache.org>
AuthorDate: Thu Apr 16 14:12:22 2020 -0500
ARTEMIS-2720 optimize cache clearing
---
.../settings/impl/HierarchicalObjectRepository.java | 19 +++++++++++++++----
1 file changed, 15 insertions(+), 4 deletions(-)
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/settings/impl/HierarchicalObjectRepository.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/settings/impl/HierarchicalObjectRepository.java
index 3bfff0b..09ce29b 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/settings/impl/HierarchicalObjectRepository.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/settings/impl/HierarchicalObjectRepository.java
@@ -172,7 +172,12 @@ public class HierarchicalObjectRepository<T> implements HierarchicalRepository<T
lock.writeLock().lock();
try {
String modifiedMatch = matchModifier.modify(match);
- clearCache();
+ // an exact match (i.e. one without wildcards) won't impact any other matches so no need to clear the cache
+ if (usesWildcards(modifiedMatch)) {
+ clearCache();
+ } else if (modifiedMatch != null && cache.containsKey(modifiedMatch)) {
+ cache.remove(modifiedMatch);
+ }
if (immutableMatch) {
immutables.add(modifiedMatch);
@@ -190,6 +195,10 @@ public class HierarchicalObjectRepository<T> implements HierarchicalRepository<T
}
}
+ private boolean usesWildcards(String modifiedMatch) {
+ return modifiedMatch == null ? false : (modifiedMatch.contains(wildcardConfiguration.getAnyWordsString()) || modifiedMatch.contains(wildcardConfiguration.getSingleWordString()));
+ }
+
@Override
public int getCacheSize() {
return cache.size();
@@ -277,10 +286,12 @@ public class HierarchicalObjectRepository<T> implements HierarchicalRepository<T
logger.debug("Cannot remove match " + modMatch + " since it came from a main config");
} else {
/**
- * clear the cache before removing the match. This will force any thread at
- * {@link #getMatch(String)} to get the lock to recompute.
+ * Clear the cache before removing the match, but only if the match used wildcards. This
+ * will force any thread at {@link #getMatch(String)} to get the lock to recompute.
*/
- clearCache();
+ if (usesWildcards(modMatch)) {
+ clearCache();
+ }
matches.remove(modMatch);
onChange();
}