Search in sources :

Example 21 with SchemaRule

use of org.neo4j.internal.schema.SchemaRule in project neo4j by neo4j.

the class TransactionRecordState method schemaRuleDelete.

void schemaRuleDelete(long ruleId, SchemaRule rule) {
    RecordProxy<SchemaRecord, SchemaRule> proxy = recordChangeSet.getSchemaRuleChanges().getOrLoad(ruleId, rule, cursorContext);
    SchemaRecord record = proxy.forReadingData();
    if (record.inUse()) {
        record = proxy.forChangingData();
        record.setInUse(false);
        getAndDeletePropertyChain(record);
    }
// Index schema rules may be deleted twice, if they were owned by a constraint; once for dropping the index, and then again as part of
// dropping the constraint. So we keep this method idempotent.
}
Also used : SchemaRecord(org.neo4j.kernel.impl.store.record.SchemaRecord) SchemaRule(org.neo4j.internal.schema.SchemaRule)

Example 22 with SchemaRule

use of org.neo4j.internal.schema.SchemaRule in project neo4j by neo4j.

the class SchemaRuleMigrationTest method constraintsWithoutNamesMustBeGivenGeneratedOnes.

@Test
void constraintsWithoutNamesMustBeGivenGeneratedOnes() throws KernelException {
    SchemaRule rule = ConstraintDescriptorFactory.uniqueForSchema(SchemaDescriptor.forLabel(1, 2)).withId(1);
    srcTokenHolders.labelTokens().setInitialTokens(List.of(new NamedToken("Label", 1)));
    srcTokenHolders.propertyKeyTokens().setInitialTokens(List.of(new NamedToken("prop", 2)));
    when(src.getAll(any())).thenReturn(List.of(rule));
    RecordStorageMigrator.migrateSchemaRules(srcTokenHolders, src, dst, NULL);
    assertEquals(1, writtenRules.size());
    assertEquals("constraint_952591e6", writtenRules.get(0).getName());
}
Also used : SchemaRule(org.neo4j.internal.schema.SchemaRule) NamedToken(org.neo4j.token.api.NamedToken) Test(org.junit.jupiter.api.Test)

Example 23 with SchemaRule

use of org.neo4j.internal.schema.SchemaRule in project neo4j by neo4j.

the class SchemaRuleMigrationTest method mustEnsureThatMigratedSchemaRuleNamesAreUnique.

@Test
void mustEnsureThatMigratedSchemaRuleNamesAreUnique() throws KernelException {
    SchemaRule rule1 = IndexPrototype.forSchema(SchemaDescriptor.forLabel(1, 2)).withName("a").materialise(1);
    SchemaRule rule2 = IndexPrototype.forSchema(SchemaDescriptor.forLabel(1, 3)).withName("a").materialise(2);
    srcTokenHolders.labelTokens().setInitialTokens(List.of(new NamedToken("Label", 1)));
    srcTokenHolders.propertyKeyTokens().setInitialTokens(List.of(new NamedToken("a", 2), new NamedToken("b", 3)));
    when(src.getAll(any())).thenReturn(List.of(rule1, rule2));
    RecordStorageMigrator.migrateSchemaRules(srcTokenHolders, src, dst, NULL);
    long distinctNames = writtenRules.stream().map(SchemaRule::getName).distinct().count();
    assertEquals(2, distinctNames);
}
Also used : SchemaRule(org.neo4j.internal.schema.SchemaRule) NamedToken(org.neo4j.token.api.NamedToken) Test(org.junit.jupiter.api.Test)

Example 24 with SchemaRule

use of org.neo4j.internal.schema.SchemaRule in project neo4j by neo4j.

the class SchemaRuleMigrationTest method mustEnsureUniqueNamesEvenWhenOldNamesMatchesNewDefaults.

