Search in sources :

Example 6 with OperationService

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

the class ClusterJoinManager method checkClusterStateBeforeJoin.

private boolean checkClusterStateBeforeJoin(Address target, UUID uuid) {
    ClusterState state = clusterStateManager.getState();
    if (state == ClusterState.IN_TRANSITION) {
        logger.warning("Cluster state is in transition process. Join is not allowed until " + "transaction is completed -> " + clusterStateManager.stateToString());
        return true;
    }
    if (state.isJoinAllowed()) {
        return checkRecentlyJoinedMemberUuidBeforeJoin(target, uuid);
    }
    if (clusterService.isMissingMember(target, uuid)) {
        return false;
    }
    if (node.getNodeExtension().isStartCompleted()) {
        String message = "Cluster state either is locked or doesn't allow new members to join -> " + clusterStateManager.stateToString();
        logger.warning(message);
        OperationService operationService = nodeEngine.getOperationService();
        BeforeJoinCheckFailureOp op = new BeforeJoinCheckFailureOp(message);
        operationService.send(op, target);
    } else {
        String message = "Cluster state either is locked or doesn't allow new members to join -> " + clusterStateManager.stateToString() + ". Silently ignored join request of " + target + " because start not completed.";
        logger.warning(message);
    }
    return true;
}
Also used : ClusterState(com.hazelcast.cluster.ClusterState) OperationService(com.hazelcast.spi.impl.operationservice.OperationService) BeforeJoinCheckFailureOp(com.hazelcast.internal.cluster.impl.operations.BeforeJoinCheckFailureOp)

Example 7 with OperationService

use of com.hazelcast.spi.impl.operationservice.OperationService 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 OperationService

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

the class CRDTReplicationTask method replicate.

/**
 * Performs replication of a {@link CRDTReplicationAwareService} to the
 * given target. The service may optimise the returned operation based on
 * the target member and the previous successful replication operations.
 *
 * @param service the service to replicate
 * @param target  the target to replicate to
 * @see CRDTReplicationAwareService
 */
private void replicate(CRDTReplicationAwareService service, Member target) {
    if (Thread.currentThread().isInterrupted()) {
        return;
    }
    final int targetIndex = getDataMemberListIndex(target);
    final Map<String, VectorClock> lastSuccessfullyReplicatedClocks = replicationMigrationService.getReplicatedVectorClocks(service.getName(), target.getUuid());
    final OperationService operationService = nodeEngine.getOperationService();
    final CRDTReplicationContainer replicationOperation = service.prepareReplicationOperation(lastSuccessfullyReplicatedClocks, targetIndex);
    if (replicationOperation == null) {
        logger.finest("Skipping replication of " + service.getName() + " for target " + target);
        return;
    }
    try {
        logger.finest("Replicating " + service.getName() + " to " + target);
        operationService.invokeOnTarget(null, replicationOperation.getOperation(), target.getAddress()).joinInternal();
        replicationMigrationService.setReplicatedVectorClocks(service.getName(), target.getUuid(), replicationOperation.getVectorClocks());
    } catch (Exception e) {
        if (logger.isFineEnabled()) {
            logger.fine("Failed replication of " + service.getName() + " for target " + target, e);
        } else {
            logger.info("Failed replication of " + service.getName() + " for target " + target);
        }
    }
}
Also used : VectorClock(com.hazelcast.cluster.impl.VectorClock) OperationService(com.hazelcast.spi.impl.operationservice.OperationService)

Example 9 with OperationService

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

the class CRDTReplicationMigrationService method tryProcessOnOtherMembers.

/**
 * Attempts to process the {@code operation} on at least one non-local
 * member. The method will iterate through the member list and try once on
 * each member.
 * The method returns as soon as the first member successfully processes
 * the operation or once there are no more members to try.
 *
 * @param serviceName the service name
 * @return {@code true} if at least one member successfully processed the
 * operation, {@code false} otherwise.
 */
