Skip to content

Commit

Permalink
fix(compaction): prevent double release on compaction shutdown (#2117)
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 40da95b commit c098ee3
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 @@ -80,6 +80,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 @@ -126,8 +126,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 c098ee3

Please sign in to comment.