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/06/19 07:42:31 UTC

[bookkeeper] 07/31: 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.16
in repository https://gitbox.apache.org/repos/asf/bookkeeper.git

commit 4d65b9e123f62ae3a873d189688b33ed0907228a
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    | 6 +++---
 1 file changed, 3 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 335609aa86..a496909f67 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
@@ -208,15 +208,15 @@ public class EntryLocationIndex implements Closeable {
     }
 
     public void removeOffsetFromDeletedLedgers() throws IOException {
-        LongPairWrapper firstKeyWrapper = LongPairWrapper.get(-1, -1);
-        LongPairWrapper lastKeyWrapper = LongPairWrapper.get(-1, -1);
-
         Set<Long> ledgersToDelete = deletedLedgers.items();
 
         if (ledgersToDelete.isEmpty()) {
             return;
         }
 
+        LongPairWrapper firstKeyWrapper = LongPairWrapper.get(-1, -1);
+        LongPairWrapper lastKeyWrapper = LongPairWrapper.get(-1, -1);
+
         log.info("Deleting indexes for ledgers: {}", ledgersToDelete);
         long startTime = System.nanoTime();