use of org.neo4j.kernel.api.exceptions.TransactionFailureException in project neo4j by neo4j.
the class ReplicatedTransactionStateMachine method applyCommand.
@Override
public synchronized void applyCommand(ReplicatedTransaction replicatedTx, long commandIndex, Consumer<Result> callback) {
if (commandIndex <= lastCommittedIndex) {
log.debug("Ignoring transaction at log index %d since already committed up to %d", commandIndex, lastCommittedIndex);
return;
}
TransactionRepresentation tx;
byte[] extraHeader = encodeLogIndexAsTxHeader(commandIndex);
tx = ReplicatedTransactionFactory.extractTransactionRepresentation(replicatedTx, extraHeader);
int currentTokenId = lockTokenStateMachine.currentToken().id();
int txLockSessionId = tx.getLockSessionId();
if (currentTokenId != txLockSessionId && txLockSessionId != Locks.Client.NO_LOCK_SESSION_ID) {
callback.accept(Result.of(new TransactionFailureException(LockSessionExpired, "The lock session in the cluster has changed: [current lock session id:%d, tx lock session id:%d]", currentTokenId, txLockSessionId)));
} else {
try {
TransactionToApply transaction = new TransactionToApply(tx);
transaction.onClose(txId -> callback.accept(Result.of(txId)));
queue.queue(transaction);
} catch (Exception e) {
throw panicException(e);
}
}
}
use of org.neo4j.kernel.api.exceptions.TransactionFailureException in project neo4j by neo4j.
the class ReplicatedTokenHolder method createCommands.
private byte[] createCommands(String tokenName) {
StorageEngine storageEngine = dependencies.resolveDependency(StorageEngine.class);
Collection<StorageCommand> commands = new ArrayList<>();
TransactionState txState = new TxState();
int tokenId = Math.toIntExact(idGeneratorFactory.get(tokenIdType).nextId());
createToken(txState, tokenName, tokenId);
try (StorageStatement statement = storageEngine.storeReadLayer().newStatement()) {
storageEngine.createCommands(commands, txState, statement, ResourceLocker.NONE, Long.MAX_VALUE);
} catch (CreateConstraintFailureException | TransactionFailureException | ConstraintValidationException e) {
throw new RuntimeException("Unable to create token '" + tokenName + "'", e);
}
return ReplicatedTokenRequestSerializer.commandBytes(commands);
}
use of org.neo4j.kernel.api.exceptions.TransactionFailureException in project neo4j by neo4j.
the class SlaveTransactionCommitProcessTest method mustTranslateIOExceptionsToKernelTransactionFailures.
@Test
public void mustTranslateIOExceptionsToKernelTransactionFailures() throws Exception {
when(master.commit(requestContext, tx)).thenThrow(new IOException());
try {
commitProcess.commit(new TransactionToApply(tx), CommitEvent.NULL, TransactionApplicationMode.INTERNAL);
fail("commit should have thrown");
} catch (TransactionFailureException e) {
assertThat(e.status(), is((Status) Status.Transaction.TransactionCommitFailed));
}
}
use of org.neo4j.kernel.api.exceptions.TransactionFailureException in project neo4j by neo4j.
the class ReadReplicaReplicationIT method transactionsShouldNotAppearOnTheReadReplicaWhilePollingIsPaused.
@Test
public void transactionsShouldNotAppearOnTheReadReplicaWhilePollingIsPaused() throws Throwable {
// given
Cluster cluster = clusterRule.startCluster();
ReadReplicaGraphDatabase readReplicaGraphDatabase = cluster.findAnyReadReplica().database();
CatchupPollingProcess pollingClient = readReplicaGraphDatabase.getDependencyResolver().resolveDependency(CatchupPollingProcess.class);
pollingClient.stop();
cluster.coreTx((coreGraphDatabase, transaction) -> {
coreGraphDatabase.createNode();
transaction.success();
});
CoreGraphDatabase leaderDatabase = cluster.awaitLeader().database();
long transactionVisibleOnLeader = transactionIdTracker(leaderDatabase).newestEncounteredTxId();
// when the poller is paused, transaction doesn't make it to the read replica
try {
transactionIdTracker(readReplicaGraphDatabase).awaitUpToDate(transactionVisibleOnLeader, ofSeconds(3));
fail("should have thrown exception");
} catch (TransactionFailureException e) {
// expected timeout
}
// when the poller is resumed, it does make it to the read replica
pollingClient.start();
transactionIdTracker(readReplicaGraphDatabase).awaitUpToDate(transactionVisibleOnLeader, ofSeconds(3));
}
use of org.neo4j.kernel.api.exceptions.TransactionFailureException in project neo4j by neo4j.
the class AbstractConstraintCreationIT method changedConstraintsShouldResultInTransientFailure.
@Test
public void changedConstraintsShouldResultInTransientFailure() throws InterruptedException {
// Given
Runnable constraintCreation = () -> {
try (Transaction tx = db.beginTx()) {
createConstraintInRunningTx(db, KEY, PROP);
tx.success();
}
};
// When
try {
try (Transaction tx = db.beginTx()) {
Executors.newSingleThreadExecutor().submit(constraintCreation).get();
db.createNode();
tx.success();
}
fail("Exception expected");
} catch (Exception e) {
// Then
assertThat(e, instanceOf(TransientTransactionFailureException.class));
assertThat(e.getCause(), instanceOf(TransactionFailureException.class));
TransactionFailureException cause = (TransactionFailureException) e.getCause();
assertEquals(Status.Transaction.ConstraintsChanged, cause.status());
}
}
Aggregations