Search in sources :

Example 11 with MemberImpl

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

the class MembershipManager method sendMemberListToOthers.

/**
 * Invoked on the master to send the member list (see {@link MembersUpdateOp}) to non-master nodes.
 */
private void sendMemberListToOthers() {
    if (!clusterService.isMaster() || !clusterService.isJoined() || clusterService.getClusterJoinManager().isMastershipClaimInProgress()) {
        if (logger.isFineEnabled()) {
            logger.fine("Cannot publish member list to cluster. Is-master: " + clusterService.isMaster() + ", joined: " + clusterService.isJoined() + " , mastership claim in progress: " + clusterService.getClusterJoinManager().isMastershipClaimInProgress());
        }
        return;
    }
    MemberMap memberMap = getMemberMap();
    MembersView membersView = memberMap.toMembersView();
    if (logger.isFineEnabled()) {
        logger.fine("Sending member list to the non-master nodes: " + memberListString());
    }
    for (MemberImpl member : memberMap.getMembers()) {
        if (member.localMember()) {
            continue;
        }
        MembersUpdateOp op = new MembersUpdateOp(member.getUuid(), membersView, clusterService.getClusterTime(), null, false);
        op.setCallerUuid(clusterService.getThisUuid());
        nodeEngine.getOperationService().send(op, member.getAddress());
    }
}
Also used : MembersUpdateOp(com.hazelcast.internal.cluster.impl.operations.MembersUpdateOp) MemberImpl(com.hazelcast.cluster.impl.MemberImpl)

Example 12 with MemberImpl

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

the class MembershipManager method registerThisMember.

private void registerThisMember() {
    MemberImpl thisMember = getLocalMember();
    memberMapRef.set(MemberMap.singleton(thisMember));
}
Also used : MemberImpl(com.hazelcast.cluster.impl.MemberImpl)

Example 13 with MemberImpl

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

the class MembershipManager method fetchLatestMembersView.

@SuppressWarnings({ "checkstyle:cyclomaticcomplexity", "checkstyle:npathcomplexity" })
private MembersView fetchLatestMembersView(MemberMap localMemberMap, Set<MemberImpl> members, Map<MemberInfo, Future<MembersView>> futures) {
    MembersView latestMembersView = localMemberMap.toTailMembersView(node.getLocalMember(), true);
    for (MemberImpl member : members) {
        futures.put(new MemberInfo(member), invokeFetchMembersViewOp(member.getAddress(), member.getUuid()));
    }
    long mastershipClaimTimeout = SECONDS.toMillis(mastershipClaimTimeoutSeconds);
    while (clusterService.isJoined()) {
        boolean done = true;
        for (Entry<MemberInfo, Future<MembersView>> e : new ArrayList<>(futures.entrySet())) {
            MemberInfo member = e.getKey();
            Address address = member.getAddress();
            Future<MembersView> future = e.getValue();
            long startNanos = Timer.nanos();
            try {
                long timeout = min(FETCH_MEMBER_LIST_MILLIS, Math.max(mastershipClaimTimeout, 1));
                MembersView membersView = future.get(timeout, MILLISECONDS);
                if (membersView.isLaterThan(latestMembersView)) {
                    if (logger.isFineEnabled()) {
                        logger.fine("A more recent " + membersView + " is received from " + address);
                    }
                    latestMembersView = membersView;
                    // If we discover a new member via a fetched member list, we should also ask for its members view.
                    // there are some new members added to the futures map. lets wait for their results.
                    done &= !fetchMembersViewFromNewMembers(membersView, futures);
                }
            } catch (InterruptedException ignored) {
                Thread.currentThread().interrupt();
            } catch (ExecutionException ignored) {
                // we couldn't learn MembersView of 'address'. It will be removed from the cluster.
                EmptyStatement.ignore(ignored);
            } catch (TimeoutException ignored) {
                MemberInfo latestMemberInfo = latestMembersView.getMember(address);
                MemberImpl memberImpl = new MemberImpl(member.getAddress(), member.getVersion(), false, member.getUuid());
                if (mastershipClaimTimeout > 0 && !isMemberSuspected(memberImpl) && latestMemberInfo != null) {
                    // we don't suspect from 'address' and we need to learn its response
                    done = false;
                    // Mastership claim is idempotent.
                    // We will retry our claim to member until it explicitly rejects or accepts our claim.
                    // We can't just rely on invocation retries, because if connection is dropped while
                    // our claim is on the wire, invocation won't get any response and will eventually timeout.
                    futures.put(latestMemberInfo, invokeFetchMembersViewOp(address, latestMemberInfo.getUuid()));
                }
            }
            mastershipClaimTimeout -= Timer.millisElapsed(startNanos);
        }
        if (done) {
            break;
        }
    }
    return latestMembersView;
}
Also used : Address(com.hazelcast.cluster.Address) MemberImpl(com.hazelcast.cluster.impl.MemberImpl) ArrayList(java.util.ArrayList) MemberInfo(com.hazelcast.internal.cluster.MemberInfo) Future(java.util.concurrent.Future) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException)

