Search in sources :

Example 71 with MemberImpl

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

the class Node method createSplitBrainJoinMessage.

public SplitBrainJoinMessage createSplitBrainJoinMessage() {
    MemberImpl localMember = getLocalMember();
    boolean liteMember = localMember.isLiteMember();
    Collection<Address> memberAddresses = clusterService.getMemberAddresses();
    int dataMemberCount = clusterService.getSize(DATA_MEMBER_SELECTOR);
    Version clusterVersion = clusterService.getClusterVersion();
    int memberListVersion = clusterService.getMembershipManager().getMemberListVersion();
    return new SplitBrainJoinMessage(Packet.VERSION, buildInfo.getBuildNumber(), version, address, localMember.getUuid(), liteMember, createConfigCheck(), memberAddresses, dataMemberCount, clusterVersion, memberListVersion);
}
Also used : Address(com.hazelcast.cluster.Address) AliasedDiscoveryConfigUtils.allUsePublicAddress(com.hazelcast.internal.config.AliasedDiscoveryConfigUtils.allUsePublicAddress) Version(com.hazelcast.version.Version) MemberVersion(com.hazelcast.version.MemberVersion) MemberImpl(com.hazelcast.cluster.impl.MemberImpl) SplitBrainJoinMessage(com.hazelcast.internal.cluster.impl.SplitBrainJoinMessage)

Example 72 with MemberImpl

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

the class Node method createJoinRequest.

public JoinRequest createJoinRequest(Address remoteAddress) {
    final Credentials credentials = (remoteAddress != null && securityContext != null) ? securityContext.getCredentialsFactory().newCredentials(remoteAddress) : null;
    final Set<UUID> excludedMemberUuids = nodeExtension.getInternalHotRestartService().getExcludedMemberUuids();
    MemberImpl localMember = getLocalMember();
    return new JoinRequest(Packet.VERSION, buildInfo.getBuildNumber(), version, address, localMember.getUuid(), localMember.isLiteMember(), createConfigCheck(), credentials, localMember.getAttributes(), excludedMemberUuids, localMember.getAddressMap());
}
Also used : MemberImpl(com.hazelcast.cluster.impl.MemberImpl) JoinRequest(com.hazelcast.internal.cluster.impl.JoinRequest) UUID(java.util.UUID) Credentials(com.hazelcast.security.Credentials)

Example 73 with MemberImpl

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

the class ClusterJoinManager method startJoin.

/**
 * Starts join process on master member.
 */
private void startJoin() {
    logger.fine("Starting join...");
    clusterServiceLock.lock();
    try {
        InternalPartitionService partitionService = node.getPartitionService();
        boolean shouldTriggerRepartition = true;
        try {
            joinInProgress = true;
            // pause migrations until join, member-update and post-join operations are completed
            partitionService.pauseMigration();
            MemberMap memberMap = clusterService.getMembershipManager().getMemberMap();
            MembersView newMembersView = MembersView.cloneAdding(memberMap.toMembersView(), joiningMembers.values());
            long time = clusterClock.getClusterTime();
            // member list must be updated on master before preparation of pre-/post-join ops so other operations which have
            // to be executed on stable cluster can detect the member list version change and retry in case of topology change
            UUID thisUuid = clusterService.getThisUuid();
            if (!clusterService.updateMembers(newMembersView, node.getThisAddress(), thisUuid, thisUuid)) {
                return;
            }
            // post join operations must be lock free, that means no locks at all:
            // no partition locks, no key-based locks, no service level locks!
            OnJoinOp preJoinOp = preparePreJoinOps();
            OnJoinOp postJoinOp = preparePostJoinOp();
            // this is the current partition assignment state, not taking into account the
            // currently joining members
            PartitionRuntimeState partitionRuntimeState = partitionService.createPartitionState();
            for (MemberInfo member : joiningMembers.values()) {
                if (isMemberRestartingWithPersistence(member.getAttributes()) && isMemberRejoining(memberMap, member.getAddress(), member.getUuid())) {
                    logger.info(member + " is rejoining the cluster");
                    // do not trigger repartition immediately, wait for joining member to load hot-restart data
                    shouldTriggerRepartition = false;
                }
                long startTime = clusterClock.getClusterStartTime();
                Operation op = new FinalizeJoinOp(member.getUuid(), newMembersView, preJoinOp, postJoinOp, time, clusterService.getClusterId(), startTime, clusterStateManager.getState(), clusterService.getClusterVersion(), partitionRuntimeState, !shouldTriggerRepartition);
                op.setCallerUuid(thisUuid);
                invokeClusterOp(op, member.getAddress());
            }
            for (MemberImpl member : memberMap.getMembers()) {
                if (member.localMember() || joiningMembers.containsKey(member.getAddress())) {
                    continue;
                }
                Operation op = new MembersUpdateOp(member.getUuid(), newMembersView, time, partitionRuntimeState, true);
                op.setCallerUuid(thisUuid);
                invokeClusterOp(op, member.getAddress());
            }
        } finally {
            reset();
            if (shouldTriggerRepartition) {
                partitionService.resumeMigration();
            }
        }
    } finally {
        clusterServiceLock.unlock();
    }
}
Also used : InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) MembersUpdateOp(com.hazelcast.internal.cluster.impl.operations.MembersUpdateOp) MemberImpl(com.hazelcast.cluster.impl.MemberImpl) Operation(com.hazelcast.spi.impl.operationservice.Operation) FinalizeJoinOp(com.hazelcast.internal.cluster.impl.operations.FinalizeJoinOp) OnJoinOp(com.hazelcast.internal.cluster.impl.operations.OnJoinOp) MemberInfo(com.hazelcast.internal.cluster.MemberInfo) PartitionRuntimeState(com.hazelcast.internal.partition.PartitionRuntimeState) UUID(java.util.UUID)

