Search in sources :

Example 1 with Operation

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

the class AbstractJoiner method startClusterMerge.

protected void startClusterMerge(final Address targetAddress) {
    ClusterServiceImpl clusterService = node.clusterService;
    if (!prepareClusterState(clusterService)) {
        return;
    }
    OperationService operationService = node.nodeEngine.getOperationService();
    Collection<Member> memberList = clusterService.getMembers();
    Collection<Future> futures = new ArrayList<Future>(memberList.size());
    for (Member member : memberList) {
        if (!member.localMember()) {
            Operation op = new MergeClustersOperation(targetAddress);
            Future<Object> future = operationService.invokeOnTarget(ClusterServiceImpl.SERVICE_NAME, op, member.getAddress());
            futures.add(future);
        }
    }
    waitWithDeadline(futures, SPLIT_BRAIN_MERGE_TIMEOUT_SECONDS, TimeUnit.SECONDS, splitBrainMergeExceptionHandler);
    Operation mergeClustersOperation = new MergeClustersOperation(targetAddress);
    mergeClustersOperation.setNodeEngine(node.nodeEngine).setService(clusterService).setOperationResponseHandler(createEmptyResponseHandler());
    operationService.run(mergeClustersOperation);
}
Also used : ArrayList(java.util.ArrayList) MergeClustersOperation(com.hazelcast.internal.cluster.impl.operations.MergeClustersOperation) Future(java.util.concurrent.Future) OperationService(com.hazelcast.spi.OperationService) SplitBrainMergeValidationOperation(com.hazelcast.internal.cluster.impl.operations.SplitBrainMergeValidationOperation) MemberRemoveOperation(com.hazelcast.internal.cluster.impl.operations.MemberRemoveOperation) MergeClustersOperation(com.hazelcast.internal.cluster.impl.operations.MergeClustersOperation) Operation(com.hazelcast.spi.Operation) Member(com.hazelcast.core.Member)

Example 2 with Operation

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

the class ClusterJoinManager method checkIfJoinRequestFromAnExistingMember.

