Search in sources :

Example 51 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 52 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)

Example 53 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 54 with OperationService

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

the class InternalPartitionServiceImpl method sendPartitionRuntimeState.

void sendPartitionRuntimeState(Address target) {
    if (!isLocalMemberMaster()) {
        return;
    }
    assert partitionStateManager.isInitialized();
    PartitionRuntimeState partitionState = createPartitionStateInternal();
    assert partitionState != null;
    if (logger.isFineEnabled()) {
        logger.fine("Sending partition state, stamp: " + partitionState.getStamp() + ", to " + target);
    }
    OperationService operationService = nodeEngine.getOperationService();
    PartitionStateOperation op = new PartitionStateOperation(partitionState, true);
    operationService.invokeOnTarget(SERVICE_NAME, op, target);
}
Also used : PartitionRuntimeState(com.hazelcast.internal.partition.PartitionRuntimeState) OperationService(com.hazelcast.spi.impl.operationservice.OperationService) FetchPartitionStateOperation(com.hazelcast.internal.partition.operation.FetchPartitionStateOperation) PartitionStateOperation(com.hazelcast.internal.partition.operation.PartitionStateOperation)

Example 55 with OperationService

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

the class InternalPartitionServiceImpl method checkClusterPartitionRuntimeStates.

void checkClusterPartitionRuntimeStates() {
    if (!partitionStateManager.isInitialized()) {
        return;
    }
    if (!isLocalMemberMaster()) {
        return;
    }
    if (!areMigrationTasksAllowed()) {
        // migration is disabled because of a member leave, wait till enabled!
        return;
    }
    long stamp = getPartitionStateStamp();
    if (logger.isFineEnabled()) {
        logger.fine("Checking partition state, stamp: " + stamp);
    }
    OperationService operationService = nodeEngine.getOperationService();
    Collection<Member> members = node.clusterService.getMembers();
    for (Member member : members) {
        if (!member.localMember()) {
            PartitionStateCheckOperation op = new PartitionStateCheckOperation(stamp);
            InvocationFuture<Boolean> future = operationService.invokeOnTarget(SERVICE_NAME, op, member.getAddress());
            future.whenCompleteAsync((response, throwable) -> {
                if (throwable == null) {
                    if (!Boolean.TRUE.equals(response)) {
                        logger.fine(member + " has a stale partition state. Will send the most recent partition state now.");
                        sendPartitionRuntimeState(member.getAddress());
                    }
                } else {
                    logger.fine("Failure while checking partition state on " + member, throwable);
                    sendPartitionRuntimeState(member.getAddress());
                }
            });
        }
    }
}
Also used : PartitionStateCheckOperation(com.hazelcast.internal.partition.operation.PartitionStateCheckOperation) OperationService(com.hazelcast.spi.impl.operationservice.OperationService) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Member(com.hazelcast.cluster.Member)

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