use of org.neo4j.concurrent.BinaryLatch in project neo4j by neo4j.
the class TransactionIT method shouldReadYourOwnWrites.
@Test
public void shouldReadYourOwnWrites() throws Exception {
try (Transaction tx = env.graph().beginTx()) {
Node node = env.graph().createNode(Label.label("A"));
node.setProperty("prop", "one");
tx.success();
}
BinaryLatch latch = new BinaryLatch();
long dbVersion = env.lastClosedTxId();
Thread thread = new Thread() {
@Override
public void run() {
try (BoltStateMachine machine = env.newMachine(new BoltConnectionDescriptor(new InetSocketAddress("<testClient>", 56789), new InetSocketAddress("<writeServer>", 7468)))) {
machine.init(USER_AGENT, emptyMap(), null);
latch.await();
machine.run("MATCH (n:A) SET n.prop = 'two'", emptyMap(), nullResponseHandler());
machine.pullAll(nullResponseHandler());
} catch (BoltConnectionFatality connectionFatality) {
throw new RuntimeException(connectionFatality);
}
}
};
thread.start();
long dbVersionAfterWrite = dbVersion + 1;
try (BoltStateMachine machine = env.newMachine(new BoltConnectionDescriptor(new InetSocketAddress("<testClient>", 56789), new InetSocketAddress("<readServer>", 7468)))) {
BoltResponseRecorder recorder = new BoltResponseRecorder();
machine.init(USER_AGENT, emptyMap(), null);
latch.release();
final String bookmark = "neo4j:bookmark:v1:tx" + Long.toString(dbVersionAfterWrite);
machine.run("BEGIN", singletonMap("bookmark", bookmark), nullResponseHandler());
machine.pullAll(recorder);
machine.run("MATCH (n:A) RETURN n.prop", emptyMap(), nullResponseHandler());
machine.pullAll(recorder);
machine.run("COMMIT", emptyMap(), nullResponseHandler());
machine.pullAll(recorder);
assertThat(recorder.nextResponse(), succeededWithMetadata("bookmark", BOOKMARK_PATTERN));
assertThat(recorder.nextResponse(), succeededWithRecord("two"));
assertThat(recorder.nextResponse(), succeededWithMetadata("bookmark", BOOKMARK_PATTERN));
}
thread.join();
}
use of org.neo4j.concurrent.BinaryLatch in project neo4j by neo4j.
the class MuninnPageCursor method initiatePageFault.
private Object initiatePageFault(long filePageId, long chunkOffset, Object[] chunk) throws IOException {
BinaryLatch latch = new BinaryLatch();
Object item = null;
if (UnsafeUtil.compareAndSwapObject(chunk, chunkOffset, null, latch)) {
// We managed to inject our latch, so we now own the right to perform the page fault. We also
// have a duty to eventually release and remove the latch, no matter what happens now.
item = pageFault(filePageId, swapper, chunkOffset, chunk, latch);
}
return item;
}
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 MuninnPageCursor method awaitPageFault.
private Object awaitPageFault(Object item) {
BinaryLatch latch = (BinaryLatch) item;
latch.await();
return null;
}
use of org.neo4j.concurrent.BinaryLatch in project neo4j by neo4j.
the class PageCacheTest method writeUnlockMustInvalidateReadLocks.
@Test(timeout = SHORT_TIMEOUT_MILLIS)
public void writeUnlockMustInvalidateReadLocks() throws Exception {
configureStandardPageCache();
BinaryLatch startLatch = new BinaryLatch();
BinaryLatch continueLatch = new BinaryLatch();
try (PagedFile pf = pageCache.map(existingFile("a"), filePageSize);
PageCursor cursor = pf.io(0, PF_SHARED_WRITE_LOCK)) {
// Lock page 0
assertTrue(cursor.next());
Future<Object> read = executor.submit(() -> {
try (PageCursor innerCursor = pf.io(0, PF_SHARED_READ_LOCK)) {
assertTrue(innerCursor.next());
assertTrue(innerCursor.shouldRetry());
startLatch.release();
continueLatch.await();
assertTrue(innerCursor.shouldRetry());
}
return null;
});
startLatch.await();
// Unlock page 0
assertTrue(cursor.next());
continueLatch.release();
read.get();
}
}
Aggregations