Skip to content

Commit

Permalink
[fix][broker] Fix memory leak if entry exists in cache (apache#16996)
Browse files Browse the repository at this point in the history
* feat:return true if entry exists in cache

* feat:return true if entry exists in cache

* chore: add comment

Co-authored-by: zhiyuanlei <zhiyuanlei@tencent.com>

Master Issue: apache#16979

### Motivation

PR apache#12258 made changes to OpAddEntry which causes a memory leak when the entry is already in the cache.

### Modifications

Modifications: Revert PR apache#12258 changes to OpAddEntry

### Documentation

- [x] `doc-not-needed`

(cherry picked from commit 374b3a1)
  • Loading branch information
leizhiyuan authored and nodece committed Sep 10, 2024
1 parent e85ff54 commit 23203a2
Showing 1 changed file with 2 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 23203a2

Please sign in to comment.