Search in sources :

Example 11 with StorageNodeCursor

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

the class GenerateIndexUpdatesStepTest method shouldSendSingleBatchIfBelowMaxSizeThreshold.

@ValueSource(booleans = { true, false })
@ParameterizedTest
void shouldSendSingleBatchIfBelowMaxSizeThreshold(boolean alsoWrite) throws Exception {
    // given
    StubStorageCursors data = someUniformData(10);
    TestPropertyScanConsumer scanConsumer = new TestPropertyScanConsumer();
    GenerateIndexUpdatesStep<StorageNodeCursor> step = new GenerateIndexUpdatesStep(new SimpleStageControl(), DEFAULT, data, alwaysTrue(), new NodeCursorBehaviour(data), new int[] { LABEL }, scanConsumer, null, NO_LOCKING, 1, mebiBytes(1), alsoWrite, PageCacheTracer.NULL, INSTANCE);
    // when
    CapturingBatchSender<GeneratedIndexUpdates> sender = new CapturingBatchSender<>();
    step.process(allNodeIds(data), sender, NULL);
    // then
    if (alsoWrite) {
        assertThat(sender.batches).isEmpty();
        assertThat(scanConsumer.batches.size()).isEqualTo(1);
        assertThat(scanConsumer.batches.get(0).size()).isEqualTo(10);
    } else {
        assertThat(sender.batches.size()).isEqualTo(1);
        assertThat(scanConsumer.batches).isEmpty();
    }
}
Also used : SimpleStageControl(org.neo4j.internal.batchimport.staging.SimpleStageControl) StubStorageCursors(org.neo4j.storageengine.api.StubStorageCursors) StorageNodeCursor(org.neo4j.storageengine.api.StorageNodeCursor) GeneratedIndexUpdates(org.neo4j.kernel.impl.transaction.state.storeview.GenerateIndexUpdatesStep.GeneratedIndexUpdates) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 12 with StorageNodeCursor

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

the class GenerateIndexUpdatesStepTest method shouldGenerateEntityTokenUpdates.

@ValueSource(booleans = { true, false })
@ParameterizedTest
void shouldGenerateEntityTokenUpdates(boolean alsoWrite) throws Exception {
    // given
    StubStorageCursors data = someUniformData(10);
    TestTokenScanConsumer scanConsumer = new TestTokenScanConsumer();
    GenerateIndexUpdatesStep<StorageNodeCursor> step = new GenerateIndexUpdatesStep<>(new SimpleStageControl(), DEFAULT, data, alwaysTrue(), new NodeCursorBehaviour(data), new int[] { LABEL }, null, scanConsumer, NO_LOCKING, 1, mebiBytes(1), alsoWrite, PageCacheTracer.NULL, INSTANCE);
    Set<TestTokenScanConsumer.Record> expectedUpdates = new HashSet<>();
    try (StorageNodeCursor cursor = data.allocateNodeCursor(NULL)) {
        cursor.scan();
        while (cursor.next()) {
            expectedUpdates.add(new TestTokenScanConsumer.Record(cursor.entityReference(), cursor.labels()));
        }
    }
    // when
    CapturingBatchSender<GeneratedIndexUpdates> sender = new CapturingBatchSender<>();
    step.process(allNodeIds(data), sender, NULL);
    // then
    if (alsoWrite) {
        for (TestTokenScanConsumer.Record tokenUpdate : scanConsumer.batches.get(0)) {
            assertThat(expectedUpdates.remove(tokenUpdate)).isTrue();
        }
    } else {
        GeneratedIndexUpdates updates = sender.batches.get(0);
        updates.completeBatch();
        for (TestTokenScanConsumer.Record tokenUpdate : scanConsumer.batches.get(0)) {
            assertThat(expectedUpdates.remove(tokenUpdate)).isTrue();
        }
    }
    assertThat(expectedUpdates).isEmpty();
}
Also used : SimpleStageControl(org.neo4j.internal.batchimport.staging.SimpleStageControl) StorageNodeCursor(org.neo4j.storageengine.api.StorageNodeCursor) StubStorageCursors(org.neo4j.storageengine.api.StubStorageCursors) HashSet(java.util.HashSet) GeneratedIndexUpdates(org.neo4j.kernel.impl.transaction.state.storeview.GenerateIndexUpdatesStep.GeneratedIndexUpdates) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 13 with StorageNodeCursor

use of org.neo4j.storageengine.api.StorageNodeCursor 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 14 with StorageNodeCursor

use of org.neo4j.storageengine.api.StorageNodeCursor 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 15 with StorageNodeCursor

use of org.neo4j.storageengine.api.StorageNodeCursor 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)

Aggregations

StorageNodeCursor (org.neo4j.storageengine.api.StorageNodeCursor)29 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)12 StubStorageCursors (org.neo4j.storageengine.api.StubStorageCursors)12 Test (org.junit.jupiter.api.Test)8 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 StoragePropertyCursor (org.neo4j.storageengine.api.StoragePropertyCursor)5 HashSet (java.util.HashSet)4 Value (org.neo4j.values.storable.Value)3 HashMap (java.util.HashMap)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 MutableLongSet (org.eclipse.collections.api.set.primitive.MutableLongSet)2 EntityUpdates (org.neo4j.storageengine.api.EntityUpdates)2 Values.intValue (org.neo4j.values.storable.Values.intValue)2 Values.stringValue (org.neo4j.values.storable.Values.stringValue)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 MutableLongList (org.eclipse.collections.api.list.primitive.MutableLongList)1