You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bookkeeper.apache.org by yo...@apache.org on 2023/12/06 07:43:01 UTC

(bookkeeper) 06/21: Fix keys leak in EntryLocationIndex when ledgersToDelete is empty (#3903)

This is an automated email from the ASF dual-hosted git repository.

yong pushed a commit to branch branch-4.15
in repository https://gitbox.apache.org/repos/asf/bookkeeper.git

commit fbc9c776587bc44c969a0aa058ff5aa460a20f63
Author: Hang Chen <ch...@apache.org>
AuthorDate: Mon Apr 10 09:23:27 2023 +0800

    Fix keys leak in EntryLocationIndex when ledgersToDelete is empty (#3903)
    
    ### Motivation
    In EntryLocationIndex#removeOffsetFromDeletedLedgers, if there are no ledgers to delete, the key pair will leak.
    
    ### Changes
    Check the ledgers to deletion Set first, and if the set is not empty, then generate the keys.
    
    (cherry picked from commit ceba60565cf7cb438e9be4ab7416a2808b9168a1)
---
 .../apache/bookkeeper/bookie/storage/ldb/EntryLocationIndex.java   | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/ldb/EntryLocationIndex.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/ldb/EntryLocationIndex.java
index dc8e947ffc..41091f1b1d 100644
--- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/ldb/EntryLocationIndex.java
+++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/ldb/EntryLocationIndex.java
@@ -195,9 +195,6 @@ public class EntryLocationIndex implements Closeable {
     private static final int DELETE_ENTRIES_BATCH_SIZE = 100000;
 
     public void removeOffsetFromDeletedLedgers() throws IOException {
-        LongPairWrapper firstKeyWrapper = LongPairWrapper.get(-1, -1);
-        LongPairWrapper lastKeyWrapper = LongPairWrapper.get(-1, -1);
-        LongPairWrapper keyToDelete = LongPairWrapper.get(-1, -1);
 
         Set<Long> ledgersToDelete = deletedLedgers.items();
 
@@ -205,6 +202,10 @@ public class EntryLocationIndex implements Closeable {
             return;
         }
 
+        LongPairWrapper keyToDelete = LongPairWrapper.get(-1, -1);
+        LongPairWrapper firstKeyWrapper = LongPairWrapper.get(-1, -1);
+        LongPairWrapper lastKeyWrapper = LongPairWrapper.get(-1, -1);
+
         log.info("Deleting indexes for ledgers: {}", ledgersToDelete);
         long startTime = System.nanoTime();
         long deletedEntries = 0;