Skip to content

Commit

Permalink
feat(wal):reduce concurrent conflicts between block write operations …
Browse files Browse the repository at this point in the history
…and poll operations (AutoMQ#1550)
  • Loading branch information
CLFutureX committed Jul 11, 2024
1 parent cb307e8 commit 1ccbeff
Showing 1 changed file with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ public class SlidingWindowService {
* The lock of {@link #pendingBlocks}, {@link #writingBlocks}, {@link #currentBlock}.
*/
private final Lock blockLock = new ReentrantLock();

private final Lock pollBlocKLock = new ReentrantLock();
/**
* The lock of {@link #pendingBlocks}.
*/
private final Lock pollBlockLock = new ReentrantLock();
/**
* Blocks that are being written.
*/
Expand Down Expand Up @@ -280,19 +282,19 @@ private Block nextBlock(Block previousBlock) {
* Get all blocks to be written. If there is no non-empty block, return null.
*/
private BlockBatch pollBlocks() {
if (this.pollBlocKLock.tryLock()) {
if (this.pollBlockLock.tryLock()) {
try {
return pollBlocksLocked();
} finally {
this.pollBlocKLock.unlock();
this.pollBlockLock.unlock();
}
}
return null;
}

/**
* Get all blocks to be written. If there is no non-empty block, return null.
* Note: this method is NOT thread safe, and it should be called with {@link #blockLock} locked.
* Note: this method is NOT thread safe, and it should be called with {@link #pollBlockLock} locked.
*/
private BlockBatch pollBlocksLocked() {
Block currentBlock = this.currentBlock;
Expand Down

0 comments on commit 1ccbeff

Please sign in to comment.