Search in sources :

Example 6 with SynchronizedArrayIdOrderingQueue

use of org.neo4j.kernel.impl.util.SynchronizedArrayIdOrderingQueue in project neo4j by neo4j.

the class RecordStorageEngineRule method get.

private RecordStorageEngine get(FileSystemAbstraction fs, PageCache pageCache, SchemaIndexProvider schemaIndexProvider, DatabaseHealth databaseHealth, File storeDirectory, Function<BatchTransactionApplierFacade, BatchTransactionApplierFacade> transactionApplierTransformer) {
    if (!fs.fileExists(storeDirectory) && !fs.mkdir(storeDirectory)) {
        throw new IllegalStateException();
    }
    IdGeneratorFactory idGeneratorFactory = new EphemeralIdGenerator.Factory();
    LabelScanStoreProvider labelScanStoreProvider = nativeLabelScanStoreProvider(storeDirectory, fs, pageCache);
    LegacyIndexProviderLookup legacyIndexProviderLookup = mock(LegacyIndexProviderLookup.class);
    when(legacyIndexProviderLookup.all()).thenReturn(Iterables.empty());
    IndexConfigStore indexConfigStore = new IndexConfigStore(storeDirectory, fs);
    JobScheduler scheduler = life.add(new Neo4jJobScheduler());
    Config config = Config.defaults();
    Supplier<KernelTransactionsSnapshot> txSnapshotSupplier = () -> new KernelTransactionsSnapshot(Collections.emptySet(), 0);
    return life.add(new ExtendedRecordStorageEngine(storeDirectory, config, idGeneratorFactory, IdReuseEligibility.ALWAYS, new CommunityIdTypeConfigurationProvider(), pageCache, fs, NullLogProvider.getInstance(), mock(PropertyKeyTokenHolder.class), mock(LabelTokenHolder.class), mock(RelationshipTypeTokenHolder.class), () -> {
    }, new StandardConstraintSemantics(), scheduler, mock(TokenNameLookup.class), new ReentrantLockService(), schemaIndexProvider, IndexingService.NO_MONITOR, databaseHealth, labelScanStoreProvider, legacyIndexProviderLookup, indexConfigStore, new SynchronizedArrayIdOrderingQueue(20), txSnapshotSupplier, transactionApplierTransformer));
}
Also used : JobScheduler(org.neo4j.kernel.impl.util.JobScheduler) Neo4jJobScheduler(org.neo4j.kernel.impl.util.Neo4jJobScheduler) LabelScanStoreProvider(org.neo4j.kernel.impl.api.scan.LabelScanStoreProvider) NeoStoreDataSourceRule.nativeLabelScanStoreProvider(org.neo4j.test.rule.NeoStoreDataSourceRule.nativeLabelScanStoreProvider) LegacyIndexProviderLookup(org.neo4j.kernel.impl.api.LegacyIndexProviderLookup) Config(org.neo4j.kernel.configuration.Config) IndexConfigStore(org.neo4j.kernel.impl.index.IndexConfigStore) IdGeneratorFactory(org.neo4j.kernel.impl.store.id.IdGeneratorFactory) IdGeneratorFactory(org.neo4j.kernel.impl.store.id.IdGeneratorFactory) KernelTransactionsSnapshot(org.neo4j.kernel.impl.api.KernelTransactionsSnapshot) Neo4jJobScheduler(org.neo4j.kernel.impl.util.Neo4jJobScheduler) CommunityIdTypeConfigurationProvider(org.neo4j.kernel.impl.store.id.configuration.CommunityIdTypeConfigurationProvider) SynchronizedArrayIdOrderingQueue(org.neo4j.kernel.impl.util.SynchronizedArrayIdOrderingQueue) ReentrantLockService(org.neo4j.kernel.impl.locking.ReentrantLockService) StandardConstraintSemantics(org.neo4j.kernel.impl.constraints.StandardConstraintSemantics)

Example 7 with SynchronizedArrayIdOrderingQueue

use of org.neo4j.kernel.impl.util.SynchronizedArrayIdOrderingQueue in project neo4j by neo4j.

the class SynchronizedArrayIdOrderingQueueStressTest method shouldWithstandHighStressAndStillKeepOrder.

@Test
public void shouldWithstandHighStressAndStillKeepOrder() throws Exception {
    // GIVEN an ordering queue w/ low initial size as to also exercise resize under stress
    VerifyingIdOrderingQueue queue = new VerifyingIdOrderingQueue(new SynchronizedArrayIdOrderingQueue(5));
    Committer[] committers = new Committer[20];
    CountDownLatch readySignal = new CountDownLatch(committers.length);
    AtomicLong endTime = new AtomicLong();
    CountDownLatch startSignal = new CountDownLatch(1);
    PrimitiveLongIterator idSource = neverEndingIdStream();
    for (int i = 0; i < committers.length; i++) {
        committers[i] = new Committer(queue, idSource, endTime, readySignal, startSignal);
    }
    // WHEN GO!
    readySignal.await();
    endTime.set(currentTimeMillis() + SECONDS.toMillis(3));
    startSignal.countDown();
    for (Committer committer : committers) {
        committer.awaitFinish();
    }
    // THEN there should have been at least a few ids processed. The order of those
    // are verified as they go, by the VerifyingIdOrderingQueue
    assertTrue("Would have wanted at least a few ids to be processed, but only saw " + queue.getNumberOfOrderlyRemovedIds(), queue.getNumberOfOrderlyRemovedIds() > 50);
}
Also used : PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) AtomicLong(java.util.concurrent.atomic.AtomicLong) SynchronizedArrayIdOrderingQueue(org.neo4j.kernel.impl.util.SynchronizedArrayIdOrderingQueue) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 8 with SynchronizedArrayIdOrderingQueue

