use of com.hazelcast.transaction.impl.Transaction in project hazelcast by hazelcast.
the class ClusterStateManager method changeClusterState.
void changeClusterState(ClusterStateChange newState, Collection<Member> members, TransactionOptions options, int partitionStateVersion, boolean isTransient) {
checkParameters(newState, options);
if (isCurrentStateEqualToRequestedOne(newState)) {
return;
}
NodeEngineImpl nodeEngine = node.getNodeEngine();
TransactionManagerServiceImpl txManagerService = (TransactionManagerServiceImpl) nodeEngine.getTransactionManagerService();
Transaction tx = txManagerService.newAllowedDuringPassiveStateTransaction(options);
tx.begin();
try {
String txnId = tx.getTxnId();
addTransactionRecords(newState, tx, members, partitionStateVersion, isTransient);
lockClusterStateOnAllMembers(newState, nodeEngine, options.getTimeoutMillis(), txnId, members, partitionStateVersion);
checkMemberListChange(members);
tx.prepare();
} catch (Throwable e) {
tx.rollback();
throw ExceptionUtil.rethrow(e);
}
try {
tx.commit();
} catch (Throwable e) {
if (e instanceof TargetNotMemberException || e.getCause() instanceof MemberLeftException) {
// if new state is passive or frozen. They will be able to rejoin later.
return;
}
throw ExceptionUtil.rethrow(e);
}
}
use of com.hazelcast.transaction.impl.Transaction in project hazelcast by hazelcast.
the class ClusterStateManager method changeClusterState.
void changeClusterState(@Nonnull ClusterStateChange stateChange, @Nonnull MemberMap memberMap, @Nonnull TransactionOptions options, long partitionStateStamp, boolean isTransient) {
checkParameters(stateChange, options);
if (isCurrentStateEqualToRequestedOne(stateChange)) {
return;
}
ClusterState oldState = getState();
ClusterState requestedState = stateChange.getClusterStateOrNull();
NodeEngineImpl nodeEngine = node.getNodeEngine();
TransactionManagerServiceImpl txManagerService = (TransactionManagerServiceImpl) nodeEngine.getTransactionManagerService();
Transaction tx = txManagerService.newAllowedDuringPassiveStateTransaction(options);
notifyBeforeStateChange(oldState, requestedState, isTransient);
tx.begin();
try {
UUID txnId = tx.getTxnId();
Collection<MemberImpl> members = memberMap.getMembers();
int memberListVersion = memberMap.getVersion();
addTransactionRecords(stateChange, tx, members, memberListVersion, partitionStateStamp, isTransient);
lockClusterStateOnAllMembers(stateChange, nodeEngine, options.getTimeoutMillis(), txnId, members, memberListVersion, partitionStateStamp);
checkMemberListChange(memberListVersion);
tx.prepare();
} catch (Throwable e) {
tx.rollback();
notifyAfterStateChange(oldState, requestedState, isTransient);
if (e instanceof TargetNotMemberException || e.getCause() instanceof MemberLeftException) {
throw new IllegalStateException("Cluster members changed during state change!", e);
}
throw ExceptionUtil.rethrow(e);
}
try {
tx.commit();
} catch (Throwable e) {
if (e instanceof TargetNotMemberException || e.getCause() instanceof MemberLeftException) {
// if new state is passive or frozen. They will be able to rejoin later.
return;
}
throw ExceptionUtil.rethrow(e);
} finally {
notifyAfterStateChange(oldState, requestedState, isTransient);
}
}
use of com.hazelcast.transaction.impl.Transaction in project hazelcast by hazelcast.
the class XAResourceImpl method commit.
@Override
public void commit(Xid xid, boolean onePhase) throws XAException {
List<TransactionContext> contexts = xidContextMap.remove(xid);
if (contexts == null && onePhase) {
throw new XAException("There is no TransactionContexts for the given xid: " + xid);
}
if (contexts == null) {
finalizeTransactionRemotely(xid, true);
return;
}
for (TransactionContext context : contexts) {
Transaction transaction = getTransaction(context);
if (onePhase) {
transaction.prepare();
}
transaction.commit();
}
clearRemoteTransactions(xid);
}
use of com.hazelcast.transaction.impl.Transaction in project hazelcast by hazelcast.
the class XATransactionRollbackMessageTask method call.
@Override
protected Object call() throws Exception {
UUID transactionId = parameters;
TransactionContext transactionContext = endpoint.getTransactionContext(transactionId);
if (transactionContext == null) {
throw new TransactionException("No transaction context with given transactionId: " + transactionId);
}
Transaction transaction = TransactionAccessor.getTransaction(transactionContext);
transaction.rollback();
endpoint.removeTransactionContext(transactionId);
return null;
}
use of com.hazelcast.transaction.impl.Transaction in project hazelcast by hazelcast.
the class XATransactionPrepareMessageTask method call.
@Override
protected Object call() throws Exception {
UUID transactionId = parameters;
TransactionContext transactionContext = endpoint.getTransactionContext(transactionId);
if (transactionContext == null) {
throw new TransactionException("No transaction context with given transactionId: " + transactionId);
}
Transaction transaction = TransactionAccessor.getTransaction(transactionContext);
transaction.prepare();
return null;
}
Aggregations