Skip to content

Commit

Permalink
Implement translog isLockAvailable
Browse files Browse the repository at this point in the history
Signed-off-by: Yujin Ahn <ujahnn@gmail.com>
  • Loading branch information
ahnyujin committed Feb 10, 2025
1 parent da1aff1 commit 1124cfe
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public class RemoteFsTranslog extends Translog {
// Semaphore used to allow only single remote generation to happen at a time
protected final Semaphore remoteGenerationDeletionPermits = new Semaphore(REMOTE_DELETION_PERMITS);

// These permits exist to allow any inflight background triggered upload.
// this lock exists to allow any inflight background triggered upload.
private static final ReentrantLock reentrantLock = new ReentrantLock();
private static final ReleasableLock syncPermit = new ReleasableLock(reentrantLock);
protected final AtomicBoolean pauseSync = new AtomicBoolean(false);
Expand Down Expand Up @@ -377,7 +377,7 @@ private boolean prepareAndUpload(Long primaryTerm, Long generation) throws IOExc
// 1. Using startedPrimarySupplier, we prevent the new primary to do pre-emptive syncs
// 2. Using syncPermit, we prevent syncs at the desired time during primary relocation.
if (startedPrimarySupplier.getAsBoolean() == false || syncPermit.isHeldByCurrentThread() || syncPermit.tryAcquire() == null) {
logger.debug("skipped uploading translog for {} {} syncPermit={}", primaryTerm, generation, availablePermits());
logger.debug("skipped uploading translog for {} {} isLockAvailable={}", primaryTerm, generation, isLockAvailable());
// NO-OP
return false;
}
Expand Down Expand Up @@ -748,8 +748,8 @@ public long getMinUnreferencedSeqNoInSegments(long minUnrefCheckpointInLastCommi
}

// Visible for testing
int availablePermits() {
return reentrantLock.isLocked() ? 0 : 1;
boolean isLockAvailable() {
return !reentrantLock.isLocked();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -544,11 +544,11 @@ public void testDrainSync() throws Exception {
}
});
thread1.start();
assertBusy(() -> assertEquals(0, translog.availablePermits()));
assertBusy(() -> assertFalse(translog.isLockAvailable()));
// Case 2 - During an upload, if drainSync is called, it will wait for it to acquire and available permits are 0.
Releasable releasable = translog.drainSync();
assertBusy(() -> assertEquals(0, latch.getCount()));
assertEquals(0, translog.availablePermits());
assertFalse(translog.isLockAvailable());
slowDown.setSleepSeconds(0);
assertEquals(4, translog.allUploaded().size());
assertEquals(2, translog.readers.size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -876,11 +876,11 @@ public void testDrainSync() throws Exception {
}
});
thread1.start();
assertBusy(() -> assertEquals(0, translog.availablePermits()));
assertBusy(() -> assertFalse(translog.isLockAvailable()));
// Case 2 - During an upload, if drainSync is called, it will wait for it to acquire and available permits are 0.
Releasable releasable = translog.drainSync();
assertBusy(() -> assertEquals(0, latch.getCount()));
assertEquals(0, translog.availablePermits());
assertFalse(translog.isLockAvailable());
slowDown.setSleepSeconds(0);
assertEquals(6, translog.allUploaded().size());
assertEquals(2, translog.readers.size());
Expand Down

0 comments on commit 1124cfe

Please sign in to comment.