Search in sources :

Example 1 with MemberLeftException

use of com.hazelcast.core.MemberLeftException 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 MemberLeftException

use of com.hazelcast.core.MemberLeftException in project hazelcast by hazelcast.

the class MemberListTest method testOutOfSyncMemberList.

/*
     * Sets up a situation where node3 removes the master and sets node2 as the
     * master but none of the other nodes do. This means that node3 thinks node2
     * is master but node2 thinks node1 is master.
     */
@Test
public void testOutOfSyncMemberList() throws Exception {
    List<HazelcastInstance> instanceList = buildInstances(3, 25701);
    final HazelcastInstance h1 = instanceList.get(0);
    final HazelcastInstance h2 = instanceList.get(1);
    final HazelcastInstance h3 = instanceList.get(2);
    // All three nodes join into one cluster
    assertClusterSizeEventually(3, h1);
    assertClusterSizeEventually(3, h2);
    assertClusterSizeEventually(3, h3);
    // This simulates each node reading from the other nodes in the list at regular intervals
    // This prevents the heart beat code from timing out
    final HazelcastInstance[] instances = new HazelcastInstance[] { h1, h2, h3 };
    final AtomicBoolean doingWork = new AtomicBoolean(true);
    Thread[] workThreads = new Thread[instances.length];
    for (int i = 0; i < instances.length; i++) {
        final int threadNum = i;
        workThreads[threadNum] = new Thread(new Runnable() {

            public void run() {
                while (doingWork.get()) {
                    final HazelcastInstance hz = instances[threadNum];
                    Set<Member> members = new HashSet<Member>(hz.getCluster().getMembers());
                    members.remove(hz.getCluster().getLocalMember());
                    final Map<Member, Future<String>> futures = hz.getExecutorService("test").submitToMembers(new PingCallable(), members);
                    for (Future<String> f : futures.values()) {
                        try {
                            f.get();
                        } catch (MemberLeftException ignored) {
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                    sleepSeconds(2);
                }
            }
        });
        workThreads[threadNum].start();
    }
    final Node n3 = TestUtil.getNode(h3);
    n3.clusterService.removeAddress(h1.getCluster().getLocalMember().getAddress(), null);
    // Give the cluster some time to figure things out. The merge and heartbeat code should have kicked in by this point
    sleepSeconds(30);
    doingWork.set(false);
    for (Thread t : workThreads) {
        t.join();
    }
    assertClusterSize(3, h1);
    assertClusterSize(3, h2);
    assertClusterSize(3, h3);
}
Also used : Node(com.hazelcast.instance.Node) MemberLeftException(com.hazelcast.core.MemberLeftException) IOException(java.io.IOException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Future(java.util.concurrent.Future) Member(com.hazelcast.core.Member) HashSet(java.util.HashSet) MemberLeftException(com.hazelcast.core.MemberLeftException) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Example 3 with MemberLeftException

use of com.hazelcast.core.MemberLeftException in project hazelcast by hazelcast.

the class AuthenticationBaseMessageTask method reduce.

@Override
protected Object reduce(Map<Member, Object> map) throws Throwable {
    for (Map.Entry<Member, Object> entry : map.entrySet()) {
        Member member = entry.getKey();
        Object response = entry.getValue();
        if (response instanceof Throwable) {
            if (response instanceof MemberLeftException) {
                cleanedUpMembers.add(member);
                continue;
            }
            throw (Throwable) response;
        }
        boolean isClientDisconnectOperationRun = (Boolean) response;
        if (isClientDisconnectOperationRun) {
            cleanedUpMembers.add(member);
        }
    }
    return prepareAuthenticatedClientMessage();
}
Also used : Map(java.util.Map) Member(com.hazelcast.core.Member) MemberLeftException(com.hazelcast.core.MemberLeftException)

Example 4 with MemberLeftException

use of com.hazelcast.core.MemberLeftException in project hazelcast by hazelcast.

the class SerializationTest method testMemberLeftException.

private void testMemberLeftException(String uuid, String host, int port, Member member) throws Exception {
    MemberLeftException exception = new MemberLeftException(member);
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    ObjectOutputStream out = new ObjectOutputStream(bout);
    out.writeObject(exception);
    ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
    ObjectInputStream in = new ObjectInputStream(bin);
    MemberLeftException exception2 = (MemberLeftException) in.readObject();
    MemberImpl member2 = (MemberImpl) exception2.getMember();
    assertEquals(uuid, member2.getUuid());
    assertEquals(host, member2.getAddress().getHost());
    assertEquals(port, member2.getAddress().getPort());
    assertEquals(member.isLiteMember(), member2.isLiteMember());
    assertEquals(member.getVersion(), member2.getVersion());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) SimpleMemberImpl(com.hazelcast.instance.SimpleMemberImpl) MemberImpl(com.hazelcast.instance.MemberImpl) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) MemberLeftException(com.hazelcast.core.MemberLeftException) ObjectInputStream(java.io.ObjectInputStream)

Example 5 with MemberLeftException

use of com.hazelcast.core.MemberLeftException 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);
    }
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) ClusterState(com.hazelcast.cluster.ClusterState) TargetNotMemberException(com.hazelcast.spi.exception.TargetNotMemberException) Transaction(com.hazelcast.transaction.impl.Transaction) TransactionManagerServiceImpl(com.hazelcast.transaction.impl.TransactionManagerServiceImpl) MemberImpl(com.hazelcast.cluster.impl.MemberImpl) UUID(java.util.UUID) MemberLeftException(com.hazelcast.core.MemberLeftException)

Aggregations

MemberLeftException (com.hazelcast.core.MemberLeftException)17 TargetNotMemberException (com.hazelcast.spi.exception.TargetNotMemberException)8 Member (com.hazelcast.cluster.Member)4 ExecutionException (java.util.concurrent.ExecutionException)4 Test (org.junit.Test)4 Address (com.hazelcast.cluster.Address)3 HazelcastInstance (com.hazelcast.core.HazelcastInstance)3 HazelcastInstanceNotActiveException (com.hazelcast.core.HazelcastInstanceNotActiveException)3 QuickTest (com.hazelcast.test.annotation.QuickTest)3 ArrayList (java.util.ArrayList)3 MemberImpl (com.hazelcast.cluster.impl.MemberImpl)2 Config (com.hazelcast.config.Config)2 Member (com.hazelcast.core.Member)2 SimpleMemberImpl (com.hazelcast.instance.SimpleMemberImpl)2 ClusterServiceImpl (com.hazelcast.internal.cluster.impl.ClusterServiceImpl)2 Data (com.hazelcast.internal.serialization.Data)2 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)2 SerializableList (com.hazelcast.spi.impl.SerializableList)2 Operation (com.hazelcast.spi.impl.operationservice.Operation)2 AssertTask (com.hazelcast.test.AssertTask)2