use of org.neo4j.kernel.impl.util.SynchronizedArrayIdOrderingQueue in project neo4j by neo4j.

the class SynchronizedArrayIdOrderingQueueTest method shouldOfferAwaitAndRemoveRoundAndRound.

@Test
public void shouldOfferAwaitAndRemoveRoundAndRound() throws Exception {
    // GIVEN
    IdOrderingQueue queue = new SynchronizedArrayIdOrderingQueue(5);
    long offeredId = 0, awaitedId = 0;
    queue.offer(offeredId++);
    queue.offer(offeredId++);
    // WHEN
    for (int i = 0; i < 20; i++) {
        queue.waitFor(awaitedId);
        queue.removeChecked(awaitedId++);
        queue.offer(offeredId++);
        assertFalse(queue.isEmpty());
    }
    // THEN
    queue.removeChecked(awaitedId++);
    queue.removeChecked(awaitedId++);
    assertTrue(queue.isEmpty());
}
Also used : SynchronizedArrayIdOrderingQueue(org.neo4j.kernel.impl.util.SynchronizedArrayIdOrderingQueue) IdOrderingQueue(org.neo4j.kernel.impl.util.IdOrderingQueue) SynchronizedArrayIdOrderingQueue(org.neo4j.kernel.impl.util.SynchronizedArrayIdOrderingQueue) Test(org.junit.Test)

Example 9 with SynchronizedArrayIdOrderingQueue

use of org.neo4j.kernel.impl.util.SynchronizedArrayIdOrderingQueue in project neo4j by neo4j.

the class SynchronizedArrayIdOrderingQueueTest method shouldExtendArrayWhenIdsAreWrappingAround.

@Test
public void shouldExtendArrayWhenIdsAreWrappingAround() throws Exception {
    // GIVEN
    IdOrderingQueue queue = new SynchronizedArrayIdOrderingQueue(5);
    for (int i = 0; i < 3; i++) {
        queue.offer(i);
        queue.removeChecked(i);
    }
    //                     ^-- headIndex and offerIndex
    for (int i = 3; i < 8; i++) {
        queue.offer(i);
    }
    // Now we're at [5,6,2,3,4]
    //                     ^-- headIndex and offerIndex%length
    // WHEN offering one more, so that the queue is forced to resize
    queue.offer(8);
    // THEN it should have been offered as well as all the previous ids should be intact
    for (int i = 3; i <= 8; i++) {
        assertFalse(queue.isEmpty());
        queue.removeChecked(i);
    }
    assertTrue(queue.isEmpty());
}
Also used : SynchronizedArrayIdOrderingQueue(org.neo4j.kernel.impl.util.SynchronizedArrayIdOrderingQueue) IdOrderingQueue(org.neo4j.kernel.impl.util.IdOrderingQueue) SynchronizedArrayIdOrderingQueue(org.neo4j.kernel.impl.util.SynchronizedArrayIdOrderingQueue) Test(org.junit.Test)

Aggregations

SynchronizedArrayIdOrderingQueue (org.neo4j.kernel.impl.util.SynchronizedArrayIdOrderingQueue)9 Test (org.junit.Test)6 IndexConfigStore (org.neo4j.kernel.impl.index.IndexConfigStore)4 IdOrderingQueue (org.neo4j.kernel.impl.util.IdOrderingQueue)4 TransactionIdStore (org.neo4j.kernel.impl.transaction.log.TransactionIdStore)3 IOException (java.io.IOException)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 KernelException (org.neo4j.kernel.api.exceptions.KernelException)2 PropertyAccessor (org.neo4j.kernel.api.index.PropertyAccessor)2 SchemaIndexProvider (org.neo4j.kernel.api.index.SchemaIndexProvider)2 LabelScanStore (org.neo4j.kernel.api.labelscan.LabelScanStore)2 Config (org.neo4j.kernel.configuration.Config)2 DeleteStoresFromOtherLabelScanStoreProviders (org.neo4j.kernel.extension.dependency.DeleteStoresFromOtherLabelScanStoreProviders)2 NamedLabelScanStoreSelectionStrategy (org.neo4j.kernel.extension.dependency.NamedLabelScanStoreSelectionStrategy)2 LabelScanStoreProvider (org.neo4j.kernel.impl.api.scan.LabelScanStoreProvider)2 File (java.io.File)1 Clock (java.time.Clock)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1