Search in sources :

Example 36 with StorageCommand

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());
}
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 37 with StorageCommand

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());
}
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 38 with StorageCommand

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);
}
Also used : StorageCommand(org.neo4j.storageengine.api.StorageCommand) ArrayList(java.util.ArrayList) LongArrayList(org.eclipse.collections.impl.list.mutable.primitive.LongArrayList) RelationshipGroupCommand(org.neo4j.internal.recordstorage.Command.RelationshipGroupCommand) RelationshipCommand(org.neo4j.internal.recordstorage.Command.RelationshipCommand) NodeCommand(org.neo4j.internal.recordstorage.Command.NodeCommand) Test(org.junit.jupiter.api.Test)

Example 39 with StorageCommand

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;
}
Also used : TestCommand(org.neo4j.kernel.impl.api.TestCommand) StorageCommand(org.neo4j.storageengine.api.StorageCommand) ArrayList(java.util.ArrayList) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation)

Example 40 with StorageCommand

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

Aggregations

StorageCommand (org.neo4j.storageengine.api.StorageCommand)77 ArrayList (java.util.ArrayList)39 Test (org.junit.jupiter.api.Test)34 CommandReader (org.neo4j.storageengine.api.CommandReader)23 InMemoryClosableChannel (org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel)22 RepeatedTest (org.junit.jupiter.api.RepeatedTest)19 PhysicalTransactionRepresentation (org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation)14 LongArrayList (org.eclipse.collections.impl.list.mutable.primitive.LongArrayList)10 Test (org.junit.Test)10 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)9 RelationshipGroupRecord (org.neo4j.kernel.impl.store.record.RelationshipGroupRecord)9 PropertyRecord (org.neo4j.kernel.impl.store.record.PropertyRecord)8 Command (org.neo4j.kernel.impl.transaction.command.Command)7 NodeCommand (org.neo4j.kernel.impl.transaction.command.Command.NodeCommand)7 LogEntryCommand (org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommand)7 SchemaRuleCommand (org.neo4j.internal.recordstorage.Command.SchemaRuleCommand)6 NeoStores (org.neo4j.kernel.impl.store.NeoStores)6 IOException (java.io.IOException)5 PropertyCommand (org.neo4j.internal.recordstorage.Command.PropertyCommand)5 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)5