@Test
void mustEnsureUniqueNamesEvenWhenOldNamesMatchesNewDefaults() throws KernelException {
    SchemaRule rule1 = ConstraintDescriptorFactory.uniqueForSchema(SchemaDescriptor.forLabel(1, 2)).withId(1);
    SchemaRule rule2 = ConstraintDescriptorFactory.uniqueForSchema(SchemaDescriptor.forLabel(1, 2)).withId(2);
    srcTokenHolders.labelTokens().setInitialTokens(List.of(new NamedToken("Label", 1)));
    srcTokenHolders.propertyKeyTokens().setInitialTokens(List.of(new NamedToken("prop", 2), new NamedToken("bla", 3)));
    when(src.getAll(any())).thenReturn(List.of(rule1, rule2));
    RecordStorageMigrator.migrateSchemaRules(srcTokenHolders, src, dst, NULL);
    assertEquals(2, writtenRules.size());
    Set<String> names = writtenRules.stream().map(SchemaRule::getName).collect(Collectors.toSet());
    // Collisions in generated names (however fantastically unlikely) must be resolved by appending a count.
    assertEquals(Set.of("constraint_952591e6", "constraint_952591e6_1"), names);
}
Also used : SchemaRule(org.neo4j.internal.schema.SchemaRule) NamedToken(org.neo4j.token.api.NamedToken) Test(org.junit.jupiter.api.Test)

Example 25 with SchemaRule

use of org.neo4j.internal.schema.SchemaRule in project neo4j by neo4j.

the class SchemaStore35Test method storeAndLoadAllRules.

@Test
void storeAndLoadAllRules() {
    // GIVEN
    long indexId = store.nextId(NULL);
    long constraintId = store.nextId(NULL);
    Collection<SchemaRule> rules = Arrays.asList(uniqueIndexRule(indexId, constraintId, 2, 5, 3), constraintUniqueRule(constraintId, indexId, 2, 5, 3), indexRule(store.nextId(NULL), 0, 5), indexRule(store.nextId(NULL), 1, 6, 10, 99), constraintExistsRule(store.nextId(NULL), 5, 1));
    for (SchemaRule rule : rules) {
        storeRule(rule);
    }
    // WHEN
    SchemaStorage35 storage35 = new SchemaStorage35(store);
    Collection<SchemaRule> readRules = asCollection(storage35.getAll(NULL));
    // THEN
    assertEquals(rules, readRules);
}
Also used : SchemaRule(org.neo4j.internal.schema.SchemaRule) Test(org.junit.jupiter.api.Test)

Aggregations

SchemaRule (org.neo4j.internal.schema.SchemaRule)29 SchemaRecord (org.neo4j.kernel.impl.store.record.SchemaRecord)12 Test (org.junit.jupiter.api.Test)8 ArrayList (java.util.ArrayList)7 MalformedSchemaRuleException (org.neo4j.internal.kernel.api.exceptions.schema.MalformedSchemaRuleException)5 ConstraintDescriptor (org.neo4j.internal.schema.ConstraintDescriptor)5 TokenHolders (org.neo4j.token.TokenHolders)5 NamedToken (org.neo4j.token.api.NamedToken)5 RepeatedTest (org.junit.jupiter.api.RepeatedTest)4 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)4 NeoStores (org.neo4j.kernel.impl.store.NeoStores)4 DynamicRecord (org.neo4j.kernel.impl.store.record.DynamicRecord)3 PropertyRecord (org.neo4j.kernel.impl.store.record.PropertyRecord)3 OptionalLong (java.util.OptionalLong)2 MutableLongSet (org.eclipse.collections.api.set.primitive.MutableLongSet)2 LongHashSet (org.eclipse.collections.impl.set.mutable.primitive.LongHashSet)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 MethodSource (org.junit.jupiter.params.provider.MethodSource)2 DefaultIdGeneratorFactory (org.neo4j.internal.id.DefaultIdGeneratorFactory)2 SchemaStore (org.neo4j.kernel.impl.store.SchemaStore)2