Search in sources :

Example 91 with MemberImpl

use of com.hazelcast.cluster.impl.MemberImpl in project hazelcast by hazelcast.

the class MembershipManager method suspectMember.

void suspectMember(MemberImpl suspectedMember, String reason, boolean closeConnection) {
    assert !suspectedMember.equals(getLocalMember()) : "Cannot suspect from myself!";
    assert !suspectedMember.localMember() : "Cannot be local member";
    final MemberMap localMemberMap;
    final Set<MemberImpl> membersToAsk;
    clusterServiceLock.lock();
    try {
        if (!clusterService.isJoined()) {
            if (logger.isFineEnabled()) {
                logger.fine("Cannot handle suspect of " + suspectedMember + " because this node is not joined...");
            }
            return;
        }
        ClusterJoinManager clusterJoinManager = clusterService.getClusterJoinManager();
        if (clusterService.isMaster() && !clusterJoinManager.isMastershipClaimInProgress()) {
            removeMember(suspectedMember, reason, closeConnection);
            return;
        }
        if (!addSuspectedMember(suspectedMember, reason, closeConnection)) {
            return;
        }
        if (!tryStartMastershipClaim()) {
            return;
        }
        localMemberMap = getMemberMap();
        membersToAsk = collectMembersToAsk(localMemberMap);
        logger.info("Local " + localMemberMap.toMembersView() + " with suspected members: " + suspectedMembers + " and initial addresses to ask: " + membersToAsk);
    } finally {
        clusterServiceLock.unlock();
    }
    ExecutorService executor = nodeEngine.getExecutionService().getExecutor(MASTERSHIP_CLAIM_EXECUTOR_NAME);
    executor.submit(new DecideNewMembersViewTask(localMemberMap, membersToAsk));
}
Also used : MemberImpl(com.hazelcast.cluster.impl.MemberImpl) ExecutorService(java.util.concurrent.ExecutorService)

Example 92 with MemberImpl

use of com.hazelcast.cluster.impl.MemberImpl in project hazelcast by hazelcast.

the class MembershipManager method decideNewMembersView.

private MembersView decideNewMembersView(MemberMap localMemberMap, Set<MemberImpl> members) {
    Map<MemberInfo, Future<MembersView>> futures = new HashMap<>();
    MembersView latestMembersView = fetchLatestMembersView(localMemberMap, members, futures);
    if (logger.isFineEnabled()) {
        logger.fine("Latest " + latestMembersView + " before final decision...");
    }
    // within the most recent members view, select the members that have reported their members view successfully
    List<MemberInfo> finalMembers = new ArrayList<>();
    for (MemberInfo member : latestMembersView.getMembers()) {
        Address address = member.getAddress();
        if (node.getThisAddress().equals(address)) {
            finalMembers.add(member);
            continue;
        }
        // if it is not certain if a member has accepted the mastership claim, its response will be ignored
        Future<MembersView> future = futures.get(member);
        if (isMemberSuspected(new MemberImpl(member.getAddress(), member.getVersion(), false, member.getUuid()))) {
            if (logger.isFineEnabled()) {
                logger.fine(member + " is excluded because suspected");
            }
            continue;
        } else if (future == null || !future.isDone()) {
            if (logger.isFineEnabled()) {
                logger.fine(member + " is excluded because I don't know its response");
            }
            continue;
        }
        addAcceptedMemberInfo(finalMembers, member, future);
    }
    int finalVersion = latestMembersView.getVersion() + 1;
    return new MembersView(finalVersion, finalMembers);
}
Also used : MemberInfo(com.hazelcast.internal.cluster.MemberInfo) Address(com.hazelcast.cluster.Address) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) MemberImpl(com.hazelcast.cluster.impl.MemberImpl) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future)

Example 93 with MemberImpl

use of com.hazelcast.cluster.impl.MemberImpl in project hazelcast by hazelcast.

the class MembershipManager method verifySplitBrainMergeMemberListVersion.

public boolean verifySplitBrainMergeMemberListVersion(SplitBrainJoinMessage joinMessage) {
    Address caller = joinMessage.getAddress();
    int callerMemberListVersion = joinMessage.getMemberListVersion();
    clusterServiceLock.lock();
    try {
        if (!clusterService.isMaster()) {
            logger.warning("Cannot verify member list version: " + callerMemberListVersion + " from " + caller + " because this node is not master");
            return false;
        } else if (clusterService.getClusterJoinManager().isMastershipClaimInProgress()) {
            logger.warning("Cannot verify member list version: " + callerMemberListVersion + " from " + caller + " because mastership claim is in progress");
            return false;
        }
        MemberMap memberMap = getMemberMap();
        if (memberMap.getVersion() < callerMemberListVersion) {
            int newVersion = callerMemberListVersion + 1;
            logger.info("Updating local member list version: " + memberMap.getVersion() + " to " + newVersion + " because of split brain merge caller: " + caller + " with member list version: " + callerMemberListVersion);
            MemberImpl[] members = memberMap.getMembers().toArray(new MemberImpl[0]);
            MemberMap newMemberMap = MemberMap.createNew(newVersion, members);
            setMembers(newMemberMap);
            sendMemberListToOthers();
            clusterService.printMemberList();
        }
        return true;
    } finally {
        clusterServiceLock.unlock();
    }
}
Also used : Address(com.hazelcast.cluster.Address) MemberImpl(com.hazelcast.cluster.impl.MemberImpl)

