Search in sources :

Example 26 with Address

use of com.hazelcast.cluster.Address in project hazelcast by hazelcast.

the class MulticastJoiner method searchForOtherClusters.

@Override
public void searchForOtherClusters() {
    node.multicastService.send(node.createSplitBrainJoinMessage());
    SplitBrainJoinMessage splitBrainMsg;
    try {
        while ((splitBrainMsg = splitBrainJoinMessages.poll(3, TimeUnit.SECONDS)) != null) {
            if (logger.isFineEnabled()) {
                logger.fine("Received  " + splitBrainMsg);
            }
            Address targetAddress = splitBrainMsg.getAddress();
            if (node.clusterService.getMember(targetAddress) != null) {
                if (logger.isFineEnabled()) {
                    logger.fine("Ignoring merge join response, since " + targetAddress + " is already a member.");
                }
                continue;
            }
            SplitBrainJoinMessage request = node.createSplitBrainJoinMessage();
            SplitBrainMergeCheckResult result = sendSplitBrainJoinMessageAndCheckResponse(targetAddress, request);
            if (result == SplitBrainMergeCheckResult.LOCAL_NODE_SHOULD_MERGE) {
                logger.warning(node.getThisAddress() + " is merging [multicast] to " + targetAddress);
                startClusterMerge(targetAddress, clusterService.getMemberListVersion());
                return;
            }
            if (result == SplitBrainMergeCheckResult.REMOTE_NODE_SHOULD_MERGE) {
                // other side should join to us. broadcast a new SplitBrainJoinMessage.
                node.multicastService.send(node.createSplitBrainJoinMessage());
            }
        }
    } catch (InterruptedException e) {
        currentThread().interrupt();
        logger.fine(e);
    } catch (Exception e) {
        logger.warning(e);
    }
}
Also used : Address(com.hazelcast.cluster.Address) SplitBrainMergeCheckResult(com.hazelcast.internal.cluster.impl.SplitBrainJoinMessage.SplitBrainMergeCheckResult)

Example 27 with Address

use of com.hazelcast.cluster.Address in project hazelcast by hazelcast.

the class MembershipManager method removeMember.

private void removeMember(MemberImpl member, String reason, boolean shouldCloseConn) {
    clusterServiceLock.lock();
    try {
        assert clusterService.isMaster() : "Master: " + clusterService.getMasterAddress();
        if (!clusterService.isJoined()) {
            logger.warning("Not removing " + member + " for reason: " + reason + ", because not joined!");
            return;
        }
        Address address = member.getAddress();
        if (shouldCloseConn) {
            closeConnections(address, reason);
        }
        MemberMap currentMembers = memberMapRef.get();
        if (currentMembers.getMember(address, member.getUuid()) == null) {
            if (logger.isFineEnabled()) {
                logger.fine("No need to remove " + member + ", not a member.");
            }
            return;
        }
        logger.info("Removing " + member);
        clusterService.getClusterJoinManager().removeJoin(address);
        clusterService.getClusterJoinManager().addLeftMember(member);
        clusterService.getClusterHeartbeatManager().removeMember(member);
        partialDisconnectionHandler.removeMember(member);
        MemberMap newMembers = MemberMap.cloneExcluding(currentMembers, member);
        setMembers(newMembers);
        node.getNodeExtension().getAuditlogService().eventBuilder(AuditlogTypeIds.CLUSTER_MEMBER_SUSPECTED).message("Member is removed").addParameter("address", address).addParameter("reason", reason).log();
        if (logger.isFineEnabled()) {
            logger.fine(member + " is removed. Publishing new member list.");
        }
        sendMemberListToOthers();
        handleMemberRemove(newMembers, member);
        clusterService.printMemberList();
    } finally {
        clusterServiceLock.unlock();
    }
}
Also used : Address(com.hazelcast.cluster.Address)

Example 28 with Address

use of com.hazelcast.cluster.Address 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 29 with Address

use of com.hazelcast.cluster.Address 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 30 with Address

use of com.hazelcast.cluster.Address in project hazelcast by hazelcast.

the class MembershipManager method clearMemberSuspicion.

boolean clearMemberSuspicion(MemberImpl member, String reason) {
    clusterServiceLock.lock();
    try {
        if (!isMemberSuspected(member)) {
            return true;
        }
        MemberMap memberMap = getMemberMap();
        Address masterAddress = clusterService.getMasterAddress();
        if (memberMap.isBeforeThan(member.getAddress(), masterAddress)) {
            if (logger.isFineEnabled()) {
                logger.fine("Not removing suspicion of " + member + " since it is before than current master " + masterAddress + " in member list.");
            }
            return false;
        }
        if (suspectedMembers.remove(member)) {
            logger.info("Removed suspicion of " + member + ". Reason: " + reason);
        }
    } finally {
        clusterServiceLock.unlock();
    }
    return true;
}
Also used : Address(com.hazelcast.cluster.Address)

Aggregations

Address (com.hazelcast.cluster.Address)540 Test (org.junit.Test)211 QuickTest (com.hazelcast.test.annotation.QuickTest)191 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)178 HazelcastInstance (com.hazelcast.core.HazelcastInstance)92 InetAddress (java.net.InetAddress)75 ArrayList (java.util.ArrayList)66 Member (com.hazelcast.cluster.Member)63 Accessors.getAddress (com.hazelcast.test.Accessors.getAddress)54 MemberImpl (com.hazelcast.cluster.impl.MemberImpl)48 Config (com.hazelcast.config.Config)43 PartitionReplica (com.hazelcast.internal.partition.PartitionReplica)43 UUID (java.util.UUID)43 ILogger (com.hazelcast.logging.ILogger)37 HashMap (java.util.HashMap)36 Operation (com.hazelcast.spi.impl.operationservice.Operation)35 List (java.util.List)35 OperationService (com.hazelcast.spi.impl.operationservice.OperationService)34 Map (java.util.Map)33 InetSocketAddress (java.net.InetSocketAddress)32