Search in sources :

Example 1 with TransactionManagerServiceImpl

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);
    }
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) TargetNotMemberException(com.hazelcast.spi.exception.TargetNotMemberException) Transaction(com.hazelcast.transaction.impl.Transaction) TransactionManagerServiceImpl(com.hazelcast.transaction.impl.TransactionManagerServiceImpl) MemberLeftException(com.hazelcast.core.MemberLeftException)

Example 2 with TransactionManagerServiceImpl

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);
}
Also used : TransactionManagerServiceImpl(com.hazelcast.transaction.impl.TransactionManagerServiceImpl)

Example 3 with TransactionManagerServiceImpl

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);
}
Also used : TransactionManagerServiceImpl(com.hazelcast.transaction.impl.TransactionManagerServiceImpl)

Example 4 with TransactionManagerServiceImpl

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]);
        }
    });
}
Also used : HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) HazelcastInstance(com.hazelcast.core.HazelcastInstance) TransactionManagerServiceImpl(com.hazelcast.transaction.impl.TransactionManagerServiceImpl) TransactionOptions(com.hazelcast.transaction.TransactionOptions) AssertTask(com.hazelcast.test.AssertTask) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) TargetNotMemberException(com.hazelcast.spi.exception.TargetNotMemberException) TransactionException(com.hazelcast.transaction.TransactionException) ExecutionException(java.util.concurrent.ExecutionException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 5 with TransactionManagerServiceImpl

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);
}
Also used : TargetNotMemberException(com.hazelcast.spi.exception.TargetNotMemberException) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Address(com.hazelcast.nio.Address) TransactionManagerServiceImpl(com.hazelcast.transaction.impl.TransactionManagerServiceImpl) TransactionOptions(com.hazelcast.transaction.TransactionOptions) AssertTask(com.hazelcast.test.AssertTask) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) TargetNotMemberException(com.hazelcast.spi.exception.TargetNotMemberException) TransactionException(com.hazelcast.transaction.TransactionException) ExecutionException(java.util.concurrent.ExecutionException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

TransactionManagerServiceImpl (com.hazelcast.transaction.impl.TransactionManagerServiceImpl)14 TargetNotMemberException (com.hazelcast.spi.exception.TargetNotMemberException)7 TransactionOptions (com.hazelcast.transaction.TransactionOptions)7 HazelcastInstance (com.hazelcast.core.HazelcastInstance)6 HazelcastInstanceNotActiveException (com.hazelcast.core.HazelcastInstanceNotActiveException)6 AssertTask (com.hazelcast.test.AssertTask)6 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)6 ParallelTest (com.hazelcast.test.annotation.ParallelTest)6 QuickTest (com.hazelcast.test.annotation.QuickTest)6 TransactionException (com.hazelcast.transaction.TransactionException)6 ExecutionException (java.util.concurrent.ExecutionException)6 Test (org.junit.Test)6 Address (com.hazelcast.nio.Address)2 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)2 MemberLeftException (com.hazelcast.core.MemberLeftException)1 TransactionContext (com.hazelcast.transaction.TransactionContext)1 Transaction (com.hazelcast.transaction.impl.Transaction)1 Field (java.lang.reflect.Field)1