Search in sources :

Example 76 with IndexUpdater

use of org.neo4j.kernel.api.index.IndexUpdater in project neo4j by neo4j.

the class FulltextIndexConsistencyCheckIT method mustDiscoverRelationshipInStoreMissingFromIndex.

@Test
void mustDiscoverRelationshipInStoreMissingFromIndex() throws Exception {
    GraphDatabaseService db = createDatabase();
    try (Transaction tx = db.beginTx()) {
        tx.execute(format(RELATIONSHIP_CREATE, "rels", asStrList("REL"), asStrList("prop"))).close();
        tx.commit();
    }
    IndexDescriptor indexDescriptor;
    long relId;
    try (Transaction tx = db.beginTx()) {
        tx.schema().awaitIndexesOnline(2, TimeUnit.MINUTES);
        indexDescriptor = getFulltextIndexDescriptor(tx.schema().getIndexes());
        Node node = tx.createNode();
        Relationship rel = node.createRelationshipTo(node, RelationshipType.withName("REL"));
        rel.setProperty("prop", "value");
        relId = rel.getId();
        tx.commit();
    }
    IndexingService indexes = getIndexingService(db);
    IndexProxy indexProxy = indexes.getIndexProxy(indexDescriptor);
    try (IndexUpdater updater = indexProxy.newUpdater(IndexUpdateMode.ONLINE, NULL)) {
        updater.process(IndexEntryUpdate.remove(relId, indexDescriptor, Values.stringValue("value")));
    }
    managementService.shutdown();
    ConsistencyCheckService.Result result = checkConsistency();
    assertFalse(result.isSuccessful());
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) IndexProxy(org.neo4j.kernel.impl.api.index.IndexProxy) ConsistencyCheckService(org.neo4j.consistency.ConsistencyCheckService) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) Test(org.junit.jupiter.api.Test)

Example 77 with IndexUpdater

use of org.neo4j.kernel.api.index.IndexUpdater in project neo4j by neo4j.

the class BlockBasedIndexPopulatorTest method shouldBuildNonUniqueSampleAsPartOfScanCompleted.

@Test
void shouldBuildNonUniqueSampleAsPartOfScanCompleted() throws IndexEntryConflictException, IOException {
    // given
    ThreadSafePeakMemoryTracker memoryTracker = new ThreadSafePeakMemoryTracker();
    ByteBufferFactory bufferFactory = new ByteBufferFactory(UnsafeDirectByteBufferAllocator::new, 100);
    BlockBasedIndexPopulator<GenericKey, NativeIndexValue> populator = instantiatePopulator(NO_MONITOR, bufferFactory, memoryTracker);
    Collection<IndexEntryUpdate<?>> populationUpdates = batchOfUpdates();
    populator.add(populationUpdates, NULL);
    // when
    populator.scanCompleted(nullInstance, populationWorkScheduler, NULL);
    // Also a couple of updates afterwards
    int numberOfUpdatesAfterCompleted = 4;
    try (IndexUpdater updater = populator.newPopulatingUpdater(NULL)) {
        for (int i = 0; i < numberOfUpdatesAfterCompleted; i++) {
            updater.process(IndexEntryUpdate.add(10_000 + i, SCHEMA_DESCRIPTOR, intValue(i)));
        }
    }
    populator.close(true, NULL);
    // then
    IndexSample sample = populator.sample(NULL);
    assertEquals(populationUpdates.size(), sample.indexSize());
    assertEquals(populationUpdates.size(), sample.sampleSize());
    assertEquals(populationUpdates.size(), sample.uniqueValues());
    assertEquals(numberOfUpdatesAfterCompleted, sample.updates());
}
Also used : IndexEntryUpdate(org.neo4j.storageengine.api.IndexEntryUpdate) IndexSample(org.neo4j.kernel.api.index.IndexSample) ThreadSafePeakMemoryTracker(org.neo4j.memory.ThreadSafePeakMemoryTracker) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) ByteBufferFactory(org.neo4j.io.memory.ByteBufferFactory) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 78 with IndexUpdater

use of org.neo4j.kernel.api.index.IndexUpdater in project neo4j by neo4j.

the class BlockBasedIndexPopulatorTest method shouldCountExternalUpdatesAsSampleUpdates.

@Test
void shouldCountExternalUpdatesAsSampleUpdates() throws IOException, IndexEntryConflictException {
    // given
    BlockBasedIndexPopulator<GenericKey, NativeIndexValue> populator = instantiatePopulator(NO_MONITOR);
    try {
        populator.add(List.of(add(0), add(1)), NULL);
        try (IndexUpdater updater = populator.newPopulatingUpdater(NULL)) {
            updater.process(add(10));
            updater.process(add(11));
            updater.process(add(12));
        }
        // when
        populator.scanCompleted(nullInstance, populationWorkScheduler, NULL);
        try (IndexUpdater updater = populator.newPopulatingUpdater(NULL)) {
            updater.process(remove(10));
        }
        // then
        IndexSample sample = populator.sample(NULL);
        assertThat(sample.updates()).isEqualTo(4);
    } finally {
        populator.close(true, NULL);
    }
}
Also used : IndexSample(org.neo4j.kernel.api.index.IndexSample) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 79 with IndexUpdater

