Search in sources :

Example 11 with StorageCommand

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

the class TransactionRecordStateTest method shouldExtractUpdateCommandsInCorrectOrder.

@Test
public void shouldExtractUpdateCommandsInCorrectOrder() throws Throwable {
    // GIVEN
    NeoStores neoStores = neoStoresRule.open(GraphDatabaseSettings.dense_node_threshold.name(), "1");
    TransactionRecordState recordState = newTransactionRecordState(neoStores);
    long nodeId = 0, relId1 = 1, relId2 = 2, relId3 = 3;
    recordState.nodeCreate(nodeId);
    recordState.relCreate(relId1, 0, nodeId, nodeId);
    recordState.relCreate(relId2, 0, nodeId, nodeId);
    recordState.nodeAddProperty(nodeId, 0, 101);
    BatchTransactionApplier applier = new NeoStoreBatchTransactionApplier(neoStores, mock(CacheAccessBackDoor.class), LockService.NO_LOCK_SERVICE);
    apply(applier, transaction(recordState));
    recordState = newTransactionRecordState(neoStores);
    recordState.nodeChangeProperty(nodeId, 0, 102);
    recordState.relCreate(relId3, 0, nodeId, nodeId);
    recordState.relAddProperty(relId1, 0, 123);
    // WHEN
    Collection<StorageCommand> commands = new ArrayList<>();
    recordState.extractCommands(commands);
    // THEN
    Iterator<StorageCommand> commandIterator = commands.iterator();
    // added rel property
    assertCommand(commandIterator.next(), PropertyCommand.class);
    // created relationship relId3
    assertCommand(commandIterator.next(), RelationshipCommand.class);
    // rest is updates...
    assertCommand(commandIterator.next(), PropertyCommand.class);
    assertCommand(commandIterator.next(), RelationshipCommand.class);
    assertCommand(commandIterator.next(), RelationshipCommand.class);
    assertCommand(commandIterator.next(), Command.RelationshipGroupCommand.class);
    assertCommand(commandIterator.next(), NodeCommand.class);
    assertFalse(commandIterator.hasNext());
}
Also used : NodeCommand(org.neo4j.kernel.impl.transaction.command.Command.NodeCommand) PropertyCommand(org.neo4j.kernel.impl.transaction.command.Command.PropertyCommand) RelationshipGroupCommand(org.neo4j.kernel.impl.transaction.command.Command.RelationshipGroupCommand) StorageCommand(org.neo4j.storageengine.api.StorageCommand) Command(org.neo4j.kernel.impl.transaction.command.Command) RelationshipCommand(org.neo4j.kernel.impl.transaction.command.Command.RelationshipCommand) NeoStores(org.neo4j.kernel.impl.store.NeoStores) StorageCommand(org.neo4j.storageengine.api.StorageCommand) NeoStoreBatchTransactionApplier(org.neo4j.kernel.impl.transaction.command.NeoStoreBatchTransactionApplier) ArrayList(java.util.ArrayList) NeoStoreBatchTransactionApplier(org.neo4j.kernel.impl.transaction.command.NeoStoreBatchTransactionApplier) BatchTransactionApplier(org.neo4j.kernel.impl.api.BatchTransactionApplier) CacheAccessBackDoor(org.neo4j.kernel.impl.core.CacheAccessBackDoor) Test(org.junit.Test)

Example 12 with StorageCommand

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

the class TransactionRecordStateTest method shouldExtractCreatedCommandsInCorrectOrder.