Example 94 with MemberImpl

use of com.hazelcast.cluster.impl.MemberImpl in project hazelcast by hazelcast.

the class MembershipManager method sendMembershipEvents.

void sendMembershipEvents(Collection<MemberImpl> currentMembers, Collection<MemberImpl> newMembers, boolean sortMembers) {
    List<Member> eventMembers = new ArrayList<>(currentMembers);
    if (!newMembers.isEmpty()) {
        for (MemberImpl newMember : newMembers) {
            // sync calls
            node.getPartitionService().memberAdded(newMember);
            node.getNodeExtension().onMemberListChange();
            // async events
            eventMembers.add(newMember);
            if (sortMembers) {
                sortMembersInMembershipOrder(eventMembers);
            }
            sendMembershipEventNotifications(newMember, unmodifiableSet(new LinkedHashSet<>(eventMembers)), true);
        }
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) MemberImpl(com.hazelcast.cluster.impl.MemberImpl) ArrayList(java.util.ArrayList) Member(com.hazelcast.cluster.Member)

Example 95 with MemberImpl

use of com.hazelcast.cluster.impl.MemberImpl in project hazelcast by hazelcast.

the class NodeMulticastListener method handleActiveAndJoined.

private void handleActiveAndJoined(JoinMessage joinMessage) {
    if (!(joinMessage instanceof JoinRequest)) {
        logDroppedMessage(joinMessage);
        return;
    }
    ClusterServiceImpl clusterService = node.getClusterService();
    Address masterAddress = clusterService.getMasterAddress();
    if (clusterService.isMaster()) {
        JoinMessage response = new JoinMessage(Packet.VERSION, node.getBuildInfo().getBuildNumber(), node.getVersion(), node.getThisAddress(), node.getThisUuid(), node.isLiteMember(), node.createConfigCheck());
        node.multicastService.send(response);
    } else if (joinMessage.getAddress().equals(masterAddress)) {
        MemberImpl master = node.getClusterService().getMember(masterAddress);
        if (master != null) {
            UUID uuidFromMaster = master.getUuid();
            UUID uuidInJoinRequest = joinMessage.getUuid();
            if (!uuidFromMaster.equals(uuidInJoinRequest)) {
                String message = "New join request has been received from current master address. " + "The UUID in the join request (" + uuidInJoinRequest + ") is different from the " + "known master one (" + uuidFromMaster + "). Suspecting the master address: " + masterAddress;
                logger.warning(message);
                // I just make a local suspicion. Probably other nodes will eventually suspect as well.
                clusterService.suspectMember(master, message, false);
            }
        }
    }
}
Also used : Address(com.hazelcast.cluster.Address) MemberImpl(com.hazelcast.cluster.impl.MemberImpl) UUID(java.util.UUID)

Aggregations

MemberImpl (com.hazelcast.cluster.impl.MemberImpl)123 Address (com.hazelcast.cluster.Address)41 Test (org.junit.Test)37 QuickTest (com.hazelcast.test.annotation.QuickTest)34 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)32 Member (com.hazelcast.cluster.Member)21 HazelcastInstance (com.hazelcast.core.HazelcastInstance)16 UUID (java.util.UUID)14 ArrayList (java.util.ArrayList)10 MemberInfo (com.hazelcast.internal.cluster.MemberInfo)9 HashMap (java.util.HashMap)9 InetAddress (java.net.InetAddress)8 HashSet (java.util.HashSet)8 ClusterService (com.hazelcast.internal.cluster.ClusterService)7 Config (com.hazelcast.config.Config)6 Future (java.util.concurrent.Future)6 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)5 StaticMemberNodeContext (com.hazelcast.instance.StaticMemberNodeContext)4 HazelcastInstanceFactory.newHazelcastInstance (com.hazelcast.instance.impl.HazelcastInstanceFactory.newHazelcastInstance)4 MembersUpdateOp (com.hazelcast.internal.cluster.impl.operations.MembersUpdateOp)4