Search in sources :

Example 1 with TransientTransactionFailureException

use of org.neo4j.graphdb.TransientTransactionFailureException 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 2 with TransientTransactionFailureException

use of org.neo4j.graphdb.TransientTransactionFailureException in project neo4j by neo4j.

the class PropertyConstraintsStressIT method performInserts.

/**
     * Inserts a bunch of new nodes with the label and property key currently set in the fields in this class, where
     * running this method twice will insert nodes with duplicate property values, assuming property key or label has
     * not changed.
     */
private WorkerCommand<Object, Integer> performInserts(final HighlyAvailableGraphDatabase slave, final boolean constraintCompliant) {
    return new WorkerCommand<Object, Integer>() {

        @Override
        public Integer doWork(Object state) throws Exception {
            int i = 0;
            try {
                for (; i < 100; i++) {
                    try (Transaction tx = slave.beginTx()) {
                        constraintOps.createEntity(slave, labelOrRelType, property, "value" + i, constraintCompliant);
                        tx.success();
                    }
                }
            } catch (TransactionFailureException | TransientTransactionFailureException e) {
            // Swallowed on purpose, we except it to fail sometimes due to either
            //  - constraint violation on master
            //  - concurrent schema operation on master
            } catch (ConstraintViolationException e) {
            // Constraint violation detected on slave while building transaction
            } catch (ComException e) {
            // Happens sometimes, cause:
            // - The lock session requested to start is already in use.
            //   Please retry your request in a few seconds.
            }
            return i;
        }
    };
}
Also used : ComException(org.neo4j.com.ComException) WorkerCommand(org.neo4j.test.OtherThreadExecutor.WorkerCommand) TransactionFailureException(org.neo4j.graphdb.TransactionFailureException) TransientTransactionFailureException(org.neo4j.graphdb.TransientTransactionFailureException) Transaction(org.neo4j.graphdb.Transaction) ConstraintViolationException(org.neo4j.graphdb.ConstraintViolationException) TransientTransactionFailureException(org.neo4j.graphdb.TransientTransactionFailureException)

Example 3 with TransientTransactionFailureException

use of org.neo4j.graphdb.TransientTransactionFailureException in project neo4j by neo4j.

the class TopLevelTransactionTest method shouldThrowTransientExceptionOnTransientKernelException.

@Test
public void shouldThrowTransientExceptionOnTransientKernelException() throws Exception {
    // GIVEN
    KernelTransaction kernelTransaction = mock(KernelTransaction.class);
    when(kernelTransaction.isOpen()).thenReturn(true);
    doThrow(new TransactionFailureException(Status.Transaction.ConstraintsChanged, "Proving that TopLevelTransaction does the right thing")).when(kernelTransaction).close();
    ThreadToStatementContextBridge bridge = new ThreadToStatementContextBridge();
    TopLevelTransaction transaction = new TopLevelTransaction(kernelTransaction, bridge);
    // WHEN
    transaction.success();
    try {
        transaction.close();
        fail("Should have failed");
    } catch (TransientTransactionFailureException e) {
    // THEN Good
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) TransientTransactionFailureException(org.neo4j.graphdb.TransientTransactionFailureException) TransactionFailureException(org.neo4j.kernel.api.exceptions.TransactionFailureException) ThreadToStatementContextBridge(org.neo4j.kernel.impl.core.ThreadToStatementContextBridge) TransientTransactionFailureException(org.neo4j.graphdb.TransientTransactionFailureException) TopLevelTransaction(org.neo4j.kernel.impl.coreapi.TopLevelTransaction) Test(org.junit.Test)

Aggregations

TransientTransactionFailureException (org.neo4j.graphdb.TransientTransactionFailureException)3 ComException (org.neo4j.com.ComException)2 TransactionFailureException (org.neo4j.kernel.api.exceptions.TransactionFailureException)2 IOException (java.io.IOException)1 Test (org.junit.Test)1 RequestContext (org.neo4j.com.RequestContext)1 ConstraintViolationException (org.neo4j.graphdb.ConstraintViolationException)1 Transaction (org.neo4j.graphdb.Transaction)1 TransactionFailureException (org.neo4j.graphdb.TransactionFailureException)1 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)1 ThreadToStatementContextBridge (org.neo4j.kernel.impl.core.ThreadToStatementContextBridge)1 TopLevelTransaction (org.neo4j.kernel.impl.coreapi.TopLevelTransaction)1 TransactionRepresentation (org.neo4j.kernel.impl.transaction.TransactionRepresentation)1 WorkerCommand (org.neo4j.test.OtherThreadExecutor.WorkerCommand)1