eolivelli commented on code in PR #17241:
URL: https://github.com/apache/pulsar/pull/17241#discussion_r956139849


##########
managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/cache/RangeEntryCacheImpl.java:
##########
@@ -256,6 +276,130 @@ public void asyncReadEntry(ReadHandle lh, long 
firstEntry, long lastEntry, boole
         }
     }
 
+    @AllArgsConstructor
+    private static final class ReadEntriesCallbackWithContext {
+        final ReadEntriesCallback callback;
+        final Object ctx;
+        final long startEntry;
+        final long endEntry;
+    }
+
+    private CachedPendingRead findBestCandidate(PendingReadKey key, 
Map<PendingReadKey, CachedPendingRead> ledgerCache,
+                                                AtomicBoolean created) {
+        synchronized (ledgerCache) {
+            CachedPendingRead existing = ledgerCache.get(key);
+            if (existing != null) {
+                return existing;
+            }
+            for (Map.Entry<PendingReadKey, CachedPendingRead> entry : 
ledgerCache.entrySet()) {
+                if (entry.getKey().includes(key)) {
+                    return entry.getValue();
+                }
+            }
+            created.set(true);
+            CachedPendingRead newRead = new CachedPendingRead(key, 
ledgerCache);
+            ledgerCache.put(key, newRead);
+            return newRead;
+        }
+    }
+
+    private class CachedPendingRead {
+        final PendingReadKey key;
+        final Map<PendingReadKey, CachedPendingRead> ledgerCache;
+        final List<ReadEntriesCallbackWithContext> callbacks = new 
ArrayList<>(1);
+        boolean completed = false;
+
+        public CachedPendingRead(PendingReadKey key,
+                                 Map<PendingReadKey, CachedPendingRead> 
ledgerCache) {
+            this.key = key;
+            this.ledgerCache = ledgerCache;
+        }
+
+        private List<EntryImpl> keepEntries(List<EntryImpl> list, long 
startEntry, long endEntry) {
+            List<EntryImpl> result = new ArrayList<>((int) (endEntry - 
startEntry));
+            for (EntryImpl entry : list) {
+                long entryId = entry.getEntryId();
+                if (startEntry <= entryId && entryId <= endEntry) {
+                    result.add(entry);
+                } else {
+                    entry.release();
+                }
+            }
+            return result;
+        }
+
+        public void attach(CompletableFuture<List<EntryImpl>> handle) {

Review Comment:
   it is done here
   
https://github.com/apache/pulsar/pull/17241/files#diff-c55509e3ab1389d89a58fd564f2e318dbb95f50121ab33c729a7ca4a21d02ef1R340



-- 
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]

Reply via email to