Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -968,12 +968,18 @@ public void scanEntryLog(long entryLogId, EntryLogScanner scanner) throws IOExce
// Buffer where to read the entrySize (4 bytes) and the ledgerId (8 bytes)
ByteBuf headerBuffer = Unpooled.buffer(4 + 8);
BufferedReadChannel bc;
boolean throwExceptionWhenGetChannel = false;
// Get the BufferedChannel for the current entry log file
try {
bc = getChannelForLogId(entryLogId);
} catch (IOException e) {
LOG.warn("Failed to get channel to scan entry log: " + entryLogId + ".log");
throwExceptionWhenGetChannel = true;
Copy link
Contributor

@AnonHxy AnonHxy Jul 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not call headerBuffer.release() here?

And I think that it will be better if we move line969 to just before the second try catch block, like:

ByteBuf data = allocator.directBuffer(1024 * 1024);
ByteBuf headerBuffer = Unpooled.buffer(4 + 8);  // line969
 try {
           
            // Read through the entry log file and extract the ledger ID's.
            while (true) {
                // Check if we'`
            // ...
           // ...
 finally {
           ReferenceCountUtil.release(headerBuffer);
            ReferenceCountUtil.release(data);
   }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for review. I think the code function is the same. release resource in finally code block is more like the java style.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree with @AnonHxy

throw e;
} finally {
if (throwExceptionWhenGetChannel) {
headerBuffer.release();
}
}
// Start the read position in the current entry log file to be after
// the header where all of the ledger entries are.
Expand Down Expand Up @@ -1027,6 +1033,7 @@ public void scanEntryLog(long entryLogId, EntryLogScanner scanner) throws IOExce
pos += entrySize;
}
} finally {
ReferenceCountUtil.release(headerBuffer);
ReferenceCountUtil.release(data);
}
}
Expand Down