Search in sources :

Example 6 with BinaryLatch

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();
        }
    }
}
Also used : BinaryLatch(org.neo4j.concurrent.BinaryLatch)

Example 7 with BinaryLatch

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;
}
Also used : BinaryLatch(org.neo4j.concurrent.BinaryLatch)

Example 8 with BinaryLatch

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);
}
Also used : JobHandle(org.neo4j.kernel.impl.util.JobScheduler.JobHandle) BinaryLatch(org.neo4j.concurrent.BinaryLatch)

Example 9 with BinaryLatch

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));
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) IOLimiter(org.neo4j.io.pagecache.IOLimiter) IOException(java.io.IOException) Flushable(java.io.Flushable) BinaryLatch(org.neo4j.concurrent.BinaryLatch)

Aggregations

BinaryLatch (org.neo4j.concurrent.BinaryLatch)9 Test (org.junit.Test)3 AdversarialPagedFile (org.neo4j.adversaries.pagecache.AdversarialPagedFile)2 Flushable (java.io.Flushable)1 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 BoltResponseRecorder (org.neo4j.bolt.testing.BoltResponseRecorder)1 BoltConnectionDescriptor (org.neo4j.bolt.v1.runtime.BoltConnectionDescriptor)1 BoltConnectionFatality (org.neo4j.bolt.v1.runtime.BoltConnectionFatality)1 BoltStateMachine (org.neo4j.bolt.v1.runtime.BoltStateMachine)1 Node (org.neo4j.graphdb.Node)1 Transaction (org.neo4j.graphdb.Transaction)1 IOLimiter (org.neo4j.io.pagecache.IOLimiter)1 JobHandle (org.neo4j.kernel.impl.util.JobScheduler.JobHandle)1