use of org.apache.ignite.internal.tx.TxState in project ignite-3 by apache.
the class TxManagerImpl method readLock.
/**
* {@inheritDoc}
*/
@Override
public CompletableFuture<Void> readLock(IgniteUuid lockId, ByteBuffer keyData, Timestamp ts) {
TxState state = state(ts);
if (state != null && state != TxState.PENDING) {
return failedFuture(new TransactionException("The operation is attempted for completed transaction"));
}
LockKey key = new LockKey(lockId, keyData);
return lockManager.tryAcquireShared(key, ts).thenAccept(ignored -> recordLock(key, ts, Boolean.TRUE));
}
use of org.apache.ignite.internal.tx.TxState in project ignite-3 by apache.
the class TxManagerImpl method writeLock.
/**
* {@inheritDoc}
*/
@Override
public CompletableFuture<Void> writeLock(IgniteUuid lockId, ByteBuffer keyData, Timestamp ts) {
// TODO IGNITE-15933 process tx messages in striped fasion to avoid races. But locks can be acquired from any thread !
TxState state = state(ts);
if (state != null && state != TxState.PENDING) {
return failedFuture(new TransactionException("The operation is attempted for completed transaction"));
}
// Should rollback tx on lock error.
LockKey key = new LockKey(lockId, keyData);
return lockManager.tryAcquire(key, ts).thenAccept(ignored -> recordLock(key, ts, Boolean.FALSE));
}
use of org.apache.ignite.internal.tx.TxState in project ignite-3 by apache.
the class VersionedRowStore method resolve.
/**
* Resolves a multi-versioned value depending on a viewer's timestamp.
*
* @param val The value.
* @param timestamp The timestamp
* @return New and old rows pair.
* @see #versionedRow
*/
private Pair<BinaryRow, BinaryRow> resolve(Value val, Timestamp timestamp) {
if (val.timestamp == null) {
// New or after reset.
assert val.oldRow == null : val;
return new Pair<>(val.newRow, null);
}
// Checks "inTx" condition. Will be false if this is a first transactional op.
if (val.timestamp.equals(timestamp)) {
return new Pair<>(val.newRow, val.oldRow);
}
TxState state = txManager.state(val.timestamp);
BinaryRow cur;
if (state == TxState.ABORTED) {
// Was aborted and had written a temp value.
cur = val.oldRow;
} else {
cur = val.newRow;
}
return new Pair<>(cur, cur);
}
use of org.apache.ignite.internal.tx.TxState 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;
}
Aggregations