Search in sources :

Example 71 with IndexUpdater

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

the class FullCheckIntegrationTest method shouldReportRelationshipTypeIndexInconsistencies1.

@Test
void shouldReportRelationshipTypeIndexInconsistencies1() throws Exception {
    // given
    // relationship present in type index but not in store
    GraphStoreFixture.IdGenerator idGenerator = fixture.idGenerator();
    long relationshipId = idGenerator.relationship();
    long relationshipTypeId = idGenerator.relationshipType() - 1;
    IndexDescriptor rtiDescriptor = findTokenIndex(fixture, EntityType.RELATIONSHIP);
    IndexAccessor accessor = fixture.indexAccessorLookup().apply(rtiDescriptor);
    try (IndexUpdater indexUpdater = accessor.newUpdater(IndexUpdateMode.ONLINE, NULL)) {
        indexUpdater.process(IndexEntryUpdate.change(relationshipId, rtiDescriptor, new long[] {}, new long[] { relationshipTypeId }));
    }
    // when
    ConsistencySummaryStatistics stats = check();
    // then
    on(stats).verify(RecordType.RELATIONSHIP_TYPE_SCAN_DOCUMENT, 1).andThatsAllFolks();
}
Also used : IndexAccessor(org.neo4j.kernel.api.index.IndexAccessor) IdGenerator(org.neo4j.consistency.checking.GraphStoreFixture.IdGenerator) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) GraphStoreFixture(org.neo4j.consistency.checking.GraphStoreFixture) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) ConsistencySummaryStatistics(org.neo4j.consistency.report.ConsistencySummaryStatistics) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 72 with IndexUpdater

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

the class SpecialisedIndexFullCheckTest method shouldReportNodesThatAreIndexedWhenTheyShouldNotBe.

@ParameterizedTest
@EnumSource(IndexSize.class)
void shouldReportNodesThatAreIndexedWhenTheyShouldNotBe(IndexSize indexSize) throws Exception {
    indexSize.createAdditionalData(fixture);
    // given
    long newNode = createOneNode();
    Iterator<IndexDescriptor> indexDescriptorIterator = getValueIndexDescriptors();
    while (indexDescriptorIterator.hasNext()) {
        IndexDescriptor indexDescriptor = indexDescriptorIterator.next();
        IndexAccessor accessor = fixture.indexAccessorLookup().apply(indexDescriptor);
        try (IndexUpdater updater = accessor.newUpdater(IndexUpdateMode.ONLINE, NULL)) {
            updater.process(IndexEntryUpdate.add(newNode, indexDescriptor, values(indexDescriptor)));
        }
    }
    // when
    ConsistencySummaryStatistics stats = check();
    assertFalse(stats.isConsistent());
    RecordType recordType = indexSize == IndexSize.SMALL_INDEX ? RecordType.INDEX : RecordType.NODE;
    assertThat(stats.getInconsistencyCountForRecordType(recordType)).isEqualTo(2);
}
Also used : RecordType(org.neo4j.consistency.RecordType) 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) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 73 with IndexUpdater

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

the class ReadEntityIdsStepUsingTokenIndexTest method populateTokenIndex.

private void populateTokenIndex(TokenIndexAccessor indexAccessor, BitSet entityIds, long count) throws Exception {
    try (IndexUpdater updater = indexAccessor.newUpdater(ONLINE, CursorContext.NULL)) {
        long id = 0;
        for (int i = 0; i < count; i++) {
            updater.process(IndexEntryUpdate.change(id, INDEX_DESCRIPTOR, EMPTY_LONG_ARRAY, new long[] { TOKEN_ID }));
            entityIds.set((int) id);
            id += random.nextInt(1, 5);
        }
    }
}
Also used : IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater)

Example 74 with IndexUpdater

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

the class NodeCheckerTest method shouldReportNodeLabelNotInIndexMiddleNode.

@Test
void shouldReportNodeLabelNotInIndexMiddleNode() throws Exception {
    // given
    try (AutoCloseable ignored = tx()) {
        try (IndexUpdater writer = labelIndexWriter()) {
            for (int i = 0; i < 20; i++) {
                long nodeId = node(nodeStore.nextId(CursorContext.NULL), NULL, NULL, label1, label2);
                // node 10 missing label2 in index
                writer.process(IndexEntryUpdate.change(nodeId, IndexDescriptor.NO_INDEX, EMPTY_LONG_ARRAY, i == 10 ? new long[] { label1 } : new long[] { label1, label2 }));
            }
        }
    }
    // when
    check();
    // then
    expect(LabelScanConsistencyReport.class, report -> report.nodeLabelNotInIndex(any(), anyLong()));
}
Also used : IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) Test(org.junit.jupiter.api.Test)

Example 75 with IndexUpdater

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

the class RelationshipCheckerWithRelationshipTypeIndexTest method storeHasBigGapButIndexDoesNot.

@Test
void storeHasBigGapButIndexDoesNot() throws Exception {
    // given
    try (Transaction tx = db.beginTx();
        IndexUpdater writer = relationshipTypeIndexWriter()) {
        for (int i = 0; i < 2 * IDS_PER_CHUNK; i++) {
            if (i == 0) {
                createCompleteEntry(writer, type);
            } else if (i == 10) {
                long relationshipId = createStoreEntry(type);
                notInUse(relationshipId);
                createIndexEntry(writer, relationshipId, type);
            } else if (i == IDS_PER_CHUNK - 1) {
                createCompleteEntry(writer, type);
            } else {
                long relationshipId = createStoreEntry(type);
                notInUse(relationshipId);
            }
        }
        tx.commit();
    }
    // when
    check();
    // then
    expect(ConsistencyReport.RelationshipTypeScanConsistencyReport.class, reporter -> reporter.relationshipNotInUse(any()));
}
Also used : Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) ConsistencyReport(org.neo4j.consistency.report.ConsistencyReport) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

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