private boolean tryProcessOnOtherMembers(Operation operation, String serviceName, long timeoutNanos) {
    final OperationService operationService = nodeEngine.getOperationService();
    final Collection<Member> targets = nodeEngine.getClusterService().getMembers(DATA_MEMBER_SELECTOR);
    final Member localMember = nodeEngine.getLocalMember();
    for (Member target : targets) {
        if (target.equals(localMember)) {
            continue;
        }
        long start = System.nanoTime();
        try {
            logger.fine("Replicating " + serviceName + " to " + target);
            InternalCompletableFuture<Object> future = operationService.createInvocationBuilder(null, operation, target.getAddress()).setTryCount(1).invoke();
            future.get(timeoutNanos, TimeUnit.NANOSECONDS);
            return true;
        } catch (Exception e) {
            logger.fine("Failed replication of " + serviceName + " for target " + target, e);
        }
        timeoutNanos -= (System.nanoTime() - start);
        if (timeoutNanos < 0) {
            break;
        }
    }
    return false;
}
Also used : OperationService(com.hazelcast.spi.impl.operationservice.OperationService) Member(com.hazelcast.cluster.Member)

Example 10 with OperationService

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

the class CRDTMigrationTask method migrate.

/**
 * Performs migration of a {@link CRDTReplicationAwareService} to the
 * given target.
 *
 * @param service                   the service to migrate
 * @param target                    the target to migrate to
 * @param maxConfiguredReplicaCount the maximum configured replica count
 *                                  for the CRDTs to be migrated (excluding)
 * @see CRDTReplicationAwareService
 */
private boolean migrate(CRDTReplicationAwareService service, Member target, int maxConfiguredReplicaCount) {
    if (Thread.currentThread().isInterrupted()) {
        return false;
    }
    final OperationService operationService = nodeEngine.getOperationService();
    final CRDTReplicationContainer migrationOperation = service.prepareMigrationOperation(maxConfiguredReplicaCount);
    if (migrationOperation == null) {
        logger.finest("Skipping migration of " + service.getName() + " for target " + target);
        return true;
    }
    try {
        logger.finest("Migrating " + service.getName() + " to " + target);
        operationService.invokeOnTarget(null, migrationOperation.getOperation(), target.getAddress()).joinInternal();
        final boolean allMigrated = service.clearCRDTState(migrationOperation.getVectorClocks());
        if (!allMigrated) {
            logger.fine(service.getName() + " CRDTs have been mutated since migrated to target " + target + ". Rescheduling migration in " + MIGRATION_RETRY_DELAY_SECONDS + " second(s).");
        }
        return allMigrated;
    } catch (Exception e) {
        if (logger.isFineEnabled()) {
            logger.fine("Failed migration of " + service.getName() + " for target " + target + ". Rescheduling migration in " + MIGRATION_RETRY_DELAY_SECONDS + " second(s).", e);
        } else {
            logger.info("Failed migration of " + service.getName() + " for target " + target + ". Rescheduling migration in " + MIGRATION_RETRY_DELAY_SECONDS + " second(s).");
        }
        return false;
    }
}
Also used : OperationService(com.hazelcast.spi.impl.operationservice.OperationService)

Aggregations

OperationService (com.hazelcast.spi.impl.operationservice.OperationService)140 Operation (com.hazelcast.spi.impl.operationservice.Operation)55 Test (org.junit.Test)54 HazelcastInstance (com.hazelcast.core.HazelcastInstance)46 QuickTest (com.hazelcast.test.annotation.QuickTest)41 Accessors.getOperationService (com.hazelcast.test.Accessors.getOperationService)40 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)40 Address (com.hazelcast.cluster.Address)31 NodeEngine (com.hazelcast.spi.impl.NodeEngine)31 InternalCompletableFuture (com.hazelcast.spi.impl.InternalCompletableFuture)24 Future (java.util.concurrent.Future)24 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)23 Config (com.hazelcast.config.Config)22 Member (com.hazelcast.cluster.Member)21 Data (com.hazelcast.internal.serialization.Data)12 SlowTest (com.hazelcast.test.annotation.SlowTest)12 ClusterService (com.hazelcast.internal.cluster.ClusterService)9 ILogger (com.hazelcast.logging.ILogger)7 ArrayList (java.util.ArrayList)7 IPartitionService (com.hazelcast.internal.partition.IPartitionService)6