Search in sources :

Example 6 with SchemaRuleAccess

use of org.neo4j.internal.recordstorage.SchemaRuleAccess in project neo4j by neo4j.

the class IndexStatisticsIT method shouldRecoverIndexCountsBySamplingThemOnStartup.

@Test
void shouldRecoverIndexCountsBySamplingThemOnStartup() {
    // given some aliens in a database
    createAliens();
    // that have been indexed
    awaitIndexOnline(indexAliensBySpecimen());
    // where ALIEN and SPECIMEN are both the first ids of their kind
    IndexDescriptor index = TestIndexDescriptorFactory.forLabel(labelId(ALIEN), pkId(SPECIMEN));
    SchemaRuleAccess schemaRuleAccess = SchemaRuleAccess.getSchemaRuleAccess(neoStores().getSchemaStore(), resolveDependency(TokenHolders.class), () -> KernelVersion.LATEST);
    long indexId = single(schemaRuleAccess.indexGetForSchema(index, NULL)).getId();
    // for which we don't have index counts
    resetIndexCounts(indexId);
    // when we shutdown the database and restart it
    restart();
    // then we should have re-sampled the index
    IndexStatisticsStore indexStatisticsStore = indexStatistics();
    var indexSample = indexStatisticsStore.indexSample(indexId);
    assertEquals(0, indexSample.updates());
    assertEquals(32, indexSample.indexSize());
    assertEquals(16, indexSample.uniqueValues());
    assertEquals(32, indexSample.sampleSize());
    // and also
    assertLogExistsForRecoveryOn("(:Alien {specimen})");
}
Also used : IndexStatisticsStore(org.neo4j.kernel.impl.api.index.stats.IndexStatisticsStore) SchemaRuleAccess(org.neo4j.internal.recordstorage.SchemaRuleAccess) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) TokenHolders(org.neo4j.token.TokenHolders) Test(org.junit.jupiter.api.Test)

Example 7 with SchemaRuleAccess

use of org.neo4j.internal.recordstorage.SchemaRuleAccess in project neo4j by neo4j.

the class DropBrokenUniquenessConstraintIT method shouldDropUniquenessConstraintWhereConstraintRecordIsMissing.

@Test
void shouldDropUniquenessConstraintWhereConstraintRecordIsMissing() {
    // given
    try (Transaction tx = db.beginTx()) {
        tx.schema().constraintFor(label).assertPropertyIsUnique(key).create();
        tx.commit();
    }
    // when intentionally breaking the schema by setting the backing index rule to unused
    SchemaRuleAccess schemaRules = storageEngine.testAccessSchemaRules();
    schemaRules.constraintsGetAllIgnoreMalformed(NULL).forEachRemaining(rule -> schemaRules.deleteSchemaRule(rule, NULL));
    // At this point the SchemaCache doesn't know about this change so we have to reload it
    storageEngine.loadSchemaCache();
    try (Transaction tx = db.beginTx()) {
        // We don't use single() here, because it is okay for the schema cache reload to clean up after us.
        tx.schema().getConstraints(label).forEach(ConstraintDefinition::drop);
        tx.schema().getIndexes(label).forEach(IndexDefinition::drop);
        tx.commit();
    }
// then
// AfterEach
}
Also used : Transaction(org.neo4j.graphdb.Transaction) SchemaRuleAccess(org.neo4j.internal.recordstorage.SchemaRuleAccess) Test(org.junit.jupiter.api.Test)

Aggregations

SchemaRuleAccess (org.neo4j.internal.recordstorage.SchemaRuleAccess)7 Test (org.junit.jupiter.api.Test)5 Transaction (org.neo4j.graphdb.Transaction)4 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)2 TokenHolders (org.neo4j.token.TokenHolders)2 ArrayList (java.util.ArrayList)1 OptionalLong (java.util.OptionalLong)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 MethodSource (org.junit.jupiter.params.provider.MethodSource)1 BatchInserter (org.neo4j.batchinsert.BatchInserter)1 RecordStorageEngine (org.neo4j.internal.recordstorage.RecordStorageEngine)1 ConstraintDescriptor (org.neo4j.internal.schema.ConstraintDescriptor)1 SchemaRule (org.neo4j.internal.schema.SchemaRule)1 IndexStatisticsStore (org.neo4j.kernel.impl.api.index.stats.IndexStatisticsStore)1 NeoStores (org.neo4j.kernel.impl.store.NeoStores)1 SchemaStore (org.neo4j.kernel.impl.store.SchemaStore)1 SchemaRecord (org.neo4j.kernel.impl.store.record.SchemaRecord)1 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)1