Search in sources :

Example 21 with BatchTransactionApplier

use of org.neo4j.kernel.impl.api.BatchTransactionApplier in project neo4j by neo4j.

the class TransactionRecordStateTest method shouldDeleteDynamicLabelsForDeletedNode.

@Test
public void shouldDeleteDynamicLabelsForDeletedNode() throws Throwable {
    // GIVEN a store that has got a node with a dynamic label record
    NeoStores store = neoStoresRule.open();
    BatchTransactionApplier applier = new NeoStoreBatchTransactionApplier(store, mock(CacheAccessBackDoor.class), LockService.NO_LOCK_SERVICE);
    AtomicLong nodeId = new AtomicLong();
    AtomicLong dynamicLabelRecordId = new AtomicLong();
    apply(applier, transaction(nodeWithDynamicLabelRecord(store, nodeId, dynamicLabelRecordId)));
    assertDynamicLabelRecordInUse(store, dynamicLabelRecordId.get(), true);
    // WHEN applying a transaction where the node is deleted
    apply(applier, transaction(deleteNode(store, nodeId.get())));
    // THEN the dynamic label record should also be deleted
    assertDynamicLabelRecordInUse(store, dynamicLabelRecordId.get(), false);
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) NeoStores(org.neo4j.kernel.impl.store.NeoStores) NeoStoreBatchTransactionApplier(org.neo4j.kernel.impl.transaction.command.NeoStoreBatchTransactionApplier) 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 22 with BatchTransactionApplier

use of org.neo4j.kernel.impl.api.BatchTransactionApplier 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)

Example 23 with BatchTransactionApplier

use of org.neo4j.kernel.impl.api.BatchTransactionApplier in project neo4j by neo4j.

the class TransactionRecordStateTest method shouldSortRelationshipGroups.

@Test
public void shouldSortRelationshipGroups() throws Throwable {
    // GIVEN
    int type5 = 5, type10 = 10, type15 = 15;
    NeoStores neoStores = neoStoresRule.open(GraphDatabaseSettings.dense_node_threshold.name(), "1");
    {
        TransactionRecordState recordState = newTransactionRecordState(neoStores);
        neoStores.getRelationshipTypeTokenStore().setHighId(16);
        recordState.createRelationshipTypeToken("5", type5);
        recordState.createRelationshipTypeToken("10", type10);
        recordState.createRelationshipTypeToken("15", type15);
        BatchTransactionApplier applier = new NeoStoreBatchTransactionApplier(neoStores, mock(CacheAccessBackDoor.class), LockService.NO_LOCK_SERVICE);
        apply(applier, transaction(recordState));
    }
    long nodeId = neoStores.getNodeStore().nextId();
    {
        long otherNode1Id = neoStores.getNodeStore().nextId();
        long otherNode2Id = neoStores.getNodeStore().nextId();
        TransactionRecordState recordState = newTransactionRecordState(neoStores);
        recordState.nodeCreate(nodeId);
        recordState.nodeCreate(otherNode1Id);
        recordState.nodeCreate(otherNode2Id);
        recordState.relCreate(neoStores.getRelationshipStore().nextId(), type10, nodeId, otherNode1Id);
        // This relationship will cause the switch to dense
        recordState.relCreate(neoStores.getRelationshipStore().nextId(), type10, nodeId, otherNode2Id);
        BatchTransactionApplier applier = new NeoStoreBatchTransactionApplier(neoStores, mock(CacheAccessBackDoor.class), LockService.NO_LOCK_SERVICE);
        apply(applier, transaction(recordState));
        // Just a little validation of assumptions
        assertRelationshipGroupsInOrder(neoStores, nodeId, type10);
    }
    // WHEN inserting a relationship of type 5
    {
        TransactionRecordState recordState = newTransactionRecordState(neoStores);
        long otherNodeId = neoStores.getNodeStore().nextId();
        recordState.nodeCreate(otherNodeId);
        recordState.relCreate(neoStores.getRelationshipStore().nextId(), type5, nodeId, otherNodeId);
        BatchTransactionApplier applier = new NeoStoreBatchTransactionApplier(neoStores, mock(CacheAccessBackDoor.class), LockService.NO_LOCK_SERVICE);
        apply(applier, transaction(recordState));
        // THEN that group should end up first in the chain
        assertRelationshipGroupsInOrder(neoStores, nodeId, type5, type10);
    }
    // WHEN inserting a relationship of type 15
    {
        TransactionRecordState recordState = newTransactionRecordState(neoStores);
        long otherNodeId = neoStores.getNodeStore().nextId();
        recordState.nodeCreate(otherNodeId);
        recordState.relCreate(neoStores.getRelationshipStore().nextId(), type15, nodeId, otherNodeId);
        BatchTransactionApplier applier = new NeoStoreBatchTransactionApplier(neoStores, mock(CacheAccessBackDoor.class), LockService.NO_LOCK_SERVICE);
        apply(applier, transaction(recordState));
        // THEN that group should end up last in the chain
        assertRelationshipGroupsInOrder(neoStores, nodeId, type5, type10, type15);
    }
}
Also used : NeoStores(org.neo4j.kernel.impl.store.NeoStores) NeoStoreBatchTransactionApplier(org.neo4j.kernel.impl.transaction.command.NeoStoreBatchTransactionApplier) NeoStoreBatchTransactionApplier(org.neo4j.kernel.impl.transaction.command.NeoStoreBatchTransactionApplier) BatchTransactionApplier(org.neo4j.kernel.impl.api.BatchTransactionApplier) Test(org.junit.Test)

