Search in sources :

Example 11 with IndexEntryUpdate

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

the class MultipleIndexPopulatorTest method testMultiplePropertyUpdateFailures.

@Test
void testMultiplePropertyUpdateFailures() throws IndexEntryConflictException, FlipFailedKernelException {
    NodePropertyAccessor nodePropertyAccessor = mock(NodePropertyAccessor.class);
    IndexEntryUpdate<?> update1 = add(1, index1, "foo");
    IndexEntryUpdate<?> update2 = add(2, index1, "bar");
    IndexUpdater updater = mock(IndexUpdater.class);
    IndexPopulator populator = createIndexPopulator(updater);
    addPopulator(populator, 1);
    doThrow(getPopulatorException()).when(updater).process(any(IndexEntryUpdate.class));
    IndexUpdater multipleIndexUpdater = multipleIndexPopulator.newPopulatingUpdater(nodePropertyAccessor, NULL);
    multipleIndexUpdater.process(update1);
    multipleIndexUpdater.process(update2);
    verify(updater).process(update1);
    verify(updater, never()).process(update2);
    verify(updater).close();
    checkPopulatorFailure(populator);
}
Also used : IndexPopulator(org.neo4j.kernel.api.index.IndexPopulator) IndexEntryUpdate(org.neo4j.storageengine.api.IndexEntryUpdate) ValueIndexEntryUpdate(org.neo4j.storageengine.api.ValueIndexEntryUpdate) NodePropertyAccessor(org.neo4j.storageengine.api.NodePropertyAccessor) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) Test(org.junit.jupiter.api.Test)

Example 12 with IndexEntryUpdate

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

the class BatchingMultipleIndexPopulatorTest method populatorMarkedAsFailed.

@Test
void populatorMarkedAsFailed() throws Exception {
    Update update1 = nodeUpdate(1, propertyId, "aaa", labelId);
    Update update2 = nodeUpdate(1, propertyId, "bbb", labelId);
    IndexStoreView storeView = newStoreView(update1, update2);
    RuntimeException batchFlushError = new RuntimeException("Batch failed");
    IndexPopulator populator;
    ExecutorService executor = Executors.newSingleThreadExecutor();
    ThreadPoolJobScheduler jobScheduler = new ThreadPoolJobScheduler(executor);
    try {
        MultipleIndexPopulator batchingPopulator = new MultipleIndexPopulator(storeView, NullLogProvider.getInstance(), EntityType.NODE, mock(SchemaState.class), jobScheduler, tokens, NULL, INSTANCE, "", AUTH_DISABLED, Config.defaults(GraphDatabaseInternalSettings.index_population_batch_max_byte_size, 1L));
        populator = addPopulator(batchingPopulator, index1);
        List<IndexEntryUpdate<IndexDescriptor>> expected = forUpdates(index1, update1, update2);
        doThrow(batchFlushError).when(populator).add(eq(expected), any());
        batchingPopulator.createStoreScan(NULL).run(NO_EXTERNAL_UPDATES);
    } finally {
        jobScheduler.shutdown();
        executor.awaitTermination(1, TimeUnit.MINUTES);
    }
    verify(populator).markAsFailed(failure(batchFlushError).asString());
}
Also used : IndexPopulator(org.neo4j.kernel.api.index.IndexPopulator) IndexEntryUpdate(org.neo4j.storageengine.api.IndexEntryUpdate) ValueIndexEntryUpdate(org.neo4j.storageengine.api.ValueIndexEntryUpdate) SchemaState(org.neo4j.internal.schema.SchemaState) ExecutorService(java.util.concurrent.ExecutorService) IndexEntryUpdate(org.neo4j.storageengine.api.IndexEntryUpdate) ValueIndexEntryUpdate(org.neo4j.storageengine.api.ValueIndexEntryUpdate) ThreadPoolJobScheduler(org.neo4j.test.scheduler.ThreadPoolJobScheduler) Test(org.junit.jupiter.api.Test)

Example 13 with IndexEntryUpdate

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

the class BlockBasedIndexPopulator method newPopulatingUpdater.

