Search in sources :

Example 31 with Address

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

the class MembershipManager method handleExplicitSuspicionTrigger.

void handleExplicitSuspicionTrigger(Address caller, int callerMemberListVersion, MembersViewMetadata suspectedMembersViewMetadata) {
    clusterServiceLock.lock();
    try {
        Address masterAddress = clusterService.getMasterAddress();
        int memberListVersion = getMemberListVersion();
        if (!(masterAddress.equals(caller) && memberListVersion == callerMemberListVersion)) {
            if (logger.isFineEnabled()) {
                logger.fine("Ignoring explicit suspicion trigger for " + suspectedMembersViewMetadata + ". Caller: " + caller + ", caller member list version: " + callerMemberListVersion + ", known master: " + masterAddress + ", local member list version: " + memberListVersion);
            }
            return;
        }
        clusterService.sendExplicitSuspicion(suspectedMembersViewMetadata);
    } finally {
        clusterServiceLock.unlock();
    }
}
Also used : Address(com.hazelcast.cluster.Address)

Example 32 with Address

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

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

Example 34 with Address

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

the class TcpIpJoiner method addPossibleAddresses.

private void addPossibleAddresses(final Set<Address> possibleAddresses, final String host, final InetAddress inetAddress, final int port, final int count) throws UnknownHostException {
    for (int i = 0; i < count; i++) {
        int currentPort = port + i;
        Address address;
        if (host != null && inetAddress != null) {
            address = new Address(host, inetAddress, currentPort);
        } else if (host != null) {
            address = new Address(host, currentPort);
        } else {
            address = new Address(inetAddress, currentPort);
        }
        if (!isLocalAddress(address)) {
            possibleAddresses.add(address);
        }
    }
}
Also used : Address(com.hazelcast.cluster.Address) InetAddress(java.net.InetAddress)

Example 35 with Address

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

the class TcpIpJoiner method searchForOtherClusters.

@Override
public void searchForOtherClusters() {
    final Collection<Address> possibleAddresses;
    try {
        possibleAddresses = getPossibleAddresses();
    } catch (Throwable e) {
        logger.severe(e);
        return;
    }
    LocalAddressRegistry addressRegistry = node.getLocalAddressRegistry();
    possibleAddresses.removeAll(addressRegistry.getLocalAddresses());
    node.getClusterService().getMembers().forEach(member -> {
        LinkedAddresses addresses = addressRegistry.linkedAddressesOf(member.getUuid());
        if (addresses != null) {
            Set<Address> knownMemberAddresses = addresses.getAllAddresses();
            possibleAddresses.removeAll(knownMemberAddresses);
        } else {
            // do not expect this case in the normal conditions, except for disconnections happens
            // at the same time
            possibleAddresses.remove(member.getAddress());
        }
    });
    if (possibleAddresses.isEmpty()) {
        return;
    }
    SplitBrainJoinMessage request = node.createSplitBrainJoinMessage();
    for (Address address : possibleAddresses) {
        SplitBrainMergeCheckResult result = sendSplitBrainJoinMessageAndCheckResponse(address, request);
        if (result == SplitBrainMergeCheckResult.LOCAL_NODE_SHOULD_MERGE) {
            logger.warning(node.getThisAddress() + " is merging [tcp/ip] to " + address);
            setTargetAddress(address);
            startClusterMerge(address, request.getMemberListVersion());
            return;
        }
    }
}
Also used : Address(com.hazelcast.cluster.Address) InetAddress(java.net.InetAddress) LocalAddressRegistry(com.hazelcast.internal.server.tcp.LocalAddressRegistry) LinkedAddresses(com.hazelcast.internal.server.tcp.LinkedAddresses) SplitBrainMergeCheckResult(com.hazelcast.internal.cluster.impl.SplitBrainJoinMessage.SplitBrainMergeCheckResult)

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