use of org.neo4j.util.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.util.concurrent.BinaryLatch in project neo4j by neo4j.
the class LatchMapTest method takeOrAwaitLatchMustNotLetUnrelatedLatchesConflictTooMuch.
@ValueSource(ints = { LatchMap.DEFAULT_FAULT_LOCK_STRIPING, 1 << 10, 1 << 11 })
@ParameterizedTest
void takeOrAwaitLatchMustNotLetUnrelatedLatchesConflictTooMuch(int size) throws Exception {
LatchMap latches = new LatchMap(size);
BinaryLatch latch = latches.takeOrAwaitLatch(42);
assertThat(latch).isNotNull();
ExecutorService executor = null;
try {
executor = Executors.newSingleThreadExecutor();
Future<BinaryLatch> future = executor.submit(() -> latches.takeOrAwaitLatch(33));
assertThat(future.get(30, TimeUnit.SECONDS)).isNotNull();
latch.release();
} finally {
if (executor != null) {
executor.shutdown();
}
}
}
use of org.neo4j.util.concurrent.BinaryLatch in project neo4j by neo4j.
the class LabelsAcceptanceTest method shouldListAllLabelsInUseEvenWhenExclusiveLabelLocksAreTaken.
@Test
void shouldListAllLabelsInUseEvenWhenExclusiveLabelLocksAreTaken() {
assertTimeoutPreemptively(Duration.ofSeconds(30), () -> {
// Given
createNode(db, Labels.MY_LABEL);
Node node = createNode(db, Labels.MY_OTHER_LABEL);
try (Transaction tx = db.beginTx()) {
tx.getNodeById(node.getId()).delete();
tx.commit();
}
BinaryLatch indexCreateStarted = new BinaryLatch();
BinaryLatch indexCreateAllowToFinish = new BinaryLatch();
Thread indexCreator = new Thread(() -> {
try (Transaction tx = db.beginTx()) {
tx.schema().indexFor(Labels.MY_LABEL).on("prop").create();
indexCreateStarted.release();
indexCreateAllowToFinish.await();
tx.commit();
}
});
indexCreator.start();
// When
indexCreateStarted.await();
List<Label> labels;
try (Transaction tx = db.beginTx()) {
labels = asList(tx.getAllLabelsInUse());
}
indexCreateAllowToFinish.release();
indexCreator.join();
// Then
assertEquals(1, labels.size());
assertThat(map(Label::name, labels)).contains(Labels.MY_LABEL.name());
});
}
use of org.neo4j.util.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 EmptyIOController() {
@Override
public void disable() {
limitDisableCounter.getAndIncrement();
forceCheckPointStartLatch.release();
}
@Override
public void enable() {
limitDisableCounter.getAndDecrement();
}
@Override
public boolean isEnabled() {
return limitDisableCounter.get() != 0;
}
};
mockTxIdStore();
CheckPointerImpl checkPointer = checkPointer();
doAnswer(invocation -> {
backgroundCheckPointStartedLatch.release();
forceCheckPointStartLatch.await();
long newValue = limitDisableCounter.get();
observedRushCount.set(newValue);
return null;
}).when(forceOperation).flushAndForce(any());
Future<Object> forceCheckPointer = forkFuture(() -> {
backgroundCheckPointStartedLatch.await();
asyncAction.accept(checkPointer);
return null;
});
when(threshold.isCheckPointingNeeded(anyLong(), anyLong(), eq(INFO))).thenReturn(true);
checkPointer.checkPointIfNeeded(INFO);
forceCheckPointer.get();
assertThat(observedRushCount.get()).isEqualTo(1L);
}
use of org.neo4j.util.concurrent.BinaryLatch in project neo4j by neo4j.
the class IndexUpdateSink method awaitUpdateApplication.
public void awaitUpdateApplication() {
BinaryLatch updateLatch = new BinaryLatch();
scheduler.schedule(Group.INDEX_UPDATING, JobMonitoringParams.NOT_MONITORED, updateLatch::release);
updateLatch.await();
}
Aggregations