Skip to content

Commit

Permalink
[refactor][bookkeeper] Refactor ByteBuf release method in DefaultEntr…
Browse files Browse the repository at this point in the history
…yLogger (apache#3673)
  • Loading branch information
HQebupt authored and Anup Ghatage committed Jul 12, 2024
1 parent 0f443c3 commit 3bd8f7e
Showing 1 changed file with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import io.netty.buffer.ByteBufAllocator;
import io.netty.buffer.PooledByteBufAllocator;
import io.netty.buffer.Unpooled;
import io.netty.util.ReferenceCountUtil;
import io.netty.util.concurrent.FastThreadLocal;
import java.io.BufferedReader;
import java.io.File;
Expand Down Expand Up @@ -190,7 +191,7 @@ public void accept(long ledgerId, long size) {
throw e;
}
} finally {
serializedMap.release();
ReferenceCountUtil.safeRelease(serializedMap);
}
// Flush the ledger's map out before we write the header.
// Otherwise the header might point to something that is not fully
Expand Down Expand Up @@ -842,7 +843,7 @@ private ByteBuf internalReadEntry(long ledgerId, long entryId, long location, bo
ByteBuf data = allocator.buffer(entrySize, entrySize);
int rc = readFromLogChannel(entryLogId, fc, data, pos);
if (rc != entrySize) {
data.release();
ReferenceCountUtil.safeRelease(data);
throw new IOException("Bad entry read from log file id: " + entryLogId,
new EntryLookupException("Short read for " + ledgerId + "@"
+ entryId + " in " + entryLogId + "@"
Expand Down Expand Up @@ -876,7 +877,7 @@ private Header getHeaderForLogId(long entryLogId) throws IOException {
int ledgersCount = headers.readInt();
return new Header(headerVersion, ledgersMapOffset, ledgersCount);
} finally {
headers.release();
ReferenceCountUtil.safeRelease(headers);
}
}

Expand Down Expand Up @@ -1025,7 +1026,7 @@ public void scanEntryLog(long entryLogId, EntryLogScanner scanner) throws IOExce
pos += entrySize;
}
} finally {
data.release();
ReferenceCountUtil.safeRelease(data);
}
}

Expand Down Expand Up @@ -1117,7 +1118,7 @@ EntryLogMetadata extractEntryLogMetadataFromIndex(long entryLogId) throws IOExce
} catch (IndexOutOfBoundsException e) {
throw new IOException(e);
} finally {
ledgersMap.release();
ReferenceCountUtil.safeRelease(ledgersMap);
}

if (meta.getLedgersMap().size() != header.ledgersCount) {
Expand Down

0 comments on commit 3bd8f7e

Please sign in to comment.