Search in sources :

Example 1 with SchemaRuleCommand

use of org.neo4j.internal.recordstorage.Command.SchemaRuleCommand in project neo4j by neo4j.

the class Commands method createIndexRule.

public static SchemaRuleCommand createIndexRule(IndexProviderDescriptor providerDescriptor, long id, LabelSchemaDescriptor descriptor) {
    SchemaRule rule = IndexPrototype.forSchema(descriptor, providerDescriptor).withName("index_" + id).materialise(id);
    SchemaRecord before = new SchemaRecord(id).initialize(false, Record.NO_NEXT_PROPERTY.longValue());
    SchemaRecord after = new SchemaRecord(id).initialize(true, 33);
    return new SchemaRuleCommand(before, after, rule);
}
Also used : SchemaRuleCommand(org.neo4j.internal.recordstorage.Command.SchemaRuleCommand) SchemaRecord(org.neo4j.kernel.impl.store.record.SchemaRecord) SchemaRule(org.neo4j.internal.schema.SchemaRule)

Example 2 with SchemaRuleCommand

use of org.neo4j.internal.recordstorage.Command.SchemaRuleCommand in project neo4j by neo4j.

the class TransactionRecordStateTest method preparingConstraintRulesMustMarkSchemaRecordAsChanged.

@Test
void preparingConstraintRulesMustMarkSchemaRecordAsChanged() throws Exception {
    neoStores = createStores();
    TransactionRecordState state = newTransactionRecordState();
    long ruleId = neoStores.getSchemaStore().nextId(NULL);
    ConstraintDescriptor rule = ConstraintDescriptorFactory.existsForLabel(0, 1).withId(ruleId);
    state.schemaRuleCreate(ruleId, true, rule);
    List<StorageCommand> commands = new ArrayList<>();
    state.extractCommands(commands, INSTANCE);
    assertThat(commands.size()).isEqualTo(1);
    SchemaRuleCommand command = (SchemaRuleCommand) commands.get(0);
    assertThat(command.getMode()).isEqualTo(Command.Mode.CREATE);
    assertThat(command.getSchemaRule()).isEqualTo(rule);
    assertThat(command.getKey()).isEqualTo(ruleId);
    assertThat(command.getBefore().inUse()).isEqualTo(false);
    assertThat(command.getAfter().inUse()).isEqualTo(true);
    assertThat(command.getAfter().isConstraint()).isEqualTo(true);
    assertThat(command.getAfter().isCreated()).isEqualTo(true);
    assertThat(command.getAfter().getNextProp()).isEqualTo(Record.NO_NEXT_PROPERTY.longValue());
}
Also used : SchemaRuleCommand(org.neo4j.internal.recordstorage.Command.SchemaRuleCommand) ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor) StorageCommand(org.neo4j.storageengine.api.StorageCommand) ArrayList(java.util.ArrayList) LongArrayList(org.eclipse.collections.impl.list.mutable.primitive.LongArrayList) Test(org.junit.jupiter.api.Test)

Example 3 with SchemaRuleCommand

use of org.neo4j.internal.recordstorage.Command.SchemaRuleCommand in project neo4j by neo4j.

the class TransactionRecordStateTest method settingIndexOwnerMustAlsoUpdateIndexRuleEvenIfIndexOwnerPropertyFitsInExistingPropertyChain.

/**
 * This is important because we have transaction appliers that look for the schema record changes and inspect the attached schema rule.
 * These appliers will not know what to do with the modified property record. Specifically, the index activator needs to observe the schema record
 * update when an index owner is attached to it.
 */
