Search in sources :

Example 1 with RelationshipGroupCommand

use of org.neo4j.kernel.impl.transaction.command.Command.RelationshipGroupCommand 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 2 with RelationshipGroupCommand

use of org.neo4j.kernel.impl.transaction.command.Command.RelationshipGroupCommand in project neo4j by neo4j.

the class PhysicalLogCommandReadersTest method assertValidRelGroupCommand.

private static void assertValidRelGroupCommand(StorageCommand command) {
    assertThat(command, instanceOf(RelationshipGroupCommand.class));
    RelationshipGroupCommand relGroupCommand = (RelationshipGroupCommand) command;
    RelationshipGroupRecord record = relGroupCommand.getAfter();
    assertEquals(ID, record.getId());
    if (IN_USE_FLAG == Record.IN_USE.byteValue()) {
        assertTrue(record.inUse());
    } else if (IN_USE_FLAG == Record.NOT_IN_USE.byteValue()) {
        assertFalse(record.inUse());
    } else {
        throw new IllegalStateException("Illegal inUse flag: " + IN_USE_FLAG);
    }
    assertEquals(TYPE_AS_INT, record.getType());
    assertEquals(NEXT, record.getNext());
    assertEquals(FIRST_OUT, record.getFirstOut());
    assertEquals(FIRST_IN, record.getFirstIn());
    assertEquals(FIRST_LOOP, record.getNext());
    assertEquals(OWNING_NODE, record.getOwningNode());
}
Also used : RelationshipGroupRecord(org.neo4j.kernel.impl.store.record.RelationshipGroupRecord) RelationshipGroupCommand(org.neo4j.kernel.impl.transaction.command.Command.RelationshipGroupCommand)

Example 3 with RelationshipGroupCommand

use of org.neo4j.kernel.impl.transaction.command.Command.RelationshipGroupCommand in project neo4j by neo4j.

the class Commands method createRelationshipGroup.

public static RelationshipGroupCommand createRelationshipGroup(long id, int type) {
    RelationshipGroupRecord before = new RelationshipGroupRecord(id);
    RelationshipGroupRecord after = new RelationshipGroupRecord(id, type);
    after.setInUse(true);
    after.setCreated();
    return new RelationshipGroupCommand(before, after);
}
Also used : RelationshipGroupRecord(org.neo4j.kernel.impl.store.record.RelationshipGroupRecord) RelationshipGroupCommand(org.neo4j.kernel.impl.transaction.command.Command.RelationshipGroupCommand)

Example 4 with RelationshipGroupCommand

use of org.neo4j.kernel.impl.transaction.command.Command.RelationshipGroupCommand in project neo4j by neo4j.

the class HighIdTransactionApplierTest method shouldTrackSecondaryUnitIdsAsWell.

@Test
public void shouldTrackSecondaryUnitIdsAsWell() throws Exception {
    // GIVEN
    NeoStores neoStores = neoStoresRule.open();
    HighIdTransactionApplier tracker = new HighIdTransactionApplier(neoStores);
    NodeRecord node = new NodeRecord(5).initialize(true, 123, true, 456, 0);
    node.setSecondaryUnitId(6);
    node.setRequiresSecondaryUnit(true);
    RelationshipRecord relationship = new RelationshipRecord(10).initialize(true, 1, 2, 3, 4, 5, 6, 7, 8, true, true);
    relationship.setSecondaryUnitId(12);
    relationship.setRequiresSecondaryUnit(true);
    RelationshipGroupRecord relationshipGroup = new RelationshipGroupRecord(8).initialize(true, 0, 1, 2, 3, 4, 5);
    relationshipGroup.setSecondaryUnitId(20);
    relationshipGroup.setRequiresSecondaryUnit(true);
    // WHEN
    tracker.visitNodeCommand(new NodeCommand(new NodeRecord(node.getId()), node));
    tracker.visitRelationshipCommand(new RelationshipCommand(new RelationshipRecord(relationship.getId()), relationship));
    tracker.visitRelationshipGroupCommand(new RelationshipGroupCommand(new RelationshipGroupRecord(relationshipGroup.getId()), relationshipGroup));
    tracker.close();
    // THEN
    assertEquals(node.getSecondaryUnitId() + 1, neoStores.getNodeStore().getHighId());
    assertEquals(relationship.getSecondaryUnitId() + 1, neoStores.getRelationshipStore().getHighId());
    assertEquals(relationshipGroup.getSecondaryUnitId() + 1, neoStores.getRelationshipGroupStore().getHighId());
}
Also used : NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) RelationshipGroupRecord(org.neo4j.kernel.impl.store.record.RelationshipGroupRecord) NeoStores(org.neo4j.kernel.impl.store.NeoStores) RelationshipRecord(org.neo4j.kernel.impl.store.record.RelationshipRecord) RelationshipGroupCommand(org.neo4j.kernel.impl.transaction.command.Command.RelationshipGroupCommand) RelationshipCommand(org.neo4j.kernel.impl.transaction.command.Command.RelationshipCommand) NodeCommand(org.neo4j.kernel.impl.transaction.command.Command.NodeCommand) Test(org.junit.Test)

Example 5 with RelationshipGroupCommand

use of org.neo4j.kernel.impl.transaction.command.Command.RelationshipGroupCommand in project neo4j by neo4j.

the class TransactionRecordStateTest method shouldPrepareRelevantRecords.

@Test
public void shouldPrepareRelevantRecords() throws Exception {
    // GIVEN
    PrepareTrackingRecordFormats format = new PrepareTrackingRecordFormats(Standard.LATEST_RECORD_FORMATS);
    NeoStores neoStores = neoStoresRule.open(format, GraphDatabaseSettings.dense_node_threshold.name(), "1");
    // WHEN
    TransactionRecordState state = newTransactionRecordState(neoStores);
    state.nodeCreate(0);
    state.relCreate(0, 0, 0, 0);
    state.relCreate(1, 0, 0, 0);
    state.relCreate(2, 0, 0, 0);
    List<StorageCommand> commands = new ArrayList<>();
    state.extractCommands(commands);
    // THEN
    int nodes = 0, rels = 0, 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 : 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) RelationshipCommand(org.neo4j.kernel.impl.transaction.command.Command.RelationshipCommand) NodeCommand(org.neo4j.kernel.impl.transaction.command.Command.NodeCommand) Test(org.junit.Test)

Aggregations

RelationshipGroupCommand (org.neo4j.kernel.impl.transaction.command.Command.RelationshipGroupCommand)5 Test (org.junit.Test)3 NeoStores (org.neo4j.kernel.impl.store.NeoStores)3 RelationshipGroupRecord (org.neo4j.kernel.impl.store.record.RelationshipGroupRecord)3 ArrayList (java.util.ArrayList)2 NodeCommand (org.neo4j.kernel.impl.transaction.command.Command.NodeCommand)2 RelationshipCommand (org.neo4j.kernel.impl.transaction.command.Command.RelationshipCommand)2 StorageCommand (org.neo4j.storageengine.api.StorageCommand)2 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)1 RelationshipRecord (org.neo4j.kernel.impl.store.record.RelationshipRecord)1