You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by mm...@apache.org on 2022/06/04 16:26:38 UTC

[pulsar] branch master updated: remove topic -> namespace cache in LedgerOffloaderStatsImpl (#15869)

This is an automated email from the ASF dual-hosted git repository.

mmerli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar.git


The following commit(s) were added to refs/heads/master by this push:
     new 6fc5214d474 remove topic -> namespace cache in LedgerOffloaderStatsImpl (#15869)
6fc5214d474 is described below

commit 6fc5214d4740a5e9c9d4f1421c9b03eb580ef5d8
Author: Tao Jiuming <95...@users.noreply.github.com>
AuthorDate: Sun Jun 5 00:26:27 2022 +0800

    remove topic -> namespace cache in LedgerOffloaderStatsImpl (#15869)
---
 .../mledger/impl/LedgerOffloaderStatsImpl.java       | 20 +++++++-------------
 1 file changed, 7 insertions(+), 13 deletions(-)

diff --git a/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/LedgerOffloaderStatsImpl.java b/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/LedgerOffloaderStatsImpl.java
index 1c21cd56445..64b0d125162 100644
--- a/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/LedgerOffloaderStatsImpl.java
+++ b/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/LedgerOffloaderStatsImpl.java
@@ -59,7 +59,6 @@ public final class LedgerOffloaderStatsImpl implements LedgerOffloaderStats, Run
     private final Summary readOffloadDataLatency;
 
     private final Map<String, Long> topicAccess;
-    private final Map<String, String> topic2Namespace;
     private final Map<String, Pair<LongAdder, LongAdder>> offloadAndReadOffloadBytesMap;
 
     final AtomicBoolean closed = new AtomicBoolean(false);
@@ -73,7 +72,6 @@ public final class LedgerOffloaderStatsImpl implements LedgerOffloaderStats, Run
         }
 
         this.topicAccess = new ConcurrentHashMap<>();
-        this.topic2Namespace = new ConcurrentHashMap<>();
         this.offloadAndReadOffloadBytesMap = new ConcurrentHashMap<>();
 
         String[] labels = exposeTopicLevelMetrics
@@ -205,13 +203,11 @@ public final class LedgerOffloaderStatsImpl implements LedgerOffloaderStats, Run
     }
 
     private String getNamespace(String topic) {
-        return this.topic2Namespace.computeIfAbsent(topic, t -> {
-            try {
-                return TopicName.get(t).getNamespace();
-            } catch (IllegalArgumentException ex) {
-                return UNKNOWN;
-            }
-        });
+        try {
+            return TopicName.get(topic).getNamespace();
+        } catch (IllegalArgumentException ex) {
+            return UNKNOWN;
+        }
     }
 
     private void cleanExpiredTopicMetrics() {
@@ -223,7 +219,6 @@ public final class LedgerOffloaderStatsImpl implements LedgerOffloaderStats, Run
             long access = entry.getValue();
 
             if (now - access >= timeout) {
-                this.topic2Namespace.remove(topic);
                 this.offloadAndReadOffloadBytesMap.remove(topic);
                 String[] labelValues = this.labelValues(topic);
                 this.offloadError.remove(labelValues);
@@ -273,7 +268,6 @@ public final class LedgerOffloaderStatsImpl implements LedgerOffloaderStats, Run
             CollectorRegistry.defaultRegistry.unregister(this.readOffloadRate);
             CollectorRegistry.defaultRegistry.unregister(this.readOffloadIndexLatency);
             CollectorRegistry.defaultRegistry.unregister(this.readOffloadDataLatency);
-            this.topic2Namespace.clear();
             this.offloadAndReadOffloadBytesMap.clear();
         }
     }
@@ -285,7 +279,7 @@ public final class LedgerOffloaderStatsImpl implements LedgerOffloaderStats, Run
             return pair.getLeft().sum();
         }
 
-        String namespace = this.topic2Namespace.get(topic);
+        String namespace = this.getNamespace(topic);
         List<String> topics = this.offloadAndReadOffloadBytesMap.keySet().stream()
                 .filter(topicName -> topicName.contains(namespace)).collect(Collectors.toList());
 
@@ -321,7 +315,7 @@ public final class LedgerOffloaderStatsImpl implements LedgerOffloaderStats, Run
             return pair.getRight().sum();
         }
 
-        String namespace = this.topic2Namespace.get(topic);
+        String namespace = this.getNamespace(topic);
         List<String> topics = this.offloadAndReadOffloadBytesMap.keySet().stream()
                 .filter(topicName -> topicName.contains(namespace)).collect(Collectors.toList());