Search in sources :

Example 1 with LockGroup

use of org.neo4j.kernel.impl.locking.LockGroup in project neo4j by neo4j.

the class ReplicatedTokenStateMachine method applyToStore.

private int applyToStore(Collection<StorageCommand> commands, long logIndex) throws NoSuchEntryException {
    int tokenId = extractTokenId(commands);
    PhysicalTransactionRepresentation representation = new PhysicalTransactionRepresentation(commands);
    representation.setHeader(encodeLogIndexAsTxHeader(logIndex), 0, 0, 0, 0L, 0L, 0);
    try (LockGroup ignored = new LockGroup()) {
        commitProcess.commit(new TransactionToApply(representation), CommitEvent.NULL, TransactionApplicationMode.EXTERNAL);
    } catch (TransactionFailureException e) {
        throw new RuntimeException(e);
    }
    return tokenId;
}
Also used : TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply) TransactionFailureException(org.neo4j.kernel.api.exceptions.TransactionFailureException) LockGroup(org.neo4j.kernel.impl.locking.LockGroup) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation)

Example 2 with LockGroup

use of org.neo4j.kernel.impl.locking.LockGroup in project neo4j by neo4j.

the class CommandHandlerContract method apply.

/**
     * In case the transactions do not have the commands to apply, use this method to apply any commands you want with a
     * given {@link ApplyFunction} instead.
     *
     * @param applier to use
     * @param function which knows what to do with the {@link TransactionApplier}.
     * @param transactions are only used to create {@link TransactionApplier}s. The actual work is delegated to the
     * function.
     * @return the boolean-and result of all function operations.
     */
public static boolean apply(BatchTransactionApplier applier, ApplyFunction function, TransactionToApply... transactions) throws Exception {
    boolean result = true;
    for (TransactionToApply tx : transactions) {
        try (TransactionApplier txApplier = applier.startTx(tx, new LockGroup())) {
            result &= function.apply(txApplier);
        }
    }
    applier.close();
    return result;
}
Also used : TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply) LockGroup(org.neo4j.kernel.impl.locking.LockGroup) BatchTransactionApplier(org.neo4j.kernel.impl.api.BatchTransactionApplier) TransactionApplier(org.neo4j.kernel.impl.api.TransactionApplier)

Example 3 with LockGroup

use of org.neo4j.kernel.impl.locking.LockGroup in project neo4j by neo4j.

the class BatchTransactionApplierFacadeTest method testStartTxCorrectOrderWithLockGroup.

@Test
public void testStartTxCorrectOrderWithLockGroup() throws Exception {
    // GIVEN
    TransactionToApply tx = mock(TransactionToApply.class);
    LockGroup lockGroup = mock(LockGroup.class);
    // WHEN
    TransactionApplierFacade result = (TransactionApplierFacade) facade.startTx(tx, lockGroup);
    // THEN
    InOrder inOrder = inOrder(applier1, applier2, applier3);
    inOrder.verify(applier1).startTx(tx, lockGroup);
    inOrder.verify(applier2).startTx(tx, lockGroup);
    inOrder.verify(applier3).startTx(tx, lockGroup);
    assertEquals(txApplier1, result.appliers[0]);
    assertEquals(txApplier2, result.appliers[1]);
    assertEquals(txApplier3, result.appliers[2]);
    assertEquals(3, result.appliers.length);
}
Also used : InOrder(org.mockito.InOrder) LockGroup(org.neo4j.kernel.impl.locking.LockGroup) Test(org.junit.Test)

Aggregations

LockGroup (org.neo4j.kernel.impl.locking.LockGroup)3 TransactionToApply (org.neo4j.kernel.impl.api.TransactionToApply)2 Test (org.junit.Test)1 InOrder (org.mockito.InOrder)1 TransactionFailureException (org.neo4j.kernel.api.exceptions.TransactionFailureException)1 BatchTransactionApplier (org.neo4j.kernel.impl.api.BatchTransactionApplier)1 TransactionApplier (org.neo4j.kernel.impl.api.TransactionApplier)1 PhysicalTransactionRepresentation (org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation)1