use of io.atomix.core.transaction.TransactionId in project atomix by atomix.
the class ConsistentMapService method commit.
/**
* Handles an commit commit (ha!).
*
* @param commit transaction commit commit
* @return commit result
*/
protected CommitResult commit(Commit<? extends TransactionCommit> commit) {
TransactionId transactionId = commit.value().transactionId();
TransactionScope transactionScope = activeTransactions.remove(transactionId);
if (transactionScope == null) {
return CommitResult.UNKNOWN_TRANSACTION_ID;
}
try {
this.currentVersion = commit.index();
return commitTransaction(transactionScope);
} catch (Exception e) {
getLogger().warn("Failure applying {}", commit, e);
throw Throwables.propagate(e);
} finally {
discardTombstones();
}
}
use of io.atomix.core.transaction.TransactionId in project atomix by atomix.
the class ConsistentMapService method rollback.
/**
* Handles an rollback commit (ha!).
*
* @param commit transaction rollback commit
* @return rollback result
*/
protected RollbackResult rollback(Commit<? extends TransactionRollback> commit) {
TransactionId transactionId = commit.value().transactionId();
TransactionScope transactionScope = activeTransactions.remove(transactionId);
if (transactionScope == null) {
return RollbackResult.UNKNOWN_TRANSACTION_ID;
} else if (!transactionScope.isPrepared()) {
discardTombstones();
return RollbackResult.OK;
} else {
try {
transactionScope.transactionLog().records().forEach(record -> {
if (record.type() != MapUpdate.Type.VERSION_MATCH) {
preparedKeys.remove(record.key());
}
});
return RollbackResult.OK;
} finally {
discardTombstones();
}
}
}
use of io.atomix.core.transaction.TransactionId in project atomix by atomix.
the class ConsistentMapService method prepareAndCommit.
/**
* Handles an prepare and commit commit.
*
* @param commit transaction prepare and commit commit
* @return prepare result
*/
protected PrepareResult prepareAndCommit(Commit<? extends TransactionPrepareAndCommit> commit) {
TransactionId transactionId = commit.value().transactionLog().transactionId();
PrepareResult prepareResult = prepare(commit);
TransactionScope transactionScope = activeTransactions.remove(transactionId);
if (prepareResult == PrepareResult.OK) {
this.currentVersion = commit.index();
transactionScope = transactionScope.prepared(commit);
commitTransaction(transactionScope);
}
discardTombstones();
return prepareResult;
}
use of io.atomix.core.transaction.TransactionId in project atomix by atomix.
the class CoreTransactionService method begin.
@Override
public CompletableFuture<TransactionId> begin() {
checkState(isRunning());
TransactionId transactionId = TransactionId.from(UUID.randomUUID().toString());
return transactions.put(transactionId, TransactionState.ACTIVE).thenApply(v -> transactionId);
}
Aggregations