Example 74 with MemberImpl

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

the class ClusterServiceImpl method promoteAndGetLocalMember.

MemberImpl promoteAndGetLocalMember() {
    MemberImpl member = getLocalMember();
    assert member.isLiteMember() : "Local member is not lite member!";
    assert lock.isHeldByCurrentThread() : "Called without holding cluster service lock!";
    localMember = new MemberImpl.Builder(member.getAddressMap()).version(member.getVersion()).localMember(true).uuid(member.getUuid()).attributes(member.getAttributes()).memberListJoinVersion(member.getMemberListJoinVersion()).instance(node.hazelcastInstance).build();
    node.loggingService.setThisMember(localMember);
    return localMember;
}
Also used : MemberImpl(com.hazelcast.cluster.impl.MemberImpl)

Example 75 with MemberImpl

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

the class ClusterServiceImpl method handleMastershipClaim.

public MembersView handleMastershipClaim(@Nonnull Address candidateAddress, @Nonnull UUID candidateUuid) {
    checkNotNull(candidateAddress);
    checkNotNull(candidateUuid);
    checkFalse(getThisAddress().equals(candidateAddress), "cannot accept my own mastership claim!");
    lock.lock();
    try {
        checkTrue(isJoined(), candidateAddress + " claims mastership but this node is not joined!");
        checkFalse(isMaster(), candidateAddress + " claims mastership but this node is master!");
        MemberImpl masterCandidate = membershipManager.getMember(candidateAddress, candidateUuid);
        checkTrue(masterCandidate != null, candidateAddress + " claims mastership but it is not a member!");
        MemberMap memberMap = membershipManager.getMemberMap();
        if (!shouldAcceptMastership(memberMap, masterCandidate)) {
            String message = "Cannot accept mastership claim of " + candidateAddress + " at the moment. There are more suitable master candidates in the member list.";
            logger.fine(message);
            throw new RetryableHazelcastException(message);
        }
        if (!membershipManager.clearMemberSuspicion(masterCandidate, "Mastership claim")) {
            throw new IllegalStateException("Cannot accept mastership claim of " + candidateAddress + ". " + getMasterAddress() + " is already master.");
        }
        setMasterAddress(masterCandidate.getAddress());
        MembersView response = memberMap.toTailMembersView(masterCandidate, true);
        logger.warning("Mastership of " + candidateAddress + " is accepted. Response: " + response);
        return response;
    } finally {
        lock.unlock();
    }
}
Also used : RetryableHazelcastException(com.hazelcast.spi.exception.RetryableHazelcastException) 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