@Test
void settingIndexOwnerMustAlsoUpdateIndexRuleEvenIfIndexOwnerPropertyFitsInExistingPropertyChain() throws Exception {
    neoStores = createStores();
    TransactionRecordState state = newTransactionRecordState();
    long ruleId = neoStores.getSchemaStore().nextId(NULL);
    IndexDescriptor rule = IndexPrototype.uniqueForSchema(forLabel(0, 1)).withName("constraint_" + ruleId).materialise(ruleId);
    state.schemaRuleCreate(ruleId, false, rule);
    state.schemaRuleSetProperty(ruleId, 42, Values.booleanValue(true), rule);
    apply(state);
    state = newTransactionRecordState();
    state.schemaRuleSetIndexOwner(rule, 13, 56, Values.longValue(13));
    List<StorageCommand> commands = new ArrayList<>();
    state.extractCommands(commands, INSTANCE);
    assertThat(commands.size()).isEqualTo(2);
    // Order matters. Props added before schema.
    PropertyCommand propCmd = (PropertyCommand) commands.get(0);
    assertThat(propCmd.getSchemaRuleId()).isEqualTo(ruleId);
    assertThat(propCmd.getBefore().inUse()).isEqualTo(true);
    assertThat(propCmd.getAfter().inUse()).isEqualTo(true);
    assertThat(propCmd.getAfter().isCreated()).isEqualTo(false);
    assertThat(propCmd.getAfter().getSchemaRuleId()).isEqualTo(ruleId);
    SchemaRuleCommand schemaCmd = (SchemaRuleCommand) commands.get(1);
    assertThat(schemaCmd.getSchemaRule()).isEqualTo(rule);
    assertThat(schemaCmd.getBefore().inUse()).isEqualTo(true);
    assertThat(schemaCmd.getBefore().getNextProp()).isEqualTo(propCmd.getKey());
    assertThat(schemaCmd.getAfter().inUse()).isEqualTo(true);
    assertThat(schemaCmd.getAfter().isCreated()).isEqualTo(false);
    assertThat(schemaCmd.getAfter().getNextProp()).isEqualTo(propCmd.getKey());
}
Also used : SchemaRuleCommand(org.neo4j.internal.recordstorage.Command.SchemaRuleCommand) StorageCommand(org.neo4j.storageengine.api.StorageCommand) ArrayList(java.util.ArrayList) LongArrayList(org.eclipse.collections.impl.list.mutable.primitive.LongArrayList) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) PropertyCommand(org.neo4j.internal.recordstorage.Command.PropertyCommand) Test(org.junit.jupiter.api.Test)

Example 4 with SchemaRuleCommand

use of org.neo4j.internal.recordstorage.Command.SchemaRuleCommand in project neo4j by neo4j.

the class TransactionRecordStateTest method settingIndexOwnerMustAlsoUpdateIndexRule.

@Test
void settingIndexOwnerMustAlsoUpdateIndexRule() throws Exception {
    neoStores = createStores();
    TransactionRecordState state = newTransactionRecordState();
    long ruleId = neoStores.getSchemaStore().nextId(NULL);
    IndexDescriptor rule = IndexPrototype.uniqueForSchema(forLabel(0, 1)).withName("index_" + ruleId).materialise(ruleId);
    state.schemaRuleCreate(ruleId, false, rule);
    apply(state);
    state = newTransactionRecordState();
    state.schemaRuleSetIndexOwner(rule, 13, 42, Values.longValue(13));
    List<StorageCommand> commands = new ArrayList<>();
    state.extractCommands(commands, INSTANCE);
    assertThat(commands.size()).isEqualTo(2);
    // Order matters. Props added before schema.
    PropertyCommand propCmd = (PropertyCommand) commands.get(0);
    assertThat(propCmd.getSchemaRuleId()).isEqualTo(ruleId);
    assertThat(propCmd.getBefore().inUse()).isEqualTo(false);
    assertThat(propCmd.getAfter().inUse()).isEqualTo(true);
    assertThat(propCmd.getAfter().isCreated()).isEqualTo(true);
    assertThat(propCmd.getAfter().getSchemaRuleId()).isEqualTo(ruleId);
    SchemaRuleCommand schemaCmd = (SchemaRuleCommand) commands.get(1);
    assertThat(schemaCmd.getSchemaRule()).isEqualTo(rule);
    assertThat(schemaCmd.getBefore().inUse()).isEqualTo(true);
    assertThat(schemaCmd.getBefore().getNextProp()).isEqualTo(Record.NO_NEXT_PROPERTY.longValue());
    assertThat(schemaCmd.getAfter().inUse()).isEqualTo(true);
    assertThat(schemaCmd.getAfter().isCreated()).isEqualTo(false);
    assertThat(schemaCmd.getAfter().getNextProp()).isEqualTo(propCmd.getKey());
}
Also used : SchemaRuleCommand(org.neo4j.internal.recordstorage.Command.SchemaRuleCommand) StorageCommand(org.neo4j.storageengine.api.StorageCommand) ArrayList(java.util.ArrayList) LongArrayList(org.eclipse.collections.impl.list.mutable.primitive.LongArrayList) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) PropertyCommand(org.neo4j.internal.recordstorage.Command.PropertyCommand) Test(org.junit.jupiter.api.Test)

