Search in sources :

Example 6 with Operation

use of com.hazelcast.spi.impl.operationservice.Operation in project hazelcast by hazelcast.

the class ClusterJoinManager method checkIfJoinRequestFromAnExistingMember.

@SuppressWarnings("checkstyle:cyclomaticcomplexity")
private boolean checkIfJoinRequestFromAnExistingMember(JoinMessage joinMessage, ServerConnection connection) {
    Address targetAddress = joinMessage.getAddress();
    MemberImpl member = clusterService.getMember(targetAddress);
    if (member == null) {
        return checkIfUsingAnExistingMemberUuid(joinMessage);
    }
    if (joinMessage.getUuid().equals(member.getUuid())) {
        sendMasterAnswer(targetAddress);
        if (clusterService.isMaster() && !isMastershipClaimInProgress()) {
            if (logger.isFineEnabled()) {
                logger.fine(format("Ignoring join request, member already exists: %s", joinMessage));
            }
            // send members update back to node trying to join again...
            boolean deferPartitionProcessing = isMemberRestartingWithPersistence(member.getAttributes());
            OnJoinOp preJoinOp = preparePreJoinOps();
            OnJoinOp postJoinOp = preparePostJoinOp();
            PartitionRuntimeState partitionRuntimeState = node.getPartitionService().createPartitionState();
            Operation op = new FinalizeJoinOp(member.getUuid(), clusterService.getMembershipManager().getMembersView(), preJoinOp, postJoinOp, clusterClock.getClusterTime(), clusterService.getClusterId(), clusterClock.getClusterStartTime(), clusterStateManager.getState(), clusterService.getClusterVersion(), partitionRuntimeState, deferPartitionProcessing);
            op.setCallerUuid(clusterService.getThisUuid());
            invokeClusterOp(op, targetAddress);
        }
        return true;
    }
    // after I suspect from the target.
    if (clusterService.isMaster() || targetAddress.equals(clusterService.getMasterAddress())) {
        String msg = format("New join request has been received from an existing endpoint %s." + " Removing old member and processing join request...", member);
        logger.warning(msg);
        clusterService.suspectMember(member, msg, false);
        ServerConnection existing = node.getServer().getConnectionManager(MEMBER).get(targetAddress);
        if (existing != connection) {
            if (existing != null) {
                existing.close(msg, null);
            }
            node.getServer().getConnectionManager(MEMBER).register(targetAddress, joinMessage.getUuid(), connection);
        }
    }
    return true;
}
Also used : Address(com.hazelcast.cluster.Address) OnJoinOp(com.hazelcast.internal.cluster.impl.operations.OnJoinOp) MemberImpl(com.hazelcast.cluster.impl.MemberImpl) PartitionRuntimeState(com.hazelcast.internal.partition.PartitionRuntimeState) ServerConnection(com.hazelcast.internal.server.ServerConnection) Operation(com.hazelcast.spi.impl.operationservice.Operation) FinalizeJoinOp(com.hazelcast.internal.cluster.impl.operations.FinalizeJoinOp)

Example 7 with Operation

use of com.hazelcast.spi.impl.operationservice.Operation in project hazelcast by hazelcast.

the class ClusterServiceImpl method sendExplicitSuspicionTrigger.

void sendExplicitSuspicionTrigger(Address triggerTo, MembersViewMetadata endpointMembersViewMetadata) {
    if (triggerTo.equals(node.getThisAddress())) {
        logger.warning("Cannot send explicit suspicion trigger for " + endpointMembersViewMetadata + " to itself.");
        return;
    }
    int memberListVersion = membershipManager.getMemberListVersion();
    Operation op = new TriggerExplicitSuspicionOp(memberListVersion, endpointMembersViewMetadata);
    OperationService operationService = nodeEngine.getOperationService();
    operationService.send(op, triggerTo);
}
Also used : TriggerExplicitSuspicionOp(com.hazelcast.internal.cluster.impl.operations.TriggerExplicitSuspicionOp) Operation(com.hazelcast.spi.impl.operationservice.Operation) OperationService(com.hazelcast.spi.impl.operationservice.OperationService)

Example 8 with Operation

use of com.hazelcast.spi.impl.operationservice.Operation in project hazelcast by hazelcast.

the class ClusterServiceImpl method sendExplicitSuspicion.

void sendExplicitSuspicion(MembersViewMetadata endpointMembersViewMetadata) {
    Address endpoint = endpointMembersViewMetadata.getMemberAddress();
    if (endpoint.equals(node.getThisAddress())) {
        logger.warning("Cannot send explicit suspicion for " + endpointMembersViewMetadata + " to itself.");
        return;
    }
    if (!isJoined()) {
        if (logger.isFineEnabled()) {
            logger.fine("Cannot send explicit suspicion, not joined yet!");
        }
        return;
    }
    Version clusterVersion = getClusterVersion();
    assert !clusterVersion.isUnknown() : "Cluster version should not be unknown after join!";
    Operation op = new ExplicitSuspicionOp(endpointMembersViewMetadata);
    nodeEngine.getOperationService().send(op, endpoint);
}
Also used : Address(com.hazelcast.cluster.Address) Version(com.hazelcast.version.Version) ExplicitSuspicionOp(com.hazelcast.internal.cluster.impl.operations.ExplicitSuspicionOp) TriggerExplicitSuspicionOp(com.hazelcast.internal.cluster.impl.operations.TriggerExplicitSuspicionOp) Operation(com.hazelcast.spi.impl.operationservice.Operation)