Example 14 with MemberImpl

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

the class MembershipManager method memberListString.

String memberListString() {
    MemberMap memberMap = getMemberMap();
    Collection<MemberImpl> members = memberMap.getMembers();
    StringBuilder sb = new StringBuilder("\n\nMembers {").append("size:").append(members.size()).append(", ").append("ver:").append(memberMap.getVersion()).append("} [");
    for (Member member : members) {
        sb.append("\n\t").append(member);
    }
    sb.append("\n]\n");
    return sb.toString();
}
Also used : MemberImpl(com.hazelcast.cluster.impl.MemberImpl) Member(com.hazelcast.cluster.Member)

Example 15 with MemberImpl

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

the class ClusterDataSerializerHook method createFactory.

@Override
public DataSerializableFactory createFactory() {
    ConstructorFunction<Integer, IdentifiedDataSerializable>[] constructors = new ConstructorFunction[LEN];
    constructors[AUTH_FAILURE] = arg -> new AuthenticationFailureOp();
    constructors[ADDRESS] = arg -> new Address();
    constructors[MEMBER] = arg -> new MemberImpl();
    constructors[HEARTBEAT] = arg -> new HeartbeatOp();
    constructors[CONFIG_CHECK] = arg -> new ConfigCheck();
    constructors[MEMBER_HANDSHAKE] = arg -> new MemberHandshake();
    constructors[MEMBER_INFO_UPDATE] = arg -> new MembersUpdateOp();
    constructors[FINALIZE_JOIN] = arg -> new FinalizeJoinOp();
    constructors[BEFORE_JOIN_CHECK_FAILURE] = arg -> new BeforeJoinCheckFailureOp();
    constructors[CHANGE_CLUSTER_STATE] = arg -> new CommitClusterStateOp();
    constructors[CONFIG_MISMATCH] = arg -> new ConfigMismatchOp();
    constructors[CLUSTER_MISMATCH] = arg -> new ClusterMismatchOp();
    constructors[SPLIT_BRAIN_MERGE_VALIDATION] = arg -> new SplitBrainMergeValidationOp();
    constructors[JOIN_REQUEST_OP] = arg -> new JoinRequestOp();
    constructors[LOCK_CLUSTER_STATE] = arg -> new LockClusterStateOp();
    constructors[MASTER_CLAIM] = arg -> new JoinMastershipClaimOp();
    constructors[WHOIS_MASTER] = arg -> new WhoisMasterOp();
    constructors[MERGE_CLUSTERS] = arg -> new MergeClustersOp();
    constructors[POST_JOIN] = arg -> new OnJoinOp();
    constructors[ROLLBACK_CLUSTER_STATE] = arg -> new RollbackClusterStateOp();
    constructors[MASTER_RESPONSE] = arg -> new MasterResponseOp();
    constructors[SHUTDOWN_NODE] = arg -> new ShutdownNodeOp();
    constructors[TRIGGER_MEMBER_LIST_PUBLISH] = arg -> new TriggerMemberListPublishOp();
    constructors[CLUSTER_STATE_TRANSACTION_LOG_RECORD] = arg -> new ClusterStateTransactionLogRecord();
    constructors[MEMBER_INFO] = arg -> new MemberInfo();
    constructors[JOIN_MESSAGE] = arg -> new JoinMessage();
    constructors[JOIN_REQUEST] = arg -> new JoinRequest();
    constructors[MIGRATION_INFO] = arg -> new MigrationInfo();
    constructors[MEMBER_VERSION] = arg -> new MemberVersion();
    constructors[CLUSTER_STATE_CHANGE] = arg -> new ClusterStateChange();
    constructors[SPLIT_BRAIN_JOIN_MESSAGE] = arg -> new SplitBrainJoinMessage();
    constructors[VERSION] = arg -> new Version();
    constructors[FETCH_MEMBER_LIST_STATE] = arg -> new FetchMembersViewOp();
    constructors[EXPLICIT_SUSPICION] = arg -> new ExplicitSuspicionOp();
    constructors[MEMBERS_VIEW] = arg -> new MembersView();
    constructors[TRIGGER_EXPLICIT_SUSPICION] = arg -> new TriggerExplicitSuspicionOp();
    constructors[MEMBERS_VIEW_METADATA] = arg -> new MembersViewMetadata();
    constructors[HEARTBEAT_COMPLAINT] = arg -> new HeartbeatComplaintOp();
    constructors[PROMOTE_LITE_MEMBER] = arg -> new PromoteLiteMemberOp();
    constructors[VECTOR_CLOCK] = arg -> new VectorClock();
    constructors[ENDPOINT_QUALIFIER] = arg -> new EndpointQualifier();
    return new ArrayDataSerializableFactory(constructors);
}
Also used : MigrationInfo(com.hazelcast.internal.partition.MigrationInfo) MergeClustersOp(com.hazelcast.internal.cluster.impl.operations.MergeClustersOp) Address(com.hazelcast.cluster.Address) MembersUpdateOp(com.hazelcast.internal.cluster.impl.operations.MembersUpdateOp) SplitBrainMergeValidationOp(com.hazelcast.internal.cluster.impl.operations.SplitBrainMergeValidationOp) RollbackClusterStateOp(com.hazelcast.internal.cluster.impl.operations.RollbackClusterStateOp) EndpointQualifier(com.hazelcast.instance.EndpointQualifier) TriggerMemberListPublishOp(com.hazelcast.internal.cluster.impl.operations.TriggerMemberListPublishOp) MemberVersion(com.hazelcast.version.MemberVersion) HeartbeatComplaintOp(com.hazelcast.internal.cluster.impl.operations.HeartbeatComplaintOp) MemberInfo(com.hazelcast.internal.cluster.MemberInfo) Version(com.hazelcast.version.Version) MemberVersion(com.hazelcast.version.MemberVersion) ShutdownNodeOp(com.hazelcast.internal.cluster.impl.operations.ShutdownNodeOp) HeartbeatOp(com.hazelcast.internal.cluster.impl.operations.HeartbeatOp) TriggerExplicitSuspicionOp(com.hazelcast.internal.cluster.impl.operations.TriggerExplicitSuspicionOp) BeforeJoinCheckFailureOp(com.hazelcast.internal.cluster.impl.operations.BeforeJoinCheckFailureOp) MasterResponseOp(com.hazelcast.internal.cluster.impl.operations.MasterResponseOp) MemberImpl(com.hazelcast.cluster.impl.MemberImpl) LockClusterStateOp(com.hazelcast.internal.cluster.impl.operations.LockClusterStateOp) ExplicitSuspicionOp(com.hazelcast.internal.cluster.impl.operations.ExplicitSuspicionOp) TriggerExplicitSuspicionOp(com.hazelcast.internal.cluster.impl.operations.TriggerExplicitSuspicionOp) VectorClock(com.hazelcast.cluster.impl.VectorClock) AuthenticationFailureOp(com.hazelcast.internal.cluster.impl.operations.AuthenticationFailureOp) ClusterMismatchOp(com.hazelcast.internal.cluster.impl.operations.ClusterMismatchOp) PromoteLiteMemberOp(com.hazelcast.internal.cluster.impl.operations.PromoteLiteMemberOp) FinalizeJoinOp(com.hazelcast.internal.cluster.impl.operations.FinalizeJoinOp) ConstructorFunction(com.hazelcast.internal.util.ConstructorFunction) ConfigMismatchOp(com.hazelcast.internal.cluster.impl.operations.ConfigMismatchOp) CommitClusterStateOp(com.hazelcast.internal.cluster.impl.operations.CommitClusterStateOp) WhoisMasterOp(com.hazelcast.internal.cluster.impl.operations.WhoisMasterOp) OnJoinOp(com.hazelcast.internal.cluster.impl.operations.OnJoinOp) JoinRequestOp(com.hazelcast.internal.cluster.impl.operations.JoinRequestOp) FetchMembersViewOp(com.hazelcast.internal.cluster.impl.operations.FetchMembersViewOp) ArrayDataSerializableFactory(com.hazelcast.internal.serialization.impl.ArrayDataSerializableFactory) JoinMastershipClaimOp(com.hazelcast.internal.cluster.impl.operations.JoinMastershipClaimOp)

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