Example 5 with SchemaRuleCommand

use of org.neo4j.internal.recordstorage.Command.SchemaRuleCommand in project neo4j by neo4j.

the class TransactionRecordStateTest method preparingIndexRulesMustMarkSchemaRecordAsChanged.

@Test
void preparingIndexRulesMustMarkSchemaRecordAsChanged() throws Exception {
    neoStores = createStores();
    TransactionRecordState state = newTransactionRecordState();
    long ruleId = neoStores.getSchemaStore().nextId(NULL);
    IndexDescriptor rule = IndexPrototype.forSchema(forLabel(0, 1)).withName("index_" + ruleId).materialise(ruleId);
    state.schemaRuleCreate(ruleId, false, rule);
    List<StorageCommand> commands = new ArrayList<>();
    state.extractCommands(commands, INSTANCE);
    assertThat(commands.size()).isEqualTo(1);
    SchemaRuleCommand command = (SchemaRuleCommand) commands.get(0);
    assertThat(command.getMode()).isEqualTo(Command.Mode.CREATE);
    assertThat(command.getSchemaRule()).isEqualTo(rule);
    assertThat(command.getKey()).isEqualTo(ruleId);
    assertThat(command.getBefore().inUse()).isEqualTo(false);
    assertThat(command.getAfter().inUse()).isEqualTo(true);
    assertThat(command.getAfter().isConstraint()).isEqualTo(false);
    assertThat(command.getAfter().isCreated()).isEqualTo(true);
    assertThat(command.getAfter().getNextProp()).isEqualTo(Record.NO_NEXT_PROPERTY.longValue());
}
Also used : SchemaRuleCommand(org.neo4j.internal.recordstorage.Command.SchemaRuleCommand) StorageCommand(org.neo4j.storageengine.api.StorageCommand) ArrayList(java.util.ArrayList) LongArrayList(org.eclipse.collections.impl.list.mutable.primitive.LongArrayList) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Test(org.junit.jupiter.api.Test)

Aggregations

SchemaRuleCommand (org.neo4j.internal.recordstorage.Command.SchemaRuleCommand)15 Test (org.junit.jupiter.api.Test)13 SchemaRecord (org.neo4j.kernel.impl.store.record.SchemaRecord)9 RepeatedTest (org.junit.jupiter.api.RepeatedTest)8 ArrayList (java.util.ArrayList)6 LongArrayList (org.eclipse.collections.impl.list.mutable.primitive.LongArrayList)6 StorageCommand (org.neo4j.storageengine.api.StorageCommand)6 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)5 PropertyCommand (org.neo4j.internal.recordstorage.Command.PropertyCommand)4 InMemoryClosableChannel (org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel)3 ConstraintDescriptor (org.neo4j.internal.schema.ConstraintDescriptor)2 SchemaRule (org.neo4j.internal.schema.SchemaRule)2