Search in sources :

Example 1 with Workers

use of org.neo4j.internal.batchimport.cache.idmapping.string.Workers in project neo4j by neo4j.

the class IndexWorkSyncTransactionApplicationStressIT method shouldApplyIndexUpdatesInWorkSyncedBatches.

@Test
public void shouldApplyIndexUpdatesInWorkSyncedBatches() throws Exception {
    // GIVEN
    long duration = parseTimeMillis.apply(System.getProperty(getClass().getName() + ".duration", "2s"));
    int numThreads = Integer.getInteger(getClass().getName() + ".numThreads", Runtime.getRuntime().availableProcessors());
    DefaultFileSystemAbstraction fs = fileSystemRule.get();
    PageCache pageCache = pageCacheRule.getPageCache(fs);
    CollectingIndexUpdateListener index = new CollectingIndexUpdateListener();
    RecordStorageEngine storageEngine = storageEngineRule.getWith(fs, pageCache, DatabaseLayout.ofFlat(directory.directory(DEFAULT_DATABASE_NAME))).indexUpdateListener(index).build();
    storageEngine.apply(tx(singletonList(Commands.createIndexRule(DESCRIPTOR, 1, descriptor))), EXTERNAL);
    // WHEN
    Workers<Worker> workers = new Workers<>(getClass().getSimpleName());
    final AtomicBoolean end = new AtomicBoolean();
    for (int i = 0; i < numThreads; i++) {
        workers.start(new Worker(i, end, storageEngine, 10, index));
    }
    // let the threads hammer the storage engine for some time
    Thread.sleep(duration);
    end.set(true);
    // THEN (assertions as part of the workers applying transactions)
    workers.awaitAndThrowOnError();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) Workers(org.neo4j.internal.batchimport.cache.idmapping.string.Workers) RecordStorageEngine(org.neo4j.internal.recordstorage.RecordStorageEngine) PageCache(org.neo4j.io.pagecache.PageCache) Test(org.junit.Test)

Example 2 with Workers

use of org.neo4j.internal.batchimport.cache.idmapping.string.Workers in project neo4j by neo4j.

the class InternalTransactionCommitProcessIT method commitDuringContinuousCheckpointing.

@Test
@Timeout(value = 5, unit = TimeUnit.MINUTES)
void commitDuringContinuousCheckpointing() throws Exception {
    final AtomicBoolean done = new AtomicBoolean();
    Workers<Runnable> workers = new Workers<>(getClass().getSimpleName());
    try {
        for (int i = 0; i < TOTAL_ACTIVE_THREADS; i++) {
            workers.start(new Runnable() {

                private final ThreadLocalRandom random = ThreadLocalRandom.current();

                @Override
                public void run() {
                    while (!done.get()) {
                        try (Transaction tx = db.beginTx()) {
                            tx.createNode();
                            tx.commit();
                        }
                        randomSleep();
                    }
                }

                private void randomSleep() {
                    try {
                        Thread.sleep(random.nextInt(50));
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
            });
        }
        Thread.sleep(SECONDS.toMillis(2));
    } finally {
        done.set(true);
    }
    workers.awaitAndThrowOnError();
    assertThat(countsStore.txId()).as("Count store should be rotated once at least").isGreaterThan(0L);
    long lastRotationTx = checkPointer.forceCheckPoint(new SimpleTriggerInfo("test"));
    assertEquals(transactionIdStore.getLastClosedTransactionId(), lastRotationTx, "NeoStore last closed transaction id should be equal last count store rotation transaction id.");
    assertEquals(transactionIdStore.getLastClosedTransactionId(), countsStore.txId(), "Last closed transaction should be last rotated tx in count store");
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SimpleTriggerInfo(org.neo4j.kernel.impl.transaction.log.checkpoint.SimpleTriggerInfo) Transaction(org.neo4j.graphdb.Transaction) Workers(org.neo4j.internal.batchimport.cache.idmapping.string.Workers) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Test(org.junit.jupiter.api.Test) Timeout(org.junit.jupiter.api.Timeout)

Aggregations

AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 Workers (org.neo4j.internal.batchimport.cache.idmapping.string.Workers)2 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)1 Test (org.junit.Test)1 Test (org.junit.jupiter.api.Test)1 Timeout (org.junit.jupiter.api.Timeout)1 Transaction (org.neo4j.graphdb.Transaction)1 RecordStorageEngine (org.neo4j.internal.recordstorage.RecordStorageEngine)1 DefaultFileSystemAbstraction (org.neo4j.io.fs.DefaultFileSystemAbstraction)1 PageCache (org.neo4j.io.pagecache.PageCache)1 SimpleTriggerInfo (org.neo4j.kernel.impl.transaction.log.checkpoint.SimpleTriggerInfo)1