use of org.neo4j.concurrent.BinaryLatch in project neo4j by neo4j.
the class TinyLockManager method lock.
public void lock(int recordId) {
Integer record = recordId;
BinaryLatch myLatch = new BinaryLatch();
for (; ; ) {
BinaryLatch existingLatch = map.putIfAbsent(record, myLatch);
if (existingLatch == null) {
break;
} else {
existingLatch.await();
}
}
}
use of org.neo4j.concurrent.BinaryLatch in project neo4j by neo4j.
the class TinyLockManager method tryLock.
public boolean tryLock(int recordId) {
Integer record = recordId;
BinaryLatch myLatch = new BinaryLatch();
BinaryLatch existingLatch = map.putIfAbsent(record, myLatch);
return existingLatch == null;
}
use of org.neo4j.concurrent.BinaryLatch in project neo4j by neo4j.
the class SlaveUpdatePuller method start.
@Override
public void start() {
if (shutdownLatch != null) {
// This SlaveUpdatePuller has already been initialised
return;
}
shutdownLatch = new BinaryLatch();
JobHandle handle = jobScheduler.schedule(JobScheduler.Groups.pullUpdates, this);
handle.registerCancelListener(this);
}
use of org.neo4j.concurrent.BinaryLatch in project neo4j by neo4j.
the class CheckPointerImplTest method verifyAsyncActionCausesConcurrentFlushingRush.
private void verifyAsyncActionCausesConcurrentFlushingRush(ThrowingConsumer<CheckPointerImpl, IOException> asyncAction) throws Exception {
AtomicLong limitDisableCounter = new AtomicLong();
AtomicLong observedRushCount = new AtomicLong();
BinaryLatch backgroundCheckPointStartedLatch = new BinaryLatch();
BinaryLatch forceCheckPointStartLatch = new BinaryLatch();
limiter = new IOLimiter() {
@Override
public long maybeLimitIO(long previousStamp, int recentlyCompletedIOs, Flushable flushable) throws IOException {
return 0;
}
@Override
public void disableLimit() {
limitDisableCounter.getAndIncrement();
forceCheckPointStartLatch.release();
}
@Override
public void enableLimit() {
limitDisableCounter.getAndDecrement();
}
};
mockTxIdStore();
CheckPointerImpl checkPointer = checkPointer();
doAnswer(invocation -> {
backgroundCheckPointStartedLatch.release();
forceCheckPointStartLatch.await();
long newValue = limitDisableCounter.get();
observedRushCount.set(newValue);
return null;
}).when(storageEngine).flushAndForce(limiter);
Future<Object> forceCheckPointer = forkFuture(() -> {
backgroundCheckPointStartedLatch.await();
asyncAction.accept(checkPointer);
return null;
});
when(threshold.isCheckPointingNeeded(anyLong(), eq(INFO))).thenReturn(true);
checkPointer.checkPointIfNeeded(INFO);
forceCheckPointer.get();
assertThat(observedRushCount.get(), is(1L));
}
Aggregations