Search in sources :

Example 26 with IndexUpdater

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

the class UniqueDatabaseIndexPopulatorTest method shouldCheckAllCollisionsFromPopulatorAdd.

@Test
void shouldCheckAllCollisionsFromPopulatorAdd() throws Exception {
    // given
    populator = newPopulator();
    // This value has to be high enough to stress the EntrySet implementation
    int iterations = 228;
    IndexUpdater updater = populator.newPopulatingUpdater(nodePropertyAccessor, NULL);
    for (int nodeId = 0; nodeId < iterations; nodeId++) {
        updater.process(add(nodeId, schemaDescriptor, "1"));
        when(nodePropertyAccessor.getNodePropertyValue(nodeId, PROPERTY_KEY_ID, NULL)).thenReturn(Values.of(nodeId));
    }
    // ... and the actual conflicting property:
    updater.process(add(iterations, schemaDescriptor, "1"));
    when(nodePropertyAccessor.getNodePropertyValue(iterations, PROPERTY_KEY_ID, NULL)).thenReturn(// This collision is real!!!
    Values.of(1));
    // when
    var conflict = assertThrows(IndexEntryConflictException.class, updater::close);
    assertEquals(1, conflict.getExistingNodeId());
    assertEquals(Values.of(1), conflict.getSinglePropertyValue());
    assertEquals(iterations, conflict.getAddedNodeId());
}
Also used : IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) Test(org.junit.jupiter.api.Test)

Example 27 with IndexUpdater

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

the class NodeCheckerTest method shouldReportNodeDoesNotHaveExpectedLabel.

@Test
void shouldReportNodeDoesNotHaveExpectedLabel() throws Exception {
    // given
    try (AutoCloseable ignored = tx()) {
        // (N) w/ label L
        // LabelIndex does not have the N:L entry
        long nodeId = node(nodeStore.nextId(CursorContext.NULL), NULL, NULL);
        try (IndexUpdater writer = labelIndexWriter()) {
            writer.process(IndexEntryUpdate.change(nodeId, IndexDescriptor.NO_INDEX, EMPTY_LONG_ARRAY, new long[] { label1 }));
        }
    }
    // when
    check();
    // then
    expect(LabelScanConsistencyReport.class, report -> report.nodeDoesNotHaveExpectedLabel(any(), anyLong()));
}
Also used : IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) Test(org.junit.jupiter.api.Test)

Example 28 with IndexUpdater

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

the class NodeCheckerTest method shouldReportNodeNotInUse.

@Test
void shouldReportNodeNotInUse() throws Exception {
    // given
    try (AutoCloseable ignored = tx()) {
        // A couple of nodes w/ correct label indexing
        try (IndexUpdater writer = labelIndexWriter()) {
            for (int i = 0; i < 10; i++) {
                long nodeId = node(nodeStore.nextId(CursorContext.NULL), NULL, NULL, label1);
                writer.process(IndexEntryUpdate.change(nodeId, IndexDescriptor.NO_INDEX, EMPTY_LONG_ARRAY, new long[] { label1 }));
            }
        }
        // Label index having (N) which is not in use in the store
        try (IndexUpdater writer = labelIndexWriter()) {
            writer.process(IndexEntryUpdate.change(nodeStore.nextId(CursorContext.NULL), IndexDescriptor.NO_INDEX, EMPTY_LONG_ARRAY, new long[] { label1 }));
        }
    }
    // when
    check();
    // then
    expect(LabelScanConsistencyReport.class, report -> report.nodeNotInUse(any()));
}
Also used : IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) Test(org.junit.jupiter.api.Test)

Example 29 with IndexUpdater

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

the class NodeCheckerTest method shouldReportNodeNotInUseOnEmptyStore.

@Test
void shouldReportNodeNotInUseOnEmptyStore() throws Exception {
    // given
    try (AutoCloseable ignored = tx()) {
        // Label index having (N) which is not in use in the store
        try (IndexUpdater writer = labelIndexWriter()) {
            writer.process(IndexEntryUpdate.change(nodeStore.nextId(CursorContext.NULL), IndexDescriptor.NO_INDEX, EMPTY_LONG_ARRAY, new long[] { label1 }));
        }
    }
    // when
    check();
    // then
    expect(LabelScanConsistencyReport.class, report -> report.nodeNotInUse(any()));
}
Also used : IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) Test(org.junit.jupiter.api.Test)

Example 30 with IndexUpdater

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

the class LimitedFullCheckIT method shouldFindDuplicatesInUniqueIndexEvenWhenInDifferentRanges.

@Test
void shouldFindDuplicatesInUniqueIndexEvenWhenInDifferentRanges() throws ConsistencyCheckIncompleteException, IndexEntryConflictException, IOException {
    // given
    Iterator<IndexDescriptor> indexRuleIterator = getValueIndexDescriptors();
    // Create 2 extra nodes to guarantee that the node id of our duplicate is not in the same range as the original entry.
    createOneNode();
    createOneNode();
    // Create a node so the duplicate in the index refers to a valid node
    // (IndexChecker only reports the duplicate if it refers to a node id lower than highId)
    long nodeId = createOneNode();
    while (indexRuleIterator.hasNext()) {
        IndexDescriptor indexRule = indexRuleIterator.next();
        // Don't close this accessor. It will be done when shutting down db.
        IndexAccessor accessor = fixture.indexAccessorLookup().apply(indexRule);
        try (IndexUpdater updater = accessor.newUpdater(IndexUpdateMode.ONLINE, NULL)) {
            // There is already another node (created in generateInitialData()) that has this value
            updater.process(IndexEntryUpdate.add(nodeId, indexRule, values(indexRule)));
        }
        accessor.force(NULL);
    }
    // when
    ConsistencySummaryStatistics stats = check();
    // then
    // the duplicate in unique index
    on(stats).verify(RecordType.NODE, 1).verify(RecordType.INDEX, // the index entries pointing to node that should not be in index
    3).andThatsAllFolks();
}
Also used : IndexAccessor(org.neo4j.kernel.api.index.IndexAccessor) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) ConsistencySummaryStatistics(org.neo4j.consistency.report.ConsistencySummaryStatistics) Test(org.junit.jupiter.api.Test) FullCheckIntegrationTest(org.neo4j.consistency.checking.full.FullCheckIntegrationTest)

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