Skip to content

Commit

Permalink
fix(compaction): prevent double release on compaction shutdown (#2115)
Browse files Browse the repository at this point in the history
Signed-off-by: Shichao Nie <[email protected]>
  • Loading branch information
SCNieh authored Nov 5, 2024
1 parent 8338f18 commit 04b53f4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ public CompletableFuture<ByteBuf> getDataCf() {
return this.dataCf;
}

public ByteBuf getAndReleaseData() {
if (refCount.getAndDecrement() == 0) {
throw new IllegalStateException("Data has already been released");
}
return this.dataCf.join();
}

public void releaseRef() {
refCount.decrementAndGet();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,7 @@ public CompletableFuture<Void> close() {
private CompositeByteBuf groupWaitingBlocks() {
CompositeByteBuf buf = ByteBufAlloc.compositeByteBuffer();
for (StreamDataBlock block : waitingUploadBlocks) {
buf.addComponent(true, block.getDataCf().join());
block.releaseRef();
buf.addComponent(true, block.getAndReleaseData());
completedBlocks.add(block);
nextDataBlockPosition += block.getBlockSize();
}
Expand Down

0 comments on commit 04b53f4

Please sign in to comment.