use of org.neo4j.kernel.api.index.IndexUpdater in project neo4j by neo4j.

the class DeferredConflictCheckingIndexUpdaterTest method shouldThrowOnIndexEntryConflict.

@Test
void shouldThrowOnIndexEntryConflict() throws Exception {
    // given
    IndexUpdater actual = mock(IndexUpdater.class);
    ValueIndexReader reader = mock(ValueIndexReader.class);
    doAnswer(new NodeIdsIndexReaderQueryAnswer(descriptor, 101, 202)).when(reader).query(any(), any(), any(), any());
    DeferredConflictCheckingIndexUpdater updater = new DeferredConflictCheckingIndexUpdater(actual, () -> reader, descriptor, NULL);
    // when
    updater.process(add(0, descriptor, tuple(10, 11)));
    var e = assertThrows(IndexEntryConflictException.class, updater::close);
    assertThat(e.getMessage()).contains("101");
    assertThat(e.getMessage()).contains("202");
}
Also used : IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) ValueIndexReader(org.neo4j.kernel.api.index.ValueIndexReader) Test(org.junit.jupiter.api.Test)

Example 80 with IndexUpdater

use of org.neo4j.kernel.api.index.IndexUpdater in project neo4j by neo4j.

the class GenericBlockBasedIndexPopulatorTest method shouldNotThrowOnDuplicationsLaterFixedByExternalUpdates.

@Test
void shouldNotThrowOnDuplicationsLaterFixedByExternalUpdates() throws IndexEntryConflictException, IOException {
    // given
    BlockBasedIndexPopulator<GenericKey, NativeIndexValue> populator = instantiatePopulator(UNIQUE_INDEX_DESCRIPTOR);
    try {
        // when
        Value duplicate = Values.of("duplicate");
        Value unique = Values.of("unique");
        ValueIndexEntryUpdate<?> firstScanUpdate = ValueIndexEntryUpdate.add(1, INDEX_DESCRIPTOR, duplicate);
        ValueIndexEntryUpdate<?> secondScanUpdate = ValueIndexEntryUpdate.add(2, INDEX_DESCRIPTOR, duplicate);
        ValueIndexEntryUpdate<?> externalUpdate = ValueIndexEntryUpdate.change(1, INDEX_DESCRIPTOR, duplicate, unique);
        populator.add(singleton(firstScanUpdate), NULL);
        try (IndexUpdater updater = populator.newPopulatingUpdater(NULL)) {
            updater.process(externalUpdate);
        }
        populator.add(singleton(secondScanUpdate), NULL);
        populator.scanCompleted(nullInstance, populationWorkScheduler, NULL);
        // then
        assertHasEntry(populator, unique, 1);
        assertHasEntry(populator, duplicate, 2);
    } finally {
        populator.close(true, NULL);
    }
}
Also used : Value(org.neo4j.values.storable.Value) TextValue(org.neo4j.values.storable.TextValue) Values.stringValue(org.neo4j.values.storable.Values.stringValue) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) Test(org.junit.jupiter.api.Test)

Aggregations

IndexUpdater (org.neo4j.kernel.api.index.IndexUpdater)94 Test (org.junit.jupiter.api.Test)61 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)22 ValueIndexEntryUpdate (org.neo4j.storageengine.api.ValueIndexEntryUpdate)13 IndexAccessor (org.neo4j.kernel.api.index.IndexAccessor)12 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)11 IndexPopulator (org.neo4j.kernel.api.index.IndexPopulator)9 Value (org.neo4j.values.storable.Value)9 ConsistencySummaryStatistics (org.neo4j.consistency.report.ConsistencySummaryStatistics)7 CursorContext (org.neo4j.io.pagecache.context.CursorContext)7 IndexEntryUpdate (org.neo4j.storageengine.api.IndexEntryUpdate)6 SwallowingIndexUpdater (org.neo4j.kernel.impl.api.index.SwallowingIndexUpdater)5 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 Transaction (org.neo4j.graphdb.Transaction)4 IndexEntryConflictException (org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException)4 SchemaIndexTestHelper.mockIndexProxy (org.neo4j.kernel.impl.api.index.SchemaIndexTestHelper.mockIndexProxy)4 NodePropertyAccessor (org.neo4j.storageengine.api.NodePropertyAccessor)4 HashMap (java.util.HashMap)3 EnumSource (org.junit.jupiter.params.provider.EnumSource)3