use of com.hazelcast.transaction.impl.TransactionManagerServiceImpl 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.TransactionManagerServiceImpl in project hazelcast by hazelcast.
the class CreateTxBackupLogOperation method run.
@Override
public void run() throws Exception {
TransactionManagerServiceImpl txManagerService = getService();
txManagerService.createBackupLog(callerUuid, txnId);
}
use of com.hazelcast.transaction.impl.TransactionManagerServiceImpl in project hazelcast by hazelcast.
the class ReplicateTxBackupLogOperation method run.
@Override
public void run() throws Exception {
TransactionManagerServiceImpl txManagerService = getService();
txManagerService.replicaBackupLog(records, callerUuid, txnId, timeoutMillis, startTime);
}
use of com.hazelcast.transaction.impl.TransactionManagerServiceImpl in project hazelcast by hazelcast.
the class AdvancedClusterStateTest method changeClusterState_shouldFail_whenInitiatorDies_beforePrepare.
@Test
public void changeClusterState_shouldFail_whenInitiatorDies_beforePrepare() throws Exception {
final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(3);
final HazelcastInstance[] instances = factory.newInstances();
final HazelcastInstance hz = instances[instances.length - 1];
TransactionManagerServiceImpl transactionManagerService = spyTransactionManagerService(hz);
TransactionOptions options = TransactionOptions.getDefault().setTimeout(30, TimeUnit.SECONDS);
when(transactionManagerService.newAllowedDuringPassiveStateTransaction(options)).thenAnswer(new TransactionAnswer() {
@Override
protected void beforePrepare() {
terminateInstance(hz);
}
});
try {
hz.getCluster().changeClusterState(ClusterState.FROZEN, options);
fail("`changeClusterState` should throw HazelcastInstanceNotActiveException!");
} catch (HazelcastInstanceNotActiveException ignored) {
}
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertClusterState(ClusterState.ACTIVE, instances[0], instances[1]);
}
});
}
use of com.hazelcast.transaction.impl.TransactionManagerServiceImpl in project hazelcast by hazelcast.
the class AdvancedClusterStateTest method changeClusterState_shouldFail_whenNonInitiatorMemberDies_beforePrepare.
@Test
public void changeClusterState_shouldFail_whenNonInitiatorMemberDies_beforePrepare() throws Exception {
final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(3);
final HazelcastInstance[] instances = factory.newInstances();
final HazelcastInstance hz = instances[2];
TransactionManagerServiceImpl transactionManagerService = spyTransactionManagerService(hz);
final Address address = getAddress(instances[0]);
TransactionOptions options = TransactionOptions.getDefault().setDurability(0);
when(transactionManagerService.newAllowedDuringPassiveStateTransaction(options)).thenAnswer(new TransactionAnswer() {
@Override
protected void beforePrepare() {
terminateInstance(instances[0]);
}
});
try {
hz.getCluster().changeClusterState(ClusterState.FROZEN, options);
fail("A member is terminated. Cannot commit the transaction!");
} catch (TargetNotMemberException ignored) {
}
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertClusterState(ClusterState.ACTIVE, instances[2], instances[1]);
}
});
instances[0] = factory.newHazelcastInstance(address);
assertClusterSizeEventually(3, instances[0]);
assertClusterSizeEventually(3, instances[1]);
assertClusterSizeEventually(3, instances[2]);
assertClusterState(ClusterState.ACTIVE, instances);
}
Aggregations