Search in sources :

Example 16 with TransactionFailureException

use of org.neo4j.kernel.api.exceptions.TransactionFailureException in project neo4j by neo4j.

the class TransitionalTxManagementKernelTransaction method rollback.

public void rollback() {
    try {
        KernelTransaction kernelTransactionBoundToThisThread = bridge.getKernelTransactionBoundToThisThread(false);
        kernelTransactionBoundToThisThread.failure();
        kernelTransactionBoundToThisThread.close();
    } catch (TransactionFailureException e) {
        throw new RuntimeException(e);
    } finally {
        bridge.unbindTransactionFromCurrentThread();
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) TransactionFailureException(org.neo4j.kernel.api.exceptions.TransactionFailureException)

Example 17 with TransactionFailureException

use of org.neo4j.kernel.api.exceptions.TransactionFailureException in project neo4j by neo4j.

the class SlaveTransactionCommitProcess method commit.

@Override
public long commit(TransactionToApply batch, CommitEvent commitEvent, TransactionApplicationMode mode) throws TransactionFailureException {
    if (batch.next() != null) {
        throw new IllegalArgumentException("Only supports single-commit on slave --> master");
    }
    try {
        TransactionRepresentation representation = batch.transactionRepresentation();
        RequestContext context = requestContextFactory.newRequestContext(representation.getLockSessionId());
        try (Response<Long> response = master.commit(context, representation)) {
            return response.response();
        }
    } catch (IOException e) {
        throw new TransactionFailureException(Status.Transaction.TransactionCommitFailed, e, "Could not commit transaction on the master");
    } catch (ComException e) {
        throw new TransientTransactionFailureException("Cannot commit this transaction on the master. " + "The master is either down, or we have network connectivity problems.", e);
    }
}
Also used : ComException(org.neo4j.com.ComException) TransientTransactionFailureException(org.neo4j.graphdb.TransientTransactionFailureException) TransactionFailureException(org.neo4j.kernel.api.exceptions.TransactionFailureException) TransactionRepresentation(org.neo4j.kernel.impl.transaction.TransactionRepresentation) TransientTransactionFailureException(org.neo4j.graphdb.TransientTransactionFailureException) RequestContext(org.neo4j.com.RequestContext) IOException(java.io.IOException)

Example 18 with TransactionFailureException

use of org.neo4j.kernel.api.exceptions.TransactionFailureException 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 19 with TransactionFailureException

use of org.neo4j.kernel.api.exceptions.TransactionFailureException in project neo4j by neo4j.

the class Rollback method exec.

@Override
protected Continuation exec(AppCommandParser parser, Session session, Output out) throws ShellException, RemoteException {
    if (parser.getLineWithoutApp().trim().length() > 0) {
        out.println("Error: ROLLBACK should  be run without trailing arguments");
        return Continuation.INPUT_COMPLETE;
    }
    KernelTransaction tx = Begin.currentTransaction(getServer());
    if (tx == null) {
        throw Commit.fail(session, "Not in a transaction");
    }
    session.remove(Variables.TX_COUNT);
    tx.failure();
    try {
        tx.close();
    } catch (TransactionFailureException e) {
        throw new ShellException(e.getMessage());
    }
    out.println("Transaction rolled back");
    return Continuation.INPUT_COMPLETE;
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) TransactionFailureException(org.neo4j.kernel.api.exceptions.TransactionFailureException) ShellException(org.neo4j.shell.ShellException)

Example 20 with TransactionFailureException

use of org.neo4j.kernel.api.exceptions.TransactionFailureException in project neo4j by neo4j.

the class SlaveLocksClientTest method mustThrowIfStartingNewLockSessionOnMasterThrowsTransactionFailureException.

@Test(expected = DistributedLockFailureException.class)
public void mustThrowIfStartingNewLockSessionOnMasterThrowsTransactionFailureException() throws Exception {
    when(master.newLockSession(any(RequestContext.class))).thenThrow(new TransactionFailureException(Status.General.DatabaseUnavailable, "Not now"));
    client.acquireShared(LockTracer.NONE, NODE, 1);
}
Also used : TransactionFailureException(org.neo4j.kernel.api.exceptions.TransactionFailureException) RequestContext(org.neo4j.com.RequestContext) Test(org.junit.Test)

Aggregations

TransactionFailureException (org.neo4j.kernel.api.exceptions.TransactionFailureException)26 Test (org.junit.Test)11 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)10 IOException (java.io.IOException)5 TransientTransactionFailureException (org.neo4j.graphdb.TransientTransactionFailureException)4 TransactionToApply (org.neo4j.kernel.impl.api.TransactionToApply)4 CreateConstraintFailureException (org.neo4j.kernel.api.exceptions.schema.CreateConstraintFailureException)3 StorageEngine (org.neo4j.storageengine.api.StorageEngine)3 ArrayList (java.util.ArrayList)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 RequestContext (org.neo4j.com.RequestContext)2 Statement (org.neo4j.kernel.api.Statement)2 ConstraintValidationException (org.neo4j.kernel.api.exceptions.schema.ConstraintValidationException)2 TransactionCommitProcess (org.neo4j.kernel.impl.api.TransactionCommitProcess)2 TransactionRepresentation (org.neo4j.kernel.impl.transaction.TransactionRepresentation)2 StorageCommand (org.neo4j.storageengine.api.StorageCommand)2 ExecutionException (java.util.concurrent.ExecutionException)1 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)1 AtomicReferenceArray (java.util.concurrent.atomic.AtomicReferenceArray)1 CatchupPollingProcess (org.neo4j.causalclustering.catchup.tx.CatchupPollingProcess)1