private boolean checkIfJoinRequestFromAnExistingMember(JoinMessage joinMessage, Connection connection) {
    Address target = joinMessage.getAddress();
    MemberImpl member = clusterService.getMember(target);
    if (member == null) {
        return checkIfUsingAnExistingMemberUuid(joinMessage);
    }
    if (joinMessage.getUuid().equals(member.getUuid())) {
        sendMasterAnswer(target);
        if (node.isMaster()) {
            if (logger.isFineEnabled()) {
                logger.fine(format("Ignoring join request, member already exists: %s", joinMessage));
            }
            // send members update back to node trying to join again...
            Operation[] postJoinOps = nodeEngine.getPostJoinOperations();
            boolean isPostJoinOperation = postJoinOps != null && postJoinOps.length > 0;
            PostJoinOperation postJoinOp = isPostJoinOperation ? new PostJoinOperation(postJoinOps) : null;
            PartitionRuntimeState partitionRuntimeState = node.getPartitionService().createPartitionState();
            List<MemberInfo> memberInfos = createMemberInfoList(clusterService.getMemberImpls());
            Operation operation = new FinalizeJoinOperation(member.getUuid(), memberInfos, postJoinOp, clusterClock.getClusterTime(), clusterService.getClusterId(), clusterClock.getClusterStartTime(), clusterStateManager.getState(), clusterService.getClusterVersion(), partitionRuntimeState, false);
            nodeEngine.getOperationService().send(operation, target);
        }
        return true;
    }
    //   and wants to join back, so drop old member and process join request if this node becomes master
    if (node.isMaster() || target.equals(node.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.doRemoveAddress(target, msg, false);
        Connection existing = node.connectionManager.getConnection(target);
        if (existing != connection) {
            if (existing != null) {
                existing.close(msg, null);
            }
            node.connectionManager.registerConnection(target, connection);
        }
        return false;
    }
    return true;
}
Also used : FinalizeJoinOperation(com.hazelcast.internal.cluster.impl.operations.FinalizeJoinOperation) Address(com.hazelcast.nio.Address) MemberInfo(com.hazelcast.internal.cluster.MemberInfo) MemberImpl(com.hazelcast.instance.MemberImpl) PartitionRuntimeState(com.hazelcast.internal.partition.PartitionRuntimeState) Connection(com.hazelcast.nio.Connection) PostJoinOperation(com.hazelcast.internal.cluster.impl.operations.PostJoinOperation) FinalizeJoinOperation(com.hazelcast.internal.cluster.impl.operations.FinalizeJoinOperation) MemberInfoUpdateOperation(com.hazelcast.internal.cluster.impl.operations.MemberInfoUpdateOperation) ConfigMismatchOperation(com.hazelcast.internal.cluster.impl.operations.ConfigMismatchOperation) Operation(com.hazelcast.spi.Operation) BeforeJoinCheckFailureOperation(com.hazelcast.internal.cluster.impl.operations.BeforeJoinCheckFailureOperation) SetMasterOperation(com.hazelcast.internal.cluster.impl.operations.SetMasterOperation) GroupMismatchOperation(com.hazelcast.internal.cluster.impl.operations.GroupMismatchOperation) PostJoinOperation(com.hazelcast.internal.cluster.impl.operations.PostJoinOperation) MasterDiscoveryOperation(com.hazelcast.internal.cluster.impl.operations.MasterDiscoveryOperation) JoinRequestOperation(com.hazelcast.internal.cluster.impl.operations.JoinRequestOperation) AuthenticationFailureOperation(com.hazelcast.internal.cluster.impl.operations.AuthenticationFailureOperation)

Example 3 with Operation

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

the class ClusterServiceImpl method shutdownNodes.

private void shutdownNodes() {
    final Operation op = new ShutdownNodeOperation();
    logger.info("Sending shutting down operations to all members...");
    Collection<Member> members = getMembers(NON_LOCAL_MEMBER_SELECTOR);
    final long timeout = node.getProperties().getNanos(GroupProperty.CLUSTER_SHUTDOWN_TIMEOUT_SECONDS);
    final long startTime = System.nanoTime();
    while ((System.nanoTime() - startTime) < timeout && !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 nodes remaining: " + getSize(NON_LOCAL_MEMBER_SELECTOR) + ". Shutting down itself.");
    final HazelcastInstanceImpl hazelcastInstance = node.hazelcastInstance;
    hazelcastInstance.getLifecycleService().shutdown();
}
Also used : HazelcastInstanceImpl(com.hazelcast.instance.HazelcastInstanceImpl) ShutdownNodeOperation(com.hazelcast.internal.cluster.impl.operations.ShutdownNodeOperation) MemberInfoUpdateOperation(com.hazelcast.internal.cluster.impl.operations.MemberInfoUpdateOperation) Operation(com.hazelcast.spi.Operation) TriggerMemberListPublishOperation(com.hazelcast.internal.cluster.impl.operations.TriggerMemberListPublishOperation) MemberRemoveOperation(com.hazelcast.internal.cluster.impl.operations.MemberRemoveOperation) ShutdownNodeOperation(com.hazelcast.internal.cluster.impl.operations.ShutdownNodeOperation) Member(com.hazelcast.core.Member)

Example 4 with Operation

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

the class PostJoinOperation method beforeRun.

@Override
public void beforeRun() throws Exception {
    if (operations != null && operations.length > 0) {
        final NodeEngine nodeEngine = getNodeEngine();
        final int len = operations.length;
        for (int i = 0; i < len; i++) {
            final Operation op = operations[i];
            op.setNodeEngine(nodeEngine);
            op.setOperationResponseHandler(new OperationResponseHandler() {

                @Override
                public void sendResponse(Operation op, Object obj) {
                    if (obj instanceof Throwable) {
                        Throwable t = (Throwable) obj;
                        ILogger logger = nodeEngine.getLogger(op.getClass());
                        logger.warning("Error while running post-join operation: " + t.getClass().getSimpleName() + ": " + t.getMessage());
                        if (logger.isFineEnabled()) {
                            logger.fine("Error while running post-join operation: ", t);
                        }
                    }
                }
            });
            OperationAccessor.setCallerAddress(op, getCallerAddress());
            OperationAccessor.setConnection(op, getConnection());
            operations[i] = op;
        }
    }
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) ILogger(com.hazelcast.logging.ILogger) Operation(com.hazelcast.spi.Operation) UrgentSystemOperation(com.hazelcast.spi.UrgentSystemOperation) OperationResponseHandler(com.hazelcast.spi.OperationResponseHandler)

Example 5 with Operation

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

the class PostJoinOperation method writeInternal.

@Override
protected void writeInternal(final ObjectDataOutput out) throws IOException {
    final int len = operations != null ? operations.length : 0;
    out.writeInt(len);
    if (len > 0) {
        for (Operation op : operations) {
            out.writeObject(op);
        }
    }
}
Also used : Operation(com.hazelcast.spi.Operation) UrgentSystemOperation(com.hazelcast.spi.UrgentSystemOperation)

Aggregations

Operation (com.hazelcast.spi.Operation)94 OperationService (com.hazelcast.spi.OperationService)14 Member (com.hazelcast.core.Member)13 Address (com.hazelcast.nio.Address)11 InternalCompletableFuture (com.hazelcast.spi.InternalCompletableFuture)8 ArrayList (java.util.ArrayList)8 ILogger (com.hazelcast.logging.ILogger)7 UrgentSystemOperation (com.hazelcast.spi.UrgentSystemOperation)7 ParallelTest (com.hazelcast.test.annotation.ParallelTest)7 QuickTest (com.hazelcast.test.annotation.QuickTest)7 Test (org.junit.Test)7 AcquireOperation (com.hazelcast.concurrent.semaphore.operations.AcquireOperation)6 AvailableOperation (com.hazelcast.concurrent.semaphore.operations.AvailableOperation)6 DrainOperation (com.hazelcast.concurrent.semaphore.operations.DrainOperation)6 InitOperation (com.hazelcast.concurrent.semaphore.operations.InitOperation)6 ReduceOperation (com.hazelcast.concurrent.semaphore.operations.ReduceOperation)6 ReleaseOperation (com.hazelcast.concurrent.semaphore.operations.ReleaseOperation)6 MemberInfo (com.hazelcast.internal.cluster.MemberInfo)6 NodeEngine (com.hazelcast.spi.NodeEngine)6 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)6