use of org.neo4j.internal.recordstorage.SchemaRuleAccess in project neo4j by neo4j.
the class DropBrokenUniquenessConstraintIT method shouldDropUniquenessConstraintWithBackingIndexHavingNoOwner.
@Test
void shouldDropUniquenessConstraintWithBackingIndexHavingNoOwner() throws KernelException {
// 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();
writeSchemaRulesWithoutConstraint(schemaRules);
// At this point the SchemaCache doesn't know about this change so we have to reload it
storageEngine.loadSchemaCache();
try (Transaction tx = db.beginTx()) {
single(tx.schema().getConstraints(label).iterator()).drop();
tx.commit();
}
// then
// AfterEach
}
use of org.neo4j.internal.recordstorage.SchemaRuleAccess in project neo4j by neo4j.
the class DropBrokenUniquenessConstraintIT method shouldDropUniquenessConstraintWhereConstraintRecordIsMissingAndIndexHasNoOwner.
@Test
void shouldDropUniquenessConstraintWhereConstraintRecordIsMissingAndIndexHasNoOwner() throws KernelException {
// 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));
writeSchemaRulesWithoutConstraint(schemaRules);
// 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
}
use of org.neo4j.internal.recordstorage.SchemaRuleAccess in project neo4j by neo4j.
the class DropBrokenUniquenessConstraintIT method shouldDropUniquenessConstraintWithBackingIndexNotInUse.
@Test
void shouldDropUniquenessConstraintWithBackingIndexNotInUse() {
// given
String backingIndexName;
try (Transaction tx = db.beginTx()) {
tx.schema().constraintFor(label).assertPropertyIsUnique(key).create();
backingIndexName = single(tx.schema().getIndexes(label).iterator()).getName();
tx.commit();
}
// when intentionally breaking the schema by setting the backing index rule to unused
SchemaRuleAccess schemaRules = storageEngine.testAccessSchemaRules();
schemaRules.deleteSchemaRule(schemaRules.indexGetForName(backingIndexName, NULL), 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()) {
single(tx.schema().getConstraints(label).iterator()).drop();
tx.commit();
}
// then
// AfterEach
}
use of org.neo4j.internal.recordstorage.SchemaRuleAccess in project neo4j by neo4j.
the class BatchInsertTest method shouldCreateConsistentUniquenessConstraint.
@ParameterizedTest
@MethodSource("params")
void shouldCreateConsistentUniquenessConstraint(int denseNodeThreshold) throws Exception {
// given
BatchInserter inserter = newBatchInserter(denseNodeThreshold);
// when
inserter.createDeferredConstraint(label("Hacker")).assertPropertyIsUnique("handle").create();
// then
GraphDatabaseAPI graphdb = switchToEmbeddedGraphDatabaseService(inserter, denseNodeThreshold);
try {
NeoStores neoStores = graphdb.getDependencyResolver().resolveDependency(RecordStorageEngine.class).testAccessNeoStores();
SchemaStore store = neoStores.getSchemaStore();
TokenHolders tokenHolders = graphdb.getDependencyResolver().resolveDependency(TokenHolders.class);
SchemaRuleAccess schemaRuleAccess = SchemaRuleAccess.getSchemaRuleAccess(store, tokenHolders, () -> KernelVersion.LATEST);
List<Long> inUse = new ArrayList<>();
SchemaRecord record = store.newRecord();
for (long i = 1, high = store.getHighestPossibleIdInUse(NULL); i <= high; i++) {
store.getRecord(i, record, RecordLoad.FORCE, NULL);
if (record.inUse()) {
inUse.add(i);
}
}
assertEquals(2, inUse.size(), "records in use");
SchemaRule rule0 = schemaRuleAccess.loadSingleSchemaRule(inUse.get(0), NULL);
SchemaRule rule1 = schemaRuleAccess.loadSingleSchemaRule(inUse.get(1), NULL);
IndexDescriptor indexRule;
ConstraintDescriptor constraint;
if (rule0 instanceof IndexDescriptor) {
indexRule = (IndexDescriptor) rule0;
constraint = (ConstraintDescriptor) rule1;
} else {
constraint = (ConstraintDescriptor) rule0;
indexRule = (IndexDescriptor) rule1;
}
OptionalLong owningConstraintId = indexRule.getOwningConstraintId();
assertTrue(owningConstraintId.isPresent(), "index should have owning constraint");
assertEquals(constraint.getId(), owningConstraintId.getAsLong(), "index should reference constraint");
assertEquals(indexRule.getId(), constraint.asIndexBackedConstraint().ownedIndexId(), "constraint should reference index");
} finally {
managementService.shutdown();
}
}
use of org.neo4j.internal.recordstorage.SchemaRuleAccess in project neo4j by neo4j.
the class FullCheckIntegrationTest method writeToSchemaStore.
private void writeToSchemaStore(SchemaStore schemaStore, SchemaRule rule) throws KernelException {
SchemaRuleAccess schemaRuleAccess = SchemaRuleAccess.getSchemaRuleAccess(schemaStore, fixture.writableTokenHolders(), () -> KernelVersion.LATEST);
schemaRuleAccess.writeSchemaRule(rule, NULL, INSTANCE);
}
Aggregations