Search in sources :

Example 76 with StorageCommand

use of org.neo4j.storageengine.api.StorageCommand in project neo4j by neo4j.

the class TransactionRecordStateTest method shouldIgnoreRelationshipGroupCommandsForGroupThatIsCreatedAndDeletedInThisTx.

@Test
void shouldIgnoreRelationshipGroupCommandsForGroupThatIsCreatedAndDeletedInThisTx() throws Exception {
    /*
         * This test verifies that there are no transaction commands generated for a state diff that contains a
         * relationship group that is created and deleted in this tx. This case requires special handling because
         * relationship groups can be created and then deleted from disjoint code paths. Look at
         * TransactionRecordState.extractCommands() for more details.
         *
         * The test setup looks complicated but all it does is mock properly a NeoStoreTransactionContext to
         * return an Iterable<RecordSet> that contains a RelationshipGroup record which has been created in this
         * tx and also is set notInUse.
         */
    // Given:
    // - dense node threshold of 5
    // - node with 4 rels of type relationshipB and 1 rel of type relationshipB
    neoStores = createStores(Config.defaults(dense_node_threshold, 5));
    int relationshipA = 0;
    int relationshipB = 1;
    TransactionRecordState state = newTransactionRecordState();
    state.nodeCreate(0);
    state.relModify(singleCreate(0, relationshipA, 0, 0));
    state.relModify(singleCreate(1, relationshipA, 0, 0));
    state.relModify(singleCreate(2, relationshipA, 0, 0));
    state.relModify(singleCreate(3, relationshipA, 0, 0));
    state.relModify(singleCreate(4, relationshipB, 0, 0));
    apply(state);
    // When doing a tx where a relationship of type A for the node is create and rel of type relationshipB is deleted
    state = newTransactionRecordState();
    // here this node should be converted to dense and the groups should be created
    // and the group relationshipB should be delete
    state.relModify(new FlatRelationshipModifications(relationships(relationship(5, relationshipA, 0, 0)), relationships(relationship(4, relationshipB, 0, 0))));
    // Then
    Collection<StorageCommand> commands = new ArrayList<>();
    state.extractCommands(commands, INSTANCE);
    RelationshipGroupCommand group = singleRelationshipGroupCommand(commands);
    assertEquals(relationshipA, group.getAfter().getType());
}
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) Test(org.junit.jupiter.api.Test)

Example 77 with StorageCommand

use of org.neo4j.storageengine.api.StorageCommand in project neo4j by neo4j.

the class TransactionRecordStateTest method readFromChannel.

@SuppressWarnings("InfiniteLoopStatement")
private static CommandsToApply readFromChannel(ReadableLogChannel channel) throws IOException {
    CommandReader reader = LogCommandSerializationV4_0.INSTANCE;
    List<StorageCommand> commands = new ArrayList<>();
    try {
        while (true) {
            commands.add(reader.read(channel));
        }
    } catch (ReadPastEndException e) {
    // reached the end
    }
    return new GroupOfCommands(commands.toArray(new StorageCommand[0]));
}
Also used : CommandReader(org.neo4j.storageengine.api.CommandReader) StorageCommand(org.neo4j.storageengine.api.StorageCommand) ArrayList(java.util.ArrayList) LongArrayList(org.eclipse.collections.impl.list.mutable.primitive.LongArrayList) ReadPastEndException(org.neo4j.io.fs.ReadPastEndException)

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