Search in sources :

Example 1 with TransactionalCommand

use of org.apache.ignite.internal.table.distributed.command.TransactionalCommand in project ignite-3 by apache.

the class PartitionListener method tryEnlistIntoTransaction.

/**
 * Attempts to enlist a command into a transaction.
 *
 * @param command The command.
 * @param clo     The closure.
 * @return {@code true} if a command is compatible with a transaction state or a command is not transactional.
 */
private boolean tryEnlistIntoTransaction(Command command, CommandClosure<?> clo) {
    if (command instanceof TransactionalCommand) {
        Timestamp ts = ((TransactionalCommand) command).getTimestamp();
        TxState state = txManager.getOrCreateTransaction(ts);
        if (state != null && state != TxState.PENDING) {
            clo.result(new TransactionException(format("Failed to enlist a key into a transaction, state={}", state)));
            return false;
        }
    }
    return true;
}
Also used : TransactionException(org.apache.ignite.tx.TransactionException) TxState(org.apache.ignite.internal.tx.TxState) Timestamp(org.apache.ignite.internal.tx.Timestamp) TransactionalCommand(org.apache.ignite.internal.table.distributed.command.TransactionalCommand)

Aggregations

TransactionalCommand (org.apache.ignite.internal.table.distributed.command.TransactionalCommand)1 Timestamp (org.apache.ignite.internal.tx.Timestamp)1 TxState (org.apache.ignite.internal.tx.TxState)1 TransactionException (org.apache.ignite.tx.TransactionException)1