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)

(cherry picked from commit 8fce024)
  • Loading branch information
HQebupt authored and nicoloboschi committed Nov 29, 2022
1 parent 7467996 commit c334fa3
Showing 1 changed file with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,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 @@ -188,7 +189,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 @@ -836,7 +837,7 @@ public ByteBuf internalReadEntry(long ledgerId, long entryId, long location, boo
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 @@ -874,7 +875,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 @@ -1020,7 +1021,7 @@ public void scanEntryLog(long entryLogId, EntryLogScanner scanner) throws IOExce
pos += entrySize;
}
} finally {
data.release();
ReferenceCountUtil.safeRelease(data);
}
}

Expand Down Expand Up @@ -1109,7 +1110,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 c334fa3

Please sign in to comment.