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