rdhabalia commented on a change in pull request #4066: Allow to configure the
managed ledger cache eviction frequency
URL: https://github.com/apache/pulsar/pull/4066#discussion_r278282876
##########
File path:
managed-ledger/src/main/java/org/apache/bookkeeper/mledger/util/RangeCache.java
##########
@@ -175,6 +177,36 @@ public Value get(Key key) {
return Pair.of(removedEntries, removedSize);
}
+ /**
+ *
+ * @param minSize
+ * @return a pair containing the number of entries evicted and their total
size
+ */
+ public Pair<Integer, Long> evictLEntriesBeforeTimestamp(long maxTimestamp) {
+ long removedSize = 0;
+ int removedEntries = 0;
+
+ while (true) {
+ Map.Entry<Key, Value> entry = entries.firstEntry();
+ if (entry == null ||
timestampExtractor.getTimestamp(entry.getValue()) > maxTimestamp) {
+ break;
+ }
+
+ entry = entries.pollFirstEntry();
+ if (entry == null) {
+ break;
+ }
+
+ Value value = entry.getValue();
+ ++removedEntries;
+ removedSize += weighter.getSize(value);
+ value.release();
+ }
+
+ size.addAndGet(-removedSize);
+ return Pair.of(removedEntries, removedSize);
Review comment:
seems like only `removedSize` is used by the caller. So, we can just return
`long` instead creating temporary Pair object for now. may be we can add back
when we really need size and entries both?
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services