Search in sources :

Example 6 with NeoStoreBatchTransactionApplier

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

use of org.neo4j.kernel.impl.transaction.command.NeoStoreBatchTransactionApplier 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 8 with NeoStoreBatchTransactionApplier

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

the class RecordStorageEngine method applier.

/**
     * Creates a {@link BatchTransactionApplierFacade} that is to be used for all transactions
     * in a batch. Each transaction is handled by a {@link TransactionApplierFacade} which wraps the
     * individual {@link TransactionApplier}s returned by the wrapped {@link BatchTransactionApplier}s.
     *
     * After all transactions have been applied the appliers are closed.
     */
protected BatchTransactionApplierFacade applier(TransactionApplicationMode mode) {
    ArrayList<BatchTransactionApplier> appliers = new ArrayList<>();
    // Graph store application. The order of the decorated store appliers is irrelevant
    appliers.add(new NeoStoreBatchTransactionApplier(neoStores, cacheAccess, lockService));
    if (mode.needsHighIdTracking()) {
        appliers.add(new HighIdBatchTransactionApplier(neoStores));
    }
    if (mode.needsCacheInvalidationOnUpdates()) {
        appliers.add(new CacheInvalidationBatchTransactionApplier(neoStores, cacheAccess));
    }
    // Schema index application
    appliers.add(new IndexBatchTransactionApplier(indexingService, labelScanStoreSync, indexUpdatesSync, neoStores.getNodeStore(), new PropertyLoader(neoStores), indexUpdatesConverter, mode));
    // Legacy index application
    appliers.add(new LegacyBatchIndexApplier(indexConfigStore, legacyIndexApplierLookup, legacyIndexTransactionOrdering, mode));
    // Counts store application
    appliers.add(new CountsStoreBatchTransactionApplier(neoStores.getCounts(), mode));
    // Perform the application
    return new BatchTransactionApplierFacade(appliers.toArray(new BatchTransactionApplier[appliers.size()]));
}
Also used : HighIdBatchTransactionApplier(org.neo4j.kernel.impl.transaction.command.HighIdBatchTransactionApplier) ArrayList(java.util.ArrayList) NeoStoreBatchTransactionApplier(org.neo4j.kernel.impl.transaction.command.NeoStoreBatchTransactionApplier) BatchTransactionApplierFacade(org.neo4j.kernel.impl.api.BatchTransactionApplierFacade) PropertyLoader(org.neo4j.kernel.impl.transaction.state.PropertyLoader) CountsStoreBatchTransactionApplier(org.neo4j.kernel.impl.api.CountsStoreBatchTransactionApplier) HighIdBatchTransactionApplier(org.neo4j.kernel.impl.transaction.command.HighIdBatchTransactionApplier) BatchTransactionApplier(org.neo4j.kernel.impl.api.BatchTransactionApplier) IndexBatchTransactionApplier(org.neo4j.kernel.impl.transaction.command.IndexBatchTransactionApplier) CacheInvalidationBatchTransactionApplier(org.neo4j.kernel.impl.transaction.command.CacheInvalidationBatchTransactionApplier) NeoStoreBatchTransactionApplier(org.neo4j.kernel.impl.transaction.command.NeoStoreBatchTransactionApplier) IndexBatchTransactionApplier(org.neo4j.kernel.impl.transaction.command.IndexBatchTransactionApplier) LegacyBatchIndexApplier(org.neo4j.kernel.impl.api.LegacyBatchIndexApplier) CacheInvalidationBatchTransactionApplier(org.neo4j.kernel.impl.transaction.command.CacheInvalidationBatchTransactionApplier) CountsStoreBatchTransactionApplier(org.neo4j.kernel.impl.api.CountsStoreBatchTransactionApplier)

Example 9 with NeoStoreBatchTransactionApplier

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

the class TransactionRecordStateTest method shouldDeleteDynamicLabelsForDeletedNodeForRecoveredTransaction.

@Test
public void shouldDeleteDynamicLabelsForDeletedNodeForRecoveredTransaction() 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, which has first round-tripped through a log (written then read)
    TransactionRepresentation transaction = transaction(deleteNode(store, nodeId.get()));
    InMemoryVersionableReadableClosablePositionAwareChannel channel = new InMemoryVersionableReadableClosablePositionAwareChannel();
    writeToChannel(transaction, channel);
    CommittedTransactionRepresentation recoveredTransaction = readFromChannel(channel);
    // and applying that recovered transaction
    apply(applier, recoveredTransaction.getTransactionRepresentation());
    // THEN should have the dynamic label record should be deleted as well
    assertDynamicLabelRecordInUse(store, dynamicLabelRecordId.get(), false);
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) CommittedTransactionRepresentation(org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation) NeoStores(org.neo4j.kernel.impl.store.NeoStores) CommittedTransactionRepresentation(org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation) TransactionRepresentation(org.neo4j.kernel.impl.transaction.TransactionRepresentation) NeoStoreBatchTransactionApplier(org.neo4j.kernel.impl.transaction.command.NeoStoreBatchTransactionApplier) InMemoryVersionableReadableClosablePositionAwareChannel(org.neo4j.kernel.impl.transaction.log.InMemoryVersionableReadableClosablePositionAwareChannel) 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 10 with NeoStoreBatchTransactionApplier

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

the class TransactionRecordStateTest method apply.

private void apply(NeoStores neoStores, TransactionRecordState state) throws Exception {
    BatchTransactionApplier applier = new NeoStoreBatchTransactionApplier(neoStores, mock(CacheAccessBackDoor.class), LockService.NO_LOCK_SERVICE);
    apply(applier, transactionRepresentationOf(state));
}
Also used : 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)

Aggregations

NeoStoreBatchTransactionApplier (org.neo4j.kernel.impl.transaction.command.NeoStoreBatchTransactionApplier)11 BatchTransactionApplier (org.neo4j.kernel.impl.api.BatchTransactionApplier)10 CacheAccessBackDoor (org.neo4j.kernel.impl.core.CacheAccessBackDoor)9 Test (org.junit.Test)7 NeoStores (org.neo4j.kernel.impl.store.NeoStores)7 ArrayList (java.util.ArrayList)3 RelationshipGroupCommand (org.neo4j.kernel.impl.transaction.command.Command.RelationshipGroupCommand)3 PhysicalTransactionRepresentation (org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation)3 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 LockService (org.neo4j.kernel.impl.locking.LockService)2 TransactionRepresentation (org.neo4j.kernel.impl.transaction.TransactionRepresentation)2 Command (org.neo4j.kernel.impl.transaction.command.Command)2 NodeCommand (org.neo4j.kernel.impl.transaction.command.Command.NodeCommand)2 PropertyCommand (org.neo4j.kernel.impl.transaction.command.Command.PropertyCommand)2 RelationshipCommand (org.neo4j.kernel.impl.transaction.command.Command.RelationshipCommand)2 StorageCommand (org.neo4j.storageengine.api.StorageCommand)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 Answer (org.mockito.stubbing.Answer)1 BatchTransactionApplierFacade (org.neo4j.kernel.impl.api.BatchTransactionApplierFacade)1