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})");
}
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
}
Aggregations