@Test
public void shouldExtractCreatedCommandsInCorrectOrder() throws Throwable {
    // GIVEN
    NeoStores neoStores = neoStoresRule.open(GraphDatabaseSettings.dense_node_threshold.name(), "1");
    TransactionRecordState recordState = newTransactionRecordState(neoStores);
    long nodeId = 0, relId = 1;
    recordState.nodeCreate(nodeId);
    recordState.relCreate(relId++, 0, nodeId, nodeId);
    recordState.relCreate(relId, 0, nodeId, nodeId);
    recordState.nodeAddProperty(nodeId, 0, 101);
    // WHEN
    Collection<StorageCommand> commands = new ArrayList<>();
    recordState.extractCommands(commands);
    // THEN
    Iterator<StorageCommand> commandIterator = commands.iterator();
    assertCommand(commandIterator.next(), PropertyCommand.class);
    assertCommand(commandIterator.next(), RelationshipCommand.class);
    assertCommand(commandIterator.next(), RelationshipCommand.class);
    assertCommand(commandIterator.next(), Command.RelationshipGroupCommand.class);
    assertCommand(commandIterator.next(), NodeCommand.class);
    assertFalse(commandIterator.hasNext());
}
Also used : NodeCommand(org.neo4j.kernel.impl.transaction.command.Command.NodeCommand) PropertyCommand(org.neo4j.kernel.impl.transaction.command.Command.PropertyCommand) RelationshipGroupCommand(org.neo4j.kernel.impl.transaction.command.Command.RelationshipGroupCommand) StorageCommand(org.neo4j.storageengine.api.StorageCommand) Command(org.neo4j.kernel.impl.transaction.command.Command) RelationshipCommand(org.neo4j.kernel.impl.transaction.command.Command.RelationshipCommand) NeoStores(org.neo4j.kernel.impl.store.NeoStores) StorageCommand(org.neo4j.storageengine.api.StorageCommand) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 13 with StorageCommand

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

the class TransactionRecordStateTest method shouldCreateProperBeforeAndAfterPropertyCommandsWhenAddingProperty.

@Test
public void shouldCreateProperBeforeAndAfterPropertyCommandsWhenAddingProperty() throws Exception {
    // GIVEN
    NeoStores neoStores = neoStoresRule.open();
    TransactionRecordState recordState = newTransactionRecordState(neoStores);
    int nodeId = 1;
    recordState.nodeCreate(nodeId);
    int propertyKey = 1;
    Object value = 5;
    // WHEN
    recordState.nodeAddProperty(nodeId, propertyKey, value);
    Collection<StorageCommand> commands = new ArrayList<>();
    recordState.extractCommands(commands);
    PropertyCommand propertyCommand = singlePropertyCommand(commands);
    // THEN
    PropertyRecord before = propertyCommand.getBefore();
    assertFalse(before.inUse());
    assertFalse(before.iterator().hasNext());
    PropertyRecord after = propertyCommand.getAfter();
    assertTrue(after.inUse());
    assertEquals(1, count(after));
}
Also used : PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) NeoStores(org.neo4j.kernel.impl.store.NeoStores) StorageCommand(org.neo4j.storageengine.api.StorageCommand) ArrayList(java.util.ArrayList) PropertyCommand(org.neo4j.kernel.impl.transaction.command.Command.PropertyCommand) Test(org.junit.Test)

Example 14 with StorageCommand

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

the class TransactionRecordStateTest method shouldIgnoreRelationshipGroupCommandsForGroupThatIsCreatedAndDeletedInThisTx.

@Test
public 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 A and 1 rel of type B
    NeoStores neoStore = neoStoresRule.open(GraphDatabaseSettings.dense_node_threshold.name(), "5");
    int A = 0, B = 1;
    TransactionRecordState state = newTransactionRecordState(neoStore);
    state.nodeCreate(0);
    state.relCreate(0, A, 0, 0);
    state.relCreate(1, A, 0, 0);
    state.relCreate(2, A, 0, 0);
    state.relCreate(3, A, 0, 0);
    state.relCreate(4, B, 0, 0);
    apply(neoStore, state);
    // When doing a tx where a relationship of type A for the node is create and rel of type B is deleted
    state = newTransactionRecordState(neoStore);
    // here this node should be converted to dense and the groups should be created
    state.relCreate(5, A, 0, 0);
    // here the group B should be delete
    state.relDelete(4);
    // Then
    Collection<StorageCommand> commands = new ArrayList<>();
    state.extractCommands(commands);
    RelationshipGroupCommand group = singleRelationshipGroupCommand(commands);
    assertEquals(A, group.getAfter().getType());
}
Also used : NeoStores(org.neo4j.kernel.impl.store.NeoStores) StorageCommand(org.neo4j.storageengine.api.StorageCommand) ArrayList(java.util.ArrayList) RelationshipGroupCommand(org.neo4j.kernel.impl.transaction.command.Command.RelationshipGroupCommand) Test(org.junit.Test)

