Search in sources :

Example 6 with CommandsToApply

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

the class RecordStorageEngineTest method newTransactionThatFailsWith.

private static CommandsToApply newTransactionThatFailsWith(Exception error) throws IOException {
    CommandsToApply transaction = mock(CommandsToApply.class);
    doThrow(error).when(transaction).accept(any());
    long txId = ThreadLocalRandom.current().nextLong(0, 1000);
    when(transaction.transactionId()).thenReturn(txId);
    return transaction;
}
Also used : CommandsToApply(org.neo4j.storageengine.api.CommandsToApply)

Example 7 with CommandsToApply

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

the class CommandHandlerContract method apply.

/**
 * Simply calls through to the {@link CommandStream#accept(Visitor)} method for each {@link
 * CommandsToApply} given. This assumes that the {@link TransactionApplierFactory} will return {@link
 * TransactionApplier}s which actually do the work and that the transaction has all the relevant data.
 *
 * @param applier to use
 * @param transactions to apply
 */
public static void apply(TransactionApplierFactory applier, CommandsToApply... transactions) throws Exception {
    var batchContext = mock(BatchContext.class);
    when(batchContext.getLockGroup()).thenReturn(new LockGroup());
    when(batchContext.getIdUpdateListener()).thenReturn(IdUpdateListener.IGNORE);
    when(batchContext.getIndexActivator()).thenReturn(mock(IndexActivator.class));
    for (CommandsToApply tx : transactions) {
        try (TransactionApplier txApplier = applier.startTx(tx, batchContext)) {
            tx.accept(txApplier);
        }
    }
}
Also used : CommandsToApply(org.neo4j.storageengine.api.CommandsToApply) LockGroup(org.neo4j.lock.LockGroup)

Example 8 with CommandsToApply

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

the class BatchingNeoStoresTest method apply.

private static void apply(TxState txState, CommandCreationContext commandCreationContext, RecordStorageEngine storageEngine) throws Exception {
    List<StorageCommand> commands = new ArrayList<>();
    try (RecordStorageReader storageReader = storageEngine.newReader()) {
        storageEngine.createCommands(commands, txState, storageReader, commandCreationContext, ResourceLocker.IGNORE, LockTracer.NONE, BASE_TX_ID, v -> v, NULL, INSTANCE);
        CommandsToApply apply = new TransactionToApply(new PhysicalTransactionRepresentation(commands, new byte[0], 0, 0, 0, 0, ANONYMOUS), NULL);
        storageEngine.apply(apply, TransactionApplicationMode.INTERNAL);
    }
}
Also used : CommandsToApply(org.neo4j.storageengine.api.CommandsToApply) TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply) RecordStorageReader(org.neo4j.internal.recordstorage.RecordStorageReader) StorageCommand(org.neo4j.storageengine.api.StorageCommand) ArrayList(java.util.ArrayList) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation)

Example 9 with CommandsToApply

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

the class RecordStorageEngine method apply.

@Override
public void apply(CommandsToApply batch, TransactionApplicationMode mode) throws Exception {
    TransactionApplierFactoryChain batchApplier = applierChain(mode);
    CommandsToApply initialBatch = batch;
    try (BatchContext context = createBatchContext(batchApplier, batch)) {
        while (batch != null) {
            try (TransactionApplier txApplier = batchApplier.startTx(batch, context)) {
                batch.accept(txApplier);
            }
            batch = batch.next();
        }
    } catch (Throwable cause) {
        TransactionApplyKernelException kernelException = new TransactionApplyKernelException(cause, "Failed to apply transaction: %s", batch == null ? initialBatch : batch);
        databaseHealth.panic(kernelException);
        throw kernelException;
    }
}
Also used : CommandsToApply(org.neo4j.storageengine.api.CommandsToApply) TransactionApplyKernelException(org.neo4j.internal.kernel.api.exceptions.TransactionApplyKernelException)

Example 10 with CommandsToApply

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

the class WriteTransactionCommandOrderingTest method shouldExecuteCommandsInTheSameOrderRegardlessOfItBeingRecoveredOrNot.

@Test
void shouldExecuteCommandsInTheSameOrderRegardlessOfItBeingRecoveredOrNot() throws Exception {
    // Given
    TransactionRecordState tx = injectAllPossibleCommands();
    // When
    CommandsToApply commands = transactionRepresentationOf(tx);
    // Then
    final OrderVerifyingCommandHandler orderVerifyingCommandHandler = new OrderVerifyingCommandHandler();
    commands.accept(element -> ((Command) element).handle(orderVerifyingCommandHandler));
}
Also used : CommandsToApply(org.neo4j.storageengine.api.CommandsToApply) Test(org.junit.jupiter.api.Test)

Aggregations

CommandsToApply (org.neo4j.storageengine.api.CommandsToApply)15 Test (org.junit.jupiter.api.Test)8 IOException (java.io.IOException)4 InOrder (org.mockito.InOrder)3 StorageCommand (org.neo4j.storageengine.api.StorageCommand)3 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)2 Mockito.doThrow (org.mockito.Mockito.doThrow)2 Mockito.mock (org.mockito.Mockito.mock)2 Mockito.verify (org.mockito.Mockito.verify)2 Mockito.when (org.mockito.Mockito.when)2 KernelException (org.neo4j.exceptions.KernelException)2 UnderlyingStorageException (org.neo4j.exceptions.UnderlyingStorageException)2 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)2 Lock (org.neo4j.lock.Lock)2 LockService (org.neo4j.lock.LockService)2 File (java.io.File)1 Path (java.nio.file.Path)1 EnumMap (java.util.EnumMap)1