From 23203a26831189c36b8cf3f126943bfa9ce81877 Mon Sep 17 00:00:00 2001 From: Lei Zhiyuan Date: Wed, 10 Aug 2022 04:29:04 +0800 Subject: [PATCH] [fix][broker] Fix memory leak if entry exists in cache (#16996) * feat:return true if entry exists in cache * feat:return true if entry exists in cache * chore: add comment Co-authored-by: zhiyuanlei Master Issue: #16979 ### Motivation PR https://github.com/apache/pulsar/pull/12258 made changes to OpAddEntry which causes a memory leak when the entry is already in the cache. ### Modifications Modifications: Revert PR https://github.com/apache/pulsar/pull/12258 changes to OpAddEntry ### Documentation - [x] `doc-not-needed` (cherry picked from commit 374b3a18155cba33c4b4cfdb18c8119487be565e) --- .../org/apache/bookkeeper/mledger/impl/OpAddEntry.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/OpAddEntry.java b/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/OpAddEntry.java index c6beadde5a355..1b6c6e9617574 100644 --- a/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/OpAddEntry.java +++ b/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/OpAddEntry.java @@ -219,11 +219,8 @@ public void safeRun() { EntryImpl entry = EntryImpl.create(ledger.getId(), entryId, data); // EntryCache.insert: duplicates entry by allocating new entry and data. so, recycle entry after calling // insert - // Entry cache doesn't copy the data if entry already exist into the cache. - // Backlog read tries to add entry into cache which can try to add duplicate entry into cache. - if (ml.entryCache.insert(entry)) { - entry.release(); - } + ml.entryCache.insert(entry); + entry.release(); } PositionImpl lastEntry = PositionImpl.get(ledger.getId(), entryId);