From 2cc107d81a178d32480fc3d20923884e268c012e Mon Sep 17 00:00:00 2001 From: mattison chao Date: Thu, 4 Aug 2022 14:58:09 +0800 Subject: [PATCH] Fix read entires --- .../mledger/impl/cache/SharedEntryCacheImpl.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/cache/SharedEntryCacheImpl.java b/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/cache/SharedEntryCacheImpl.java index 9b08481bc7954..5db97f5ec17af 100644 --- a/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/cache/SharedEntryCacheImpl.java +++ b/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/cache/SharedEntryCacheImpl.java @@ -101,14 +101,19 @@ public void asyncReadEntry(ReadHandle lh, long firstEntry, long lastEntry, boole long totalCachedSize = entryCacheManager.getRange(ledgerId, firstEntry, lastEntry, cachedEntries); if (cachedEntries.size() == entriesToRead) { + final List entriesToReturn = Lists.newArrayListWithExpectedSize(entriesToRead); // All entries found in cache - entryCacheManager.getFactoryMBean().recordCacheHits(entriesToRead, totalCachedSize); + for (Entry entry : cachedEntries) { + entriesToReturn.add(EntryImpl.create((EntryImpl) entry)); + entry.release(); + } + // All entries found in cache + entryCacheManager.getFactoryMBean().recordCacheHits(entriesToReturn.size(), totalCachedSize); if (log.isDebugEnabled()) { log.debug("[{}] Ledger {} -- Found in cache entries: {}-{}", ml.getName(), ledgerId, firstEntry, lastEntry); } - - callback.readEntriesComplete(cachedEntries, ctx); + callback.readEntriesComplete(entriesToReturn, ctx); } else { if (!cachedEntries.isEmpty()) {