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);
}
}
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;
}
};
}
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
}
}
Aggregations