Example 24 with BatchTransactionApplier

use of org.neo4j.kernel.impl.api.BatchTransactionApplier in project neo4j by neo4j.

the class NeoStoreTransactionApplierTest method shouldApplyRelationshipCommandToTheStore.

// RELATIONSHIP COMMAND
@Test
public void shouldApplyRelationshipCommandToTheStore() throws Exception {
    // given
    final BatchTransactionApplier applier = newApplier(false);
    final RelationshipRecord before = new RelationshipRecord(12);
    final RelationshipRecord record = new RelationshipRecord(12, 3, 4, 5);
    record.setInUse(true);
    final Command command = new Command.RelationshipCommand(before, record);
    // when
    boolean result = apply(applier, command::handle, transactionToApply);
    // then
    assertFalse(result);
    verify(relationshipStore, times(1)).updateRecord(record);
}
Also used : RelationshipTypeTokenCommand(org.neo4j.kernel.impl.transaction.command.Command.RelationshipTypeTokenCommand) LabelTokenCommand(org.neo4j.kernel.impl.transaction.command.Command.LabelTokenCommand) PropertyKeyTokenCommand(org.neo4j.kernel.impl.transaction.command.Command.PropertyKeyTokenCommand) RelationshipRecord(org.neo4j.kernel.impl.store.record.RelationshipRecord) BatchTransactionApplier(org.neo4j.kernel.impl.api.BatchTransactionApplier) Test(org.junit.Test)

Example 25 with BatchTransactionApplier

use of org.neo4j.kernel.impl.api.BatchTransactionApplier in project neo4j by neo4j.

the class NeoStoreTransactionApplierTest method shouldApplyNodeCommandToTheStoreInRecoveryMode.

@Test
public void shouldApplyNodeCommandToTheStoreInRecoveryMode() throws Exception {
    // given
    final BatchTransactionApplier applier = newApplier(true);
    final NodeRecord before = new NodeRecord(11);
    before.setLabelField(42, Arrays.asList(one, two));
    final NodeRecord after = new NodeRecord(12);
    after.setInUse(true);
    after.setLabelField(42, Arrays.asList(one, two, three));
    final Command.NodeCommand command = new Command.NodeCommand(before, after);
    // when
    boolean result = apply(applier, command::handle, transactionToApply);
    // then
    assertFalse(result);
    verify(lockService, times(1)).acquireNodeLock(command.getKey(), LockService.LockType.WRITE_LOCK);
    verify(nodeStore, times(1)).setHighestPossibleIdInUse(after.getId());
    verify(nodeStore, times(1)).updateRecord(after);
    verify(dynamicLabelStore, times(1)).setHighestPossibleIdInUse(three.getId());
}
Also used : NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) RelationshipTypeTokenCommand(org.neo4j.kernel.impl.transaction.command.Command.RelationshipTypeTokenCommand) LabelTokenCommand(org.neo4j.kernel.impl.transaction.command.Command.LabelTokenCommand) PropertyKeyTokenCommand(org.neo4j.kernel.impl.transaction.command.Command.PropertyKeyTokenCommand) BatchTransactionApplier(org.neo4j.kernel.impl.api.BatchTransactionApplier) Test(org.junit.Test)

Aggregations

BatchTransactionApplier (org.neo4j.kernel.impl.api.BatchTransactionApplier)45 Test (org.junit.Test)41 LabelTokenCommand (org.neo4j.kernel.impl.transaction.command.Command.LabelTokenCommand)34 PropertyKeyTokenCommand (org.neo4j.kernel.impl.transaction.command.Command.PropertyKeyTokenCommand)34 RelationshipTypeTokenCommand (org.neo4j.kernel.impl.transaction.command.Command.RelationshipTypeTokenCommand)34 DynamicRecord (org.neo4j.kernel.impl.store.record.DynamicRecord)13 NeoStoreBatchTransactionApplier (org.neo4j.kernel.impl.transaction.command.NeoStoreBatchTransactionApplier)10 CacheAccessBackDoor (org.neo4j.kernel.impl.core.CacheAccessBackDoor)8 SchemaIndexProvider (org.neo4j.kernel.api.index.SchemaIndexProvider)7 NeoStores (org.neo4j.kernel.impl.store.NeoStores)7 IndexRule (org.neo4j.kernel.impl.store.record.IndexRule)7 ConstraintRule (org.neo4j.kernel.impl.store.record.ConstraintRule)6 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)4 PropertyRecord (org.neo4j.kernel.impl.store.record.PropertyRecord)4 ArrayList (java.util.ArrayList)3 RelationshipTypeToken (org.neo4j.kernel.impl.core.RelationshipTypeToken)3 RelationshipRecord (org.neo4j.kernel.impl.store.record.RelationshipRecord)3 RelationshipGroupCommand (org.neo4j.kernel.impl.transaction.command.Command.RelationshipGroupCommand)3 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 BatchTransactionApplierFacade (org.neo4j.kernel.impl.api.BatchTransactionApplierFacade)2