@Override
public IndexUpdater newPopulatingUpdater(CursorContext cursorContext) {
    if (scanCompleted) {
        // Will need the reader from newReader, which a sub-class of this class implements
        return new DelegatingIndexUpdater(super.newPopulatingUpdater(cursorContext)) {

            @Override
            public void process(IndexEntryUpdate<?> update) throws IndexEntryConflictException {
                ValueIndexEntryUpdate<?> valueUpdate = asValueUpdate(update);
                validateUpdate(valueUpdate);
                numberOfIndexUpdatesSinceSample.incrementAndGet();
                super.process(valueUpdate);
            }
        };
    }
    return new IndexUpdater() {

        private volatile boolean closed;

        @Override
        public void process(IndexEntryUpdate<?> update) {
            assertOpen();
            ValueIndexEntryUpdate<?> valueUpdate = asValueUpdate(update);
            try {
                validateUpdate(valueUpdate);
                externalUpdates.add(valueUpdate);
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        }

        @Override
        public void close() {
            closed = true;
        }

        private void assertOpen() {
            if (closed) {
                throw new IllegalStateException("Updater has been closed");
            }
        }
    };
}
Also used : IndexEntryUpdate(org.neo4j.storageengine.api.IndexEntryUpdate) ValueIndexEntryUpdate(org.neo4j.storageengine.api.ValueIndexEntryUpdate) DelegatingIndexUpdater(org.neo4j.kernel.impl.api.index.updater.DelegatingIndexUpdater) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) DelegatingIndexUpdater(org.neo4j.kernel.impl.api.index.updater.DelegatingIndexUpdater)

Example 14 with IndexEntryUpdate

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

the class NonUniqueDatabaseIndexPopulatorTest method addUpdates.

@Test
void addUpdates() throws Exception {
    populator = newPopulator();
    List<IndexEntryUpdate<?>> updates = Arrays.asList(add(1, labelSchemaDescriptor, "foo"), add(2, labelSchemaDescriptor, "bar"), add(42, labelSchemaDescriptor, "bar"));
    populator.add(updates, NULL);
    index.maybeRefreshBlocking();
    try (ValueIndexReader reader = index.getIndexReader();
        NodeValueIterator allEntities = new NodeValueIterator()) {
        int propertyKeyId = labelSchemaDescriptor.getPropertyId();
        reader.query(NULL_CONTEXT, allEntities, unconstrained(), PropertyIndexQuery.exists(propertyKeyId));
        assertArrayEquals(new long[] { 1, 2, 42 }, PrimitiveLongCollections.asArray(allEntities));
    }
}
Also used : NodeValueIterator(org.neo4j.kernel.impl.index.schema.NodeValueIterator) IndexEntryUpdate(org.neo4j.storageengine.api.IndexEntryUpdate) ValueIndexReader(org.neo4j.kernel.api.index.ValueIndexReader) Test(org.junit.jupiter.api.Test)

Example 15 with IndexEntryUpdate

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

the class NonUniqueDatabaseIndexPopulatorTest method sampleIncludedUpdates.

@Test
void sampleIncludedUpdates() {
    populator = newPopulator();
    List<IndexEntryUpdate<?>> updates = Arrays.asList(add(1, labelSchemaDescriptor, "aaa"), add(2, labelSchemaDescriptor, "bbb"), add(3, labelSchemaDescriptor, "ccc"));
    populator.add(updates, NULL);
    IndexSample sample = populator.sample(NULL);
    assertEquals(new IndexSample(3, 3, 3), sample);
}
Also used : IndexEntryUpdate(org.neo4j.storageengine.api.IndexEntryUpdate) IndexSample(org.neo4j.kernel.api.index.IndexSample) Test(org.junit.jupiter.api.Test)

Aggregations

IndexEntryUpdate (org.neo4j.storageengine.api.IndexEntryUpdate)24 Test (org.junit.jupiter.api.Test)18 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)6 IndexSample (org.neo4j.kernel.api.index.IndexSample)6 IndexUpdater (org.neo4j.kernel.api.index.IndexUpdater)6 Value (org.neo4j.values.storable.Value)6 ArrayList (java.util.ArrayList)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 IndexPopulator (org.neo4j.kernel.api.index.IndexPopulator)4 ByteBufferFactory (org.neo4j.io.memory.ByteBufferFactory)3 ThreadSafePeakMemoryTracker (org.neo4j.memory.ThreadSafePeakMemoryTracker)3 ValueIndexEntryUpdate (org.neo4j.storageengine.api.ValueIndexEntryUpdate)3 PointValue (org.neo4j.values.storable.PointValue)3 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 ExecutorService (java.util.concurrent.ExecutorService)2 TokenNameLookup (org.neo4j.common.TokenNameLookup)2 Transaction (org.neo4j.graphdb.Transaction)2 LabelSchemaDescriptor (org.neo4j.internal.schema.LabelSchemaDescriptor)2 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)2