Search in sources :

Example 76 with MemberImpl

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

the class ClusterServiceImpl method promoteLocalLiteMember.

@Override
public void promoteLocalLiteMember() {
    MemberImpl member = getLocalMember();
    if (!member.isLiteMember()) {
        throw new IllegalStateException(member + " is not a lite member!");
    }
    MemberImpl master = getMasterMember();
    PromoteLiteMemberOp op = new PromoteLiteMemberOp();
    op.setCallerUuid(member.getUuid());
    InvocationFuture<MembersView> future = nodeEngine.getOperationService().invokeOnTarget(SERVICE_NAME, op, master.getAddress());
    MembersView view = future.joinInternal();
    lock.lock();
    try {
        if (!member.getAddress().equals(master.getAddress())) {
            updateMembers(view, master.getAddress(), master.getUuid(), getThisUuid());
        }
        MemberImpl localMemberInMemberList = membershipManager.getMember(member.getAddress());
        boolean result = localMemberInMemberList.isLiteMember();
        node.getNodeExtension().getAuditlogService().eventBuilder(AuditlogTypeIds.CLUSTER_PROMOTE_MEMBER).message("Promotion of the lite member").addParameter("success", result).addParameter("address", node.getThisAddress()).log();
        if (result) {
            throw new IllegalStateException("Cannot promote to data member! Previous master was: " + master.getAddress() + ", Current master is: " + getMasterAddress());
        }
    } finally {
        lock.unlock();
    }
}
Also used : MemberImpl(com.hazelcast.cluster.impl.MemberImpl) PromoteLiteMemberOp(com.hazelcast.internal.cluster.impl.operations.PromoteLiteMemberOp)

Example 77 with MemberImpl

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

the class ClusterHeartbeatManager method handleHeartbeat.

public void handleHeartbeat(MembersViewMetadata senderMembersViewMetadata, UUID receiverUuid, long timestamp, Collection<MemberInfo> suspectedMembers) {
    Address senderAddress = senderMembersViewMetadata.getMemberAddress();
    try {
        long timeout = Math.min(TimeUnit.SECONDS.toMillis(1), heartbeatIntervalMillis / 2);
        if (!clusterServiceLock.tryLock(timeout, MILLISECONDS)) {
            logger.warning("Cannot handle heartbeat from " + senderAddress + ", could not acquire lock in time.");
            return;
        }
    } catch (InterruptedException e) {
        logger.warning("Cannot handle heartbeat from " + senderAddress + ", thread interrupted.");
        Thread.currentThread().interrupt();
        return;
    }
    try {
        if (!clusterService.isJoined()) {
            if (clusterService.getThisUuid().equals(receiverUuid)) {
                logger.fine("Ignoring heartbeat of sender: " + senderMembersViewMetadata + ", because node is not joined!");
            } else {
                // we know that sender version is 3.9 so we send explicit suspicion back even if we are not joined...
                logger.fine("Sending explicit suspicion to " + senderAddress + " for heartbeat " + senderMembersViewMetadata + ", because this node has received an invalid heartbeat before it joins to the cluster");
                OperationService operationService = nodeEngine.getOperationService();
                Operation op = new ExplicitSuspicionOp(senderMembersViewMetadata);
                operationService.send(op, senderAddress);
            }
            return;
        }
        MembershipManager membershipManager = clusterService.getMembershipManager();
        MemberImpl member = membershipManager.getMember(senderAddress, senderMembersViewMetadata.getMemberUuid());
        if (member != null) {
            if (clusterService.getThisUuid().equals(receiverUuid)) {
                if (onHeartbeat(member, timestamp)) {
                    // local timestamp is used on purpose here
                    membershipManager.handleReceivedSuspectedMembers(member, clusterClock.getClusterTime(), suspectedMembers);
                }
                return;
            }
            logger.warning("Local UUID mismatch on received heartbeat. local UUID: " + clusterService.getThisUuid() + " received UUID: " + receiverUuid + " with " + senderMembersViewMetadata);
        }
        onInvalidHeartbeat(senderMembersViewMetadata);
    } finally {
        clusterServiceLock.unlock();
    }
}
Also used : Address(com.hazelcast.cluster.Address) MemberImpl(com.hazelcast.cluster.impl.MemberImpl) ExplicitSuspicionOp(com.hazelcast.internal.cluster.impl.operations.ExplicitSuspicionOp) OperationService(com.hazelcast.spi.impl.operationservice.OperationService) Operation(com.hazelcast.spi.impl.operationservice.Operation)

Example 78 with MemberImpl

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

the class PartialDisconnectionHandler method buildConnectionGraph.

private Graph<MemberImpl> buildConnectionGraph(Set<MemberImpl> members, Map<MemberImpl, Set<MemberImpl>> disconnections) {
    Graph<MemberImpl> graph = new Graph<>();
    members.forEach(graph::add);
    for (MemberImpl member1 : members) {
        for (MemberImpl member2 : members) {
            if (!isDisconnected(disconnections, member1, member2)) {
                graph.connect(member1, member2);
            }
        }
    }
    return graph;
}
Also used : Graph(com.hazelcast.internal.util.graph.Graph) MemberImpl(com.hazelcast.cluster.impl.MemberImpl)

Example 79 with MemberImpl

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

the class MemberMap method headMemberSet.

Set<MemberImpl> headMemberSet(Member member, boolean inclusive) {
    ensureMemberExist(member);
    Set<MemberImpl> result = new LinkedHashSet<>();
    for (MemberImpl m : members) {
        if (!m.equals(member)) {
            result.add(m);
            continue;
        }
        if (inclusive) {
            result.add(m);
        }
        break;
    }
    return result;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) MemberImpl(com.hazelcast.cluster.impl.MemberImpl)

Example 80 with MemberImpl

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

the class MemberMap method putMember.

private static void putMember(Map<Address, MemberImpl> addressMap, Map<UUID, MemberImpl> uuidMap, MemberImpl member) {
    MemberImpl current = addressMap.put(member.getAddress(), member);
    if (current != null) {
        throw new IllegalArgumentException("Replacing existing member with address: " + member);
    }
    current = uuidMap.put(member.getUuid(), member);
    if (current != null) {
        throw new IllegalArgumentException("Replacing existing member with UUID: " + member);
    }
}
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