lhotari commented on code in PR #23052:
URL: https://github.com/apache/pulsar/pull/23052#discussion_r1684153134
##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/BrokerService.java:
##########
@@ -625,6 +625,16 @@ public void start() throws Exception {
this.updateBrokerDispatchThrottlingMaxRate();
this.startCheckReplicationPolicies();
this.startDeduplicationSnapshotMonitor();
+ this.startClearInvalidateTopicNameCacheTask();
+ }
+
+ protected void startClearInvalidateTopicNameCacheTask() {
+ final int maxSecondsToClearTopicNameCache =
pulsar.getConfiguration().getMaxSecondsToClearTopicNameCache();
+ inactivityMonitor.scheduleAtFixedRate(
+ () ->
TopicName.clearIfReachedMaxCapacity(pulsar.getConfiguration().getTopicNameCacheCaxCapacity()),
+ maxSecondsToClearTopicNameCache,
+ maxSecondsToClearTopicNameCache,
+ TimeUnit.SECONDS);
Review Comment:
This solution doesn't seem effective when the cache size can go over limits.
I think it's better to use Caffeine cache with max size (as a LRU cache). You
could remove expiration when using Caffeine if that's expensive.
##########
pulsar-common/src/main/java/org/apache/pulsar/common/naming/NamespaceName.java:
##########
@@ -40,7 +40,7 @@ public class NamespaceName implements ServiceUnitId {
private final String localName;
private static final LoadingCache<String, NamespaceName> cache =
CacheBuilder.newBuilder().maximumSize(100000)
- .expireAfterAccess(30, TimeUnit.MINUTES).build(new
CacheLoader<String, NamespaceName>() {
+ .expireAfterWrite(30, TimeUnit.MINUTES).build(new
CacheLoader<String, NamespaceName>() {
Review Comment:
Why is this changed in this PR?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]