You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by "void-ptr974 (via GitHub)" <gi...@apache.org> on 2026/06/29 05:37:50 UTC

Re: [PR] [fix][broker] Remove lock contention in delayed delivery stats read paths [pulsar]

void-ptr974 commented on code in PR #25990:
URL: https://github.com/apache/pulsar/pull/25990#discussion_r3489466291


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/delayed/bucket/BucketDelayedDeliveryTracker.java:
##########
@@ -897,7 +904,7 @@ private CompletableFuture<Void> deleteBucketSnapshot(String ledgerName,
                     }
                     synchronized (this) {
                         snapshotSegmentLastIndexMap.entrySet().removeIf(entry -> entry.getValue() == bucket);
-                        immutableBuckets.remove(range);
+                        removeBucket(range);

Review Comment:
   This helper is not equivalent to the old removal logic. The old code used `RangeMap.remove(range)`, which can remove the covered range. The new helper removes from `asMapOfRanges()` by exact range key. Some callers pass a range produced by `subRangeMap(...)`, which may be only part of the real bucket range, so the bucket may remain in `immutableBuckets` after its snapshot is deleted and its message count is decremented.



##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/delayed/bucket/BucketDelayedDeliveryTracker.java:
##########
@@ -847,13 +858,9 @@ public synchronized boolean containsMessage(long ledgerId, long entryId) {
     }
 
     public Map<String, TopicMetricBean> genTopicMetricMap() {
-        stats.recordNumOfBuckets(immutableBuckets.asMapOfRanges().size() + 1);
+        stats.recordNumOfBuckets((int) (bucketsCount.get() + 1));
         stats.recordDelayedMessageIndexLoaded(this.sharedBucketPriorityQueue.size() + this.lastMutableBucket.size());

Review Comment:
   This method still reads mutable tracker state without the tracker lock. `sharedBucketPriorityQueue` and `lastMutableBucket` are updated under the tracker lock elsewhere, so reading their sizes here without the same lock can race with those updates. Since this is only for metrics, it would be simpler to collect these values under the tracker lock first.



-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org