Example 9 with Operation

use of com.hazelcast.spi.impl.operationservice.Operation in project hazelcast by hazelcast.

the class ClusterServiceImpl method shutdownNodesConcurrently.

private void shutdownNodesConcurrently(final long timeoutNanos) {
    Operation op = new ShutdownNodeOp();
    Collection<Member> members = getMembers(NON_LOCAL_MEMBER_SELECTOR);
    long startTimeNanos = Timer.nanos();
    logger.info("Sending shut down operations to all members...");
    while (Timer.nanosElapsed(startTimeNanos) < timeoutNanos && !members.isEmpty()) {
        for (Member member : members) {
            nodeEngine.getOperationService().send(op, member.getAddress());
        }
        try {
            Thread.sleep(CLUSTER_SHUTDOWN_SLEEP_DURATION_IN_MILLIS);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            logger.warning("Shutdown sleep interrupted. ", e);
            break;
        }
        members = getMembers(NON_LOCAL_MEMBER_SELECTOR);
    }
    logger.info("Number of other members remaining: " + getSize(NON_LOCAL_MEMBER_SELECTOR) + ". Shutting down itself.");
    HazelcastInstanceImpl hazelcastInstance = node.hazelcastInstance;
    hazelcastInstance.getLifecycleService().shutdown();
}
Also used : HazelcastInstanceImpl(com.hazelcast.instance.impl.HazelcastInstanceImpl) ShutdownNodeOp(com.hazelcast.internal.cluster.impl.operations.ShutdownNodeOp) Operation(com.hazelcast.spi.impl.operationservice.Operation) Member(com.hazelcast.cluster.Member)

Example 10 with Operation

use of com.hazelcast.spi.impl.operationservice.Operation in project hazelcast by hazelcast.

the class ClusterHeartbeatManager method sendHeartbeat.

/**
 * Send a {@link HeartbeatOp} to the {@code target}
 *
 * @param target target Member
 */
private void sendHeartbeat(Member target) {
    if (target == null) {
        return;
    }
    try {
        MembersViewMetadata membersViewMetadata = clusterService.getMembershipManager().createLocalMembersViewMetadata();
        Collection<MemberInfo> suspectedMembers = Collections.emptySet();
        if (clusterService.getMembershipManager().isPartialDisconnectionDetectionEnabled() && !clusterService.isMaster() && target.getAddress().equals(clusterService.getMasterAddress())) {
            suspectedMembers = clusterService.getMembershipManager().getSuspectedMembers().stream().map(MemberInfo::new).collect(toSet());
        }
        long clusterTime = clusterClock.getClusterTime();
        Operation op = new HeartbeatOp(membersViewMetadata, target.getUuid(), clusterTime, suspectedMembers);
        op.setCallerUuid(clusterService.getThisUuid());
        node.nodeEngine.getOperationService().send(op, target.getAddress());
    } catch (Exception e) {
        if (logger.isFineEnabled()) {
            logger.fine(format("Error while sending heartbeat -> %s[%s]", e.getClass().getName(), e.getMessage()));
        }
    }
}
Also used : MemberInfo(com.hazelcast.internal.cluster.MemberInfo) HeartbeatOp(com.hazelcast.internal.cluster.impl.operations.HeartbeatOp) Operation(com.hazelcast.spi.impl.operationservice.Operation) ConnectException(java.net.ConnectException) IOException(java.io.IOException)

Aggregations

Operation (com.hazelcast.spi.impl.operationservice.Operation)271 Test (org.junit.Test)80 QuickTest (com.hazelcast.test.annotation.QuickTest)79 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)59 OperationService (com.hazelcast.spi.impl.operationservice.OperationService)56 Address (com.hazelcast.cluster.Address)31 HazelcastInstance (com.hazelcast.core.HazelcastInstance)25 Data (com.hazelcast.internal.serialization.Data)24 Future (java.util.concurrent.Future)24 Member (com.hazelcast.cluster.Member)22 ArrayList (java.util.ArrayList)21 NodeEngine (com.hazelcast.spi.impl.NodeEngine)18 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)17 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)17 AssertTask (com.hazelcast.test.AssertTask)15 ILogger (com.hazelcast.logging.ILogger)14 UrgentSystemOperation (com.hazelcast.spi.impl.operationservice.UrgentSystemOperation)13 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)13 Config (com.hazelcast.config.Config)12 CompletableFuture (java.util.concurrent.CompletableFuture)12