Search in sources :

Example 86 with MemberImpl

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

the class MembershipManager method shrinkMissingMembers.

void shrinkMissingMembers(Collection<UUID> memberUuidsToRemove) {
    clusterServiceLock.lock();
    try {
        Map<Object, MemberImpl> m = new HashMap<>(missingMembersRef.get());
        Iterator<MemberImpl> it = m.values().iterator();
        while (it.hasNext()) {
            MemberImpl member = it.next();
            if (memberUuidsToRemove.contains(member.getUuid())) {
                if (logger.isFineEnabled()) {
                    logger.fine("Removing " + member + " from members removed in not joinable state.");
                }
                it.remove();
            }
        }
        missingMembersRef.set(unmodifiableMap(m));
    } finally {
        clusterServiceLock.unlock();
    }
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) MemberImpl(com.hazelcast.cluster.impl.MemberImpl)

Example 87 with MemberImpl

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

the class MembershipManager method handleExplicitSuspicion.

void handleExplicitSuspicion(MembersViewMetadata expectedMembersViewMetadata, Address suspectedAddress) {
    clusterServiceLock.lock();
    try {
        MembersViewMetadata localMembersViewMetadata = createLocalMembersViewMetadata();
        if (!localMembersViewMetadata.equals(expectedMembersViewMetadata)) {
            if (logger.isFineEnabled()) {
                logger.fine("Ignoring explicit suspicion of " + suspectedAddress + ". Expected: " + expectedMembersViewMetadata + ", Local: " + localMembersViewMetadata);
            }
            return;
        }
        MemberImpl suspectedMember = getMember(suspectedAddress);
        if (suspectedMember == null) {
            if (logger.isFineEnabled()) {
                logger.fine("No need for explicit suspicion, " + suspectedAddress + " is not a member.");
            }
            return;
        }
        suspectMember(suspectedMember, "explicit suspicion", true);
    } finally {
        clusterServiceLock.unlock();
    }
}
Also used : MemberImpl(com.hazelcast.cluster.impl.MemberImpl)

Example 88 with MemberImpl

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

the class MembershipManager method sendMemberListToMember.

/**
 * Sends the current member list to the {@code target}. Called on the master node.
 *
 * @param target the destination for the member update operation
 */
public void sendMemberListToMember(Address target) {
    clusterServiceLock.lock();
    try {
        if (!clusterService.isMaster() || !clusterService.isJoined()) {
            if (logger.isFineEnabled()) {
                logger.fine("Cannot publish member list to " + target + ". Is-master: " + clusterService.isMaster() + ", joined: " + clusterService.isJoined());
            }
            return;
        }
        if (clusterService.getThisAddress().equals(target)) {
            return;
        }
        MemberMap memberMap = memberMapRef.get();
        MemberImpl member = memberMap.getMember(target);
        if (member == null) {
            if (logger.isFineEnabled()) {
                logger.fine("Not member: " + target + ", cannot send member list.");
            }
            return;
        }
        if (logger.isFineEnabled()) {
            logger.fine("Sending member list to member: " + target + " " + memberListString());
        }
        MembersUpdateOp op = new MembersUpdateOp(member.getUuid(), memberMap.toMembersView(), clusterService.getClusterTime(), null, false);
        op.setCallerUuid(clusterService.getThisUuid());
        nodeEngine.getOperationService().send(op, target);
    } finally {
        clusterServiceLock.unlock();
    }
}
Also used : MembersUpdateOp(com.hazelcast.internal.cluster.impl.operations.MembersUpdateOp) MemberImpl(com.hazelcast.cluster.impl.MemberImpl)

Example 89 with MemberImpl

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

the class MembershipManager method setMissingMembers.

void setMissingMembers(Collection<MemberImpl> members) {
    clusterServiceLock.lock();
    try {
        Map<Object, MemberImpl> m = new HashMap<>(members.size());
        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));
    } finally {
        clusterServiceLock.unlock();
    }
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) MemberImpl(com.hazelcast.cluster.impl.MemberImpl)

Example 90 with MemberImpl

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

the class MembershipManager method promoteToDataMember.

public MembersView promoteToDataMember(Address address, UUID uuid) {
    clusterServiceLock.lock();
    try {
        ensureLiteMemberPromotionIsAllowed();
        MemberMap memberMap = getMemberMap();
        MemberImpl member = memberMap.getMember(address, uuid);
        if (member == null) {
            throw new IllegalStateException(uuid + "/" + address + " is not a member!");
        }
        if (!member.isLiteMember()) {
            if (logger.isFineEnabled()) {
                logger.fine(member + " is not lite member, no promotion is required.");
            }
            return memberMap.toMembersView();
        }
        logger.info("Promoting " + member + " to normal member.");
        MemberImpl[] members = memberMap.getMembers().toArray(new MemberImpl[0]);
        for (int i = 0; i < members.length; i++) {
            if (member.equals(members[i])) {
                if (member.localMember()) {
                    member = clusterService.promoteAndGetLocalMember();
                } else {
                    member = new MemberImpl.Builder(member.getAddressMap()).version(member.getVersion()).localMember(member.localMember()).uuid(member.getUuid()).attributes(member.getAttributes()).memberListJoinVersion(members[i].getMemberListJoinVersion()).instance(node.hazelcastInstance).build();
                }
                members[i] = member;
                break;
            }
        }
        MemberMap newMemberMap = MemberMap.createNew(memberMap.getVersion() + 1, members);
        setMembers(newMemberMap);
        sendMemberListToOthers();
        node.partitionService.memberAdded(member);
        clusterService.printMemberList();
        return newMemberMap.toMembersView();
    } finally {
        clusterServiceLock.unlock();
    }
}
Also used : 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