Example 15 with StorageCommand

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

the class TransactionRecordStateTest method shouldExtractDeleteCommandsInCorrectOrder.

@Test
public void shouldExtractDeleteCommandsInCorrectOrder() throws Exception {
    // GIVEN
    NeoStores neoStores = neoStoresRule.open(GraphDatabaseSettings.dense_node_threshold.name(), "1");
    TransactionRecordState recordState = newTransactionRecordState(neoStores);
    long nodeId1 = 0, nodeId2 = 1, relId1 = 1, relId2 = 2, relId4 = 10;
    recordState.nodeCreate(nodeId1);
    recordState.nodeCreate(nodeId2);
    recordState.relCreate(relId1, 0, nodeId1, nodeId1);
    recordState.relCreate(relId2, 0, nodeId1, nodeId1);
    recordState.relCreate(relId4, 1, nodeId1, nodeId1);
    recordState.nodeAddProperty(nodeId1, 0, 101);
    BatchTransactionApplier applier = new NeoStoreBatchTransactionApplier(neoStores, mock(CacheAccessBackDoor.class), LockService.NO_LOCK_SERVICE);
    apply(applier, transaction(recordState));
    recordState = newTransactionRecordState(neoStores);
    recordState.relDelete(relId4);
    recordState.nodeDelete(nodeId2);
    recordState.nodeRemoveProperty(nodeId1, 0);
    // WHEN
    Collection<StorageCommand> commands = new ArrayList<>();
    recordState.extractCommands(commands);
    // THEN
    Iterator<StorageCommand> commandIterator = commands.iterator();
    // updated rel group to not point to the deleted one below
    assertCommand(commandIterator.next(), Command.RelationshipGroupCommand.class);
    // updated node to point to the group after the deleted one
    assertCommand(commandIterator.next(), NodeCommand.class);
    // rest is deletions below...
    assertCommand(commandIterator.next(), PropertyCommand.class);
    assertCommand(commandIterator.next(), RelationshipCommand.class);
    assertCommand(commandIterator.next(), Command.RelationshipGroupCommand.class);
    assertCommand(commandIterator.next(), NodeCommand.class);
    assertFalse(commandIterator.hasNext());
}
Also used : NodeCommand(org.neo4j.kernel.impl.transaction.command.Command.NodeCommand) PropertyCommand(org.neo4j.kernel.impl.transaction.command.Command.PropertyCommand) RelationshipGroupCommand(org.neo4j.kernel.impl.transaction.command.Command.RelationshipGroupCommand) StorageCommand(org.neo4j.storageengine.api.StorageCommand) Command(org.neo4j.kernel.impl.transaction.command.Command) RelationshipCommand(org.neo4j.kernel.impl.transaction.command.Command.RelationshipCommand) NeoStores(org.neo4j.kernel.impl.store.NeoStores) StorageCommand(org.neo4j.storageengine.api.StorageCommand) NeoStoreBatchTransactionApplier(org.neo4j.kernel.impl.transaction.command.NeoStoreBatchTransactionApplier) ArrayList(java.util.ArrayList) NeoStoreBatchTransactionApplier(org.neo4j.kernel.impl.transaction.command.NeoStoreBatchTransactionApplier) BatchTransactionApplier(org.neo4j.kernel.impl.api.BatchTransactionApplier) CacheAccessBackDoor(org.neo4j.kernel.impl.core.CacheAccessBackDoor) Test(org.junit.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