use of org.neo4j.storageengine.api.StorageCommand 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.storageengine.api.StorageCommand 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.storageengine.api.StorageCommand in project neo4j by neo4j.
the class TransactionRecordStateTest method shouldPrepareRelevantRecords.
@Test
void shouldPrepareRelevantRecords() throws Exception {
PrepareTrackingRecordFormats format = new PrepareTrackingRecordFormats(Standard.LATEST_RECORD_FORMATS);
neoStores = createStores(Config.defaults(dense_node_threshold, 1), format);
// WHEN
TransactionRecordState state = newTransactionRecordState();
state.nodeCreate(0);
state.relModify(singleCreate(0, 0, 0, 0));
state.relModify(singleCreate(1, 0, 0, 0));
state.relModify(singleCreate(2, 0, 0, 0));
List<StorageCommand> commands = new ArrayList<>();
state.extractCommands(commands, INSTANCE);
// THEN
int nodes = 0;
int rels = 0;
int groups = 0;
for (StorageCommand command : commands) {
if (command instanceof NodeCommand) {
assertTrue(format.node().prepared(((NodeCommand) command).getAfter()));
nodes++;
} else if (command instanceof RelationshipCommand) {
assertTrue(format.relationship().prepared(((RelationshipCommand) command).getAfter()));
rels++;
} else if (command instanceof RelationshipGroupCommand) {
assertTrue(format.relationshipGroup().prepared(((RelationshipGroupCommand) command).getAfter()));
groups++;
}
}
assertEquals(1, nodes);
assertEquals(3, rels);
assertEquals(1, groups);
}
use of org.neo4j.storageengine.api.StorageCommand in project neo4j by neo4j.
the class ReversedSingleFileTransactionCursorTest method tx.
private static TransactionRepresentation tx(int size) {
List<StorageCommand> commands = new ArrayList<>();
for (int i = 0; i < size; i++) {
// The type of command doesn't matter here
commands.add(new TestCommand());
}
PhysicalTransactionRepresentation tx = new PhysicalTransactionRepresentation(commands);
tx.setHeader(new byte[0], 0, 0, 0, 0, ANONYMOUS);
return tx;
}
use of org.neo4j.storageengine.api.StorageCommand 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());
}
Aggregations