Search in sources :

Example 6 with MemberImpl

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

the class MembershipManager method removeFromMissingMembers.

private void removeFromMissingMembers(MemberImpl... members) {
    Map<Object, MemberImpl> m = new HashMap<>(missingMembersRef.get());
    if (isHotRestartEnabled()) {
        for (MemberImpl member : members) {
            m.remove(member.getUuid());
        }
    } else {
        for (MemberImpl member : members) {
            m.remove(member.getAddress());
        }
    }
    missingMembersRef.set(unmodifiableMap(m));
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) MemberImpl(com.hazelcast.cluster.impl.MemberImpl)

Example 7 with MemberImpl

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

the class MembershipManager method fetchMembersViewFromNewMembers.

private boolean fetchMembersViewFromNewMembers(MembersView membersView, Map<MemberInfo, Future<MembersView>> futures) {
    boolean isNewMemberPresent = false;
    for (MemberInfo member : membersView.getMembers()) {
        Address memberAddress = member.getAddress();
        if (!(node.getThisAddress().equals(memberAddress) || isMemberSuspected(new MemberImpl(member.getAddress(), member.getVersion(), false, member.getUuid())) || futures.containsKey(member))) {
            // this is a new member for us. lets ask its members view
            if (logger.isFineEnabled()) {
                logger.fine("Asking MembersView of " + memberAddress);
            }
            futures.put(member, invokeFetchMembersViewOp(memberAddress, member.getUuid()));
            isNewMemberPresent = true;
        }
    }
    return isNewMemberPresent;
}
Also used : MemberInfo(com.hazelcast.internal.cluster.MemberInfo) Address(com.hazelcast.cluster.Address) MemberImpl(com.hazelcast.cluster.impl.MemberImpl)

Example 8 with MemberImpl

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

the class MembershipManager method repairPartitionTableIfReturningMember.

private void repairPartitionTableIfReturningMember(MemberImpl member) {
    if (!clusterService.isMaster()) {
        return;
    }
    if (clusterService.getClusterState().isMigrationAllowed()) {
        return;
    }
    if (!node.getNodeExtension().isStartCompleted()) {
        return;
    }
    MemberImpl missingMember = getMissingMember(member.getAddress(), member.getUuid());
    if (missingMember != null) {
        boolean repair;
        Level level;
        if (isHotRestartEnabled()) {
            repair = !missingMember.getAddress().equals(member.getAddress());
            level = Level.INFO;
        } else {
            repair = !missingMember.getUuid().equals(member.getUuid());
            level = Level.FINE;
        }
        if (repair) {
            logger.log(level, member + " is returning with a new identity. Old one was: " + missingMember + ". Will update partition table with the new identity.");
            InternalPartitionServiceImpl partitionService = node.partitionService;
            partitionService.replaceMember(missingMember, member);
        }
    }
}
Also used : MemberImpl(com.hazelcast.cluster.impl.MemberImpl) InternalPartitionServiceImpl(com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl) Level(java.util.logging.Level)

Example 9 with MemberImpl

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

the class MembershipManager method updateMembers.

// handles both new and left members
void updateMembers(MembersView membersView) {
    MemberMap currentMemberMap = memberMapRef.get();
    Collection<MemberImpl> addedMembers = new LinkedList<>();
    Collection<MemberImpl> removedMembers = new LinkedList<>();
    ClusterHeartbeatManager clusterHeartbeatManager = clusterService.getClusterHeartbeatManager();
    MemberImpl[] members = new MemberImpl[membersView.size()];
    int memberIndex = 0;
    // Indicates whether we received a notification on lite member membership change
    // (e.g. its promotion to a data member)
    boolean updatedLiteMember = false;
    for (MemberInfo memberInfo : membersView.getMembers()) {
        Address address = memberInfo.getAddress();
        MemberImpl member = currentMemberMap.getMember(address);
        if (member != null && member.getUuid().equals(memberInfo.getUuid())) {
            if (member.isLiteMember()) {
                updatedLiteMember = true;
            }
            member = createNewMemberImplIfChanged(memberInfo, member);
            members[memberIndex++] = member;
            continue;
        }
        if (member != null) {
            assert !(member.localMember() && member.equals(getLocalMember())) : "Local " + member + " cannot be replaced with " + memberInfo;
            // UUID changed: means member has gone and come back with a new uuid
            removedMembers.add(member);
        }
        member = createMember(memberInfo, memberInfo.getAttributes());
        addedMembers.add(member);
        long now = clusterService.getClusterTime();
        clusterHeartbeatManager.onHeartbeat(member, now);
        repairPartitionTableIfReturningMember(member);
        members[memberIndex++] = member;
    }
    MemberMap newMemberMap = membersView.toMemberMap();
    for (MemberImpl member : currentMemberMap.getMembers()) {
        if (!newMemberMap.contains(member.getAddress())) {
            removedMembers.add(member);
        }
    }
    setMembers(MemberMap.createNew(membersView.getVersion(), members));
    if (updatedLiteMember) {
        node.partitionService.updateMemberGroupSize();
    }
    for (MemberImpl member : removedMembers) {
        closeConnections(member.getAddress(), "Member left event received from master");
        handleMemberRemove(memberMapRef.get(), member);
    }
    clusterService.getClusterJoinManager().insertIntoRecentlyJoinedMemberSet(addedMembers);
    sendMembershipEvents(currentMemberMap.getMembers(), addedMembers, !clusterService.isJoined());
    removeFromMissingMembers(members);
    clusterHeartbeatManager.heartbeat();
    clusterService.printMemberList();
    // async call
    node.getNodeExtension().scheduleClusterVersionAutoUpgrade();
}
Also used : MemberInfo(com.hazelcast.internal.cluster.MemberInfo) Address(com.hazelcast.cluster.Address) MemberImpl(com.hazelcast.cluster.impl.MemberImpl) LinkedList(java.util.LinkedList)

Example 10 with MemberImpl

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

the class MembershipManager method addToMissingMembers.

private void addToMissingMembers(MemberImpl... members) {
    Map<Object, MemberImpl> m = new HashMap<>(missingMembersRef.get());
    if (isHotRestartEnabled()) {
        for (MemberImpl member : members) {
            m.put(member.getUuid(), member);
        }
    } else {
        for (MemberImpl member : members) {
            m.put(member.getAddress(), member);
        }
    }
    missingMembersRef.set(unmodifiableMap(m));
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) MemberImpl(com.hazelcast.cluster.impl.MemberImpl)

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