Search in sources :

Example 6 with StubStorageCursors

use of org.neo4j.storageengine.api.StubStorageCursors in project neo4j by neo4j.

the class StoreScanStageTest method shouldGenerateUpdatesInParallel.

@ValueSource(booleans = { true, false })
@ParameterizedTest(name = "parallelWrite={0}")
void shouldGenerateUpdatesInParallel(boolean parallelWrite) {
    // given
    StubStorageCursors data = someData();
    EntityIdIterator entityIdIterator = new CursorEntityIdIterator<>(data.allocateNodeCursor(NULL));
    var propertyConsumer = new ThreadCapturingPropertyConsumer();
    var tokenConsumer = new ThreadCapturingTokenConsumer();
    ControlledLockFunction lockFunction = new ControlledLockFunction();
    StoreScanStage<StorageNodeCursor> scan = new StoreScanStage<>(dbConfig, config, ct -> entityIdIterator, NO_EXTERNAL_UPDATES, new AtomicBoolean(true), data, new int[] { LABEL }, alwaysTrue(), propertyConsumer, tokenConsumer, new NodeCursorBehaviour(data), lockFunction, parallelWrite, jobScheduler, PageCacheTracer.NULL, EmptyMemoryTracker.INSTANCE);
    // when
    runScan(scan);
    // then it completes and we see > 1 threads
    assertThat(lockFunction.seenThreads.size()).isGreaterThan(1);
    if (parallelWrite) {
        assertThat(propertyConsumer.seenThreads.size()).isGreaterThan(1);
        assertThat(tokenConsumer.seenThreads.size()).isGreaterThan(1);
    } else {
        assertThat(propertyConsumer.seenThreads.size()).isEqualTo(1);
        assertThat(tokenConsumer.seenThreads.size()).isEqualTo(1);
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CursorEntityIdIterator(org.neo4j.kernel.impl.transaction.state.storeview.PropertyAwareEntityStoreScan.CursorEntityIdIterator) StubStorageCursors(org.neo4j.storageengine.api.StubStorageCursors) CursorEntityIdIterator(org.neo4j.kernel.impl.transaction.state.storeview.PropertyAwareEntityStoreScan.CursorEntityIdIterator) StorageNodeCursor(org.neo4j.storageengine.api.StorageNodeCursor) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 7 with StubStorageCursors

use of org.neo4j.storageengine.api.StubStorageCursors in project neo4j by neo4j.

the class StoreScanStageTest method shouldPanicAndExitStageOnWriteFailure.

@Test
void shouldPanicAndExitStageOnWriteFailure() {
    // given
    StubStorageCursors data = someData();
    EntityIdIterator entityIdIterator = new CursorEntityIdIterator<>(data.allocateNodeCursor(NULL));
    var failingWriter = new PropertyConsumer(() -> {
        throw new IllegalStateException("Failed to write");
    });
    StoreScanStage<StorageNodeCursor> scan = new StoreScanStage<>(dbConfig, config, ct -> entityIdIterator, NO_EXTERNAL_UPDATES, new AtomicBoolean(true), data, new int[] { LABEL }, alwaysTrue(), failingWriter, null, new NodeCursorBehaviour(data), id -> null, true, jobScheduler, PageCacheTracer.NULL, EmptyMemoryTracker.INSTANCE);
    // when/then
    assertThatThrownBy(() -> runScan(scan)).isInstanceOf(IllegalStateException.class).hasMessageContaining("Failed to write");
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CursorEntityIdIterator(org.neo4j.kernel.impl.transaction.state.storeview.PropertyAwareEntityStoreScan.CursorEntityIdIterator) StubStorageCursors(org.neo4j.storageengine.api.StubStorageCursors) CursorEntityIdIterator(org.neo4j.kernel.impl.transaction.state.storeview.PropertyAwareEntityStoreScan.CursorEntityIdIterator) StorageNodeCursor(org.neo4j.storageengine.api.StorageNodeCursor) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 8 with StubStorageCursors

use of org.neo4j.storageengine.api.StubStorageCursors in project neo4j by neo4j.

the class StoreScanStageTest method shouldReportCorrectNumberOfEntitiesProcessed.

@Test
void shouldReportCorrectNumberOfEntitiesProcessed() {
    // given
    StubStorageCursors data = someData();
    AtomicReference<StoreScanStage<StorageNodeCursor>> stage = new AtomicReference<>();
    EntityIdIterator entityIdIterator = new CursorEntityIdIterator<>(data.allocateNodeCursor(NULL)) {

        private long manualCounter;

        @Override
        protected boolean fetchNext() {
            assertThat(stage.get().numberOfIteratedEntities()).isEqualTo((manualCounter / config.batchSize()) * config.batchSize());
            manualCounter++;
            return super.fetchNext();
        }
    };
    StoreScanStage<StorageNodeCursor> scan = new StoreScanStage(dbConfig, config, ct -> entityIdIterator, NO_EXTERNAL_UPDATES, new AtomicBoolean(true), data, new int[] { LABEL }, alwaysTrue(), new ThreadCapturingPropertyConsumer(), new ThreadCapturingTokenConsumer(), new NodeCursorBehaviour(data), l -> LockService.NO_LOCK, true, jobScheduler, PageCacheTracer.NULL, EmptyMemoryTracker.INSTANCE);
    stage.set(scan);
    // when
    runScan(scan);
    // then
    assertThat(scan.numberOfIteratedEntities()).isEqualTo((long) config.batchSize() * NUMBER_OF_BATCHES);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CursorEntityIdIterator(org.neo4j.kernel.impl.transaction.state.storeview.PropertyAwareEntityStoreScan.CursorEntityIdIterator) AtomicReference(java.util.concurrent.atomic.AtomicReference) StubStorageCursors(org.neo4j.storageengine.api.StubStorageCursors) CursorEntityIdIterator(org.neo4j.kernel.impl.transaction.state.storeview.PropertyAwareEntityStoreScan.CursorEntityIdIterator) StorageNodeCursor(org.neo4j.storageengine.api.StorageNodeCursor) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 9 with StubStorageCursors

use of org.neo4j.storageengine.api.StubStorageCursors in project neo4j by neo4j.

the class StoreScanStageTest method shouldAbortScanOnStopped.

@Test
void shouldAbortScanOnStopped() {
    // given
    StubStorageCursors data = someData();
    EntityIdIterator entityIdIterator = new CursorEntityIdIterator<>(data.allocateNodeCursor(NULL));
    AtomicInteger numBatchesProcessed = new AtomicInteger();
    AtomicBoolean continueScanning = new AtomicBoolean(true);
    AbortingExternalUpdatesCheck externalUpdatesCheck = new AbortingExternalUpdatesCheck(1, continueScanning);
    var writer = new PropertyConsumer(() -> numBatchesProcessed.incrementAndGet());
    StoreScanStage<StorageNodeCursor> scan = new StoreScanStage(dbConfig, config, ct -> entityIdIterator, externalUpdatesCheck, continueScanning, data, new int[] { LABEL }, alwaysTrue(), writer, null, new NodeCursorBehaviour(data), id -> null, true, jobScheduler, PageCacheTracer.NULL, EmptyMemoryTracker.INSTANCE);
    // when
    runScan(scan);
    // then
    assertThat(numBatchesProcessed.get()).isEqualTo(2);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CursorEntityIdIterator(org.neo4j.kernel.impl.transaction.state.storeview.PropertyAwareEntityStoreScan.CursorEntityIdIterator) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) StubStorageCursors(org.neo4j.storageengine.api.StubStorageCursors) CursorEntityIdIterator(org.neo4j.kernel.impl.transaction.state.storeview.PropertyAwareEntityStoreScan.CursorEntityIdIterator) StorageNodeCursor(org.neo4j.storageengine.api.StorageNodeCursor) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 10 with StubStorageCursors

use of org.neo4j.storageengine.api.StubStorageCursors in project neo4j by neo4j.

the class EntityValueUpdatesTest method propertyLoader.

private static StorageReader propertyLoader(StorageProperty... properties) {
    StubStorageCursors stub = new StubStorageCursors();
    for (StorageProperty property : properties) {
        stub.propertyKeyTokenHolder().addToken(new NamedToken(String.valueOf(property.propertyKeyId()), property.propertyKeyId()));
    }
    Map<String, Value> propertyMap = new HashMap<>();
    for (StorageProperty p : properties) {
        propertyMap.put(String.valueOf(p.propertyKeyId()), p.value());
    }
    stub.withNode(ENTITY_ID).properties(propertyMap);
    stub.withRelationship(ENTITY_ID, 1, 1, 2).properties(propertyMap);
    return stub;
}
Also used : HashMap(java.util.HashMap) Value(org.neo4j.values.storable.Value) PropertyKeyValue(org.neo4j.storageengine.api.PropertyKeyValue) StorageProperty(org.neo4j.storageengine.api.StorageProperty) StubStorageCursors(org.neo4j.storageengine.api.StubStorageCursors) NamedToken(org.neo4j.token.api.NamedToken)

Aggregations

StubStorageCursors (org.neo4j.storageengine.api.StubStorageCursors)17 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)12 StorageNodeCursor (org.neo4j.storageengine.api.StorageNodeCursor)12 Test (org.junit.jupiter.api.Test)9 ValueSource (org.junit.jupiter.params.provider.ValueSource)7 SimpleStageControl (org.neo4j.internal.batchimport.staging.SimpleStageControl)7 GeneratedIndexUpdates (org.neo4j.kernel.impl.transaction.state.storeview.GenerateIndexUpdatesStep.GeneratedIndexUpdates)7 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5 CursorEntityIdIterator (org.neo4j.kernel.impl.transaction.state.storeview.PropertyAwareEntityStoreScan.CursorEntityIdIterator)5 Value (org.neo4j.values.storable.Value)5 IndexProxyProvider (org.neo4j.kernel.impl.api.index.IndexingService.IndexProxyProvider)4 StoreScan (org.neo4j.kernel.impl.api.index.StoreScan)4 HashMap (java.util.HashMap)3 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)3 IndexProxy (org.neo4j.kernel.impl.api.index.IndexProxy)3 HashSet (java.util.HashSet)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 MutableLongList (org.eclipse.collections.api.list.primitive.MutableLongList)2 MutableLongSet (org.eclipse.collections.api.set.primitive.MutableLongSet)2 Values.intValue (org.neo4j.values.storable.Values.intValue)2