Search in sources :

Example 1 with BOOLEAN

use of com.hazelcast.internal.metrics.ProbeUnit.BOOLEAN in project hazelcast by hazelcast.

the class MigrationManager method commitMigrationToDestinationAsync.

/**
 * Sends a {@link MigrationCommitOperation} to the destination and returns {@code true} if the new partition state
 * was applied on the destination.
 */
@SuppressWarnings({ "checkstyle:npathcomplexity", "checkstyle:cyclomaticcomplexity", "checkstyle:methodlength" })
private CompletionStage<Boolean> commitMigrationToDestinationAsync(final MigrationInfo migration) {
    PartitionReplica destination = migration.getDestination();
    if (destination.isIdentical(node.getLocalMember())) {
        if (logger.isFinestEnabled()) {
            logger.finest("Shortcutting migration commit, since destination is master. -> " + migration);
        }
        return CompletableFuture.completedFuture(Boolean.TRUE);
    }
    Member member = node.getClusterService().getMember(destination.address(), destination.uuid());
    if (member == null) {
        logger.warning("Cannot commit " + migration + ". Destination " + destination + " is not a member anymore");
        return CompletableFuture.completedFuture(Boolean.FALSE);
    }
    try {
        if (logger.isFinestEnabled()) {
            logger.finest("Sending migration commit operation to " + destination + " for " + migration);
        }
        migration.setStatus(MigrationStatus.SUCCESS);
        UUID destinationUuid = member.getUuid();
        MigrationCommitOperation operation = new MigrationCommitOperation(migration, destinationUuid);
        InvocationFuture<Boolean> future = nodeEngine.getOperationService().createInvocationBuilder(SERVICE_NAME, operation, destination.address()).setTryCount(Integer.MAX_VALUE).setCallTimeout(memberHeartbeatTimeoutMillis).invoke();
        return future.handleAsync((done, t) -> {
            // Inspect commit result;
            // - if there's an exception, either retry or fail
            // - if result is true then success, otherwise failure
            logger.fine("Migration commit response received -> " + migration + ", success: " + done + ", failure: " + t);
            if (t != null) {
                logMigrationCommitFailure(migration, t);
                if (t instanceof OperationTimeoutException || t.getCause() instanceof OperationTimeoutException) {
                    return COMMIT_RETRY;
                }
                return COMMIT_FAILURE;
            }
            return done ? COMMIT_SUCCESS : COMMIT_FAILURE;
        }, asyncExecutor).thenComposeAsync(result -> {
            switch(result) {
                case COMMIT_SUCCESS:
                    return CompletableFuture.completedFuture(true);
                case COMMIT_FAILURE:
                    return CompletableFuture.completedFuture(false);
                case COMMIT_RETRY:
                    logger.fine("Retrying migration commit for -> " + migration);
                    return commitMigrationToDestinationAsync(migration);
                default:
                    throw new IllegalArgumentException("Unknown migration commit result: " + result);
            }
        }, asyncExecutor).handleAsync((result, t) -> {
            if (t != null) {
                logMigrationCommitFailure(migration, t);
                return false;
            }
            if (logger.isFineEnabled()) {
                logger.fine("Migration commit result " + result + " from " + destination + " for " + migration);
            }
            return result;
        }, asyncExecutor);
    } catch (Throwable t) {
        logMigrationCommitFailure(migration, t);
        return CompletableFuture.completedFuture(Boolean.FALSE);
    }
}
Also used : MigrationCommitOperation(com.hazelcast.internal.partition.operation.MigrationCommitOperation) Address(com.hazelcast.cluster.Address) HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) InvocationFuture(com.hazelcast.spi.impl.operationservice.impl.InvocationFuture) Arrays(java.util.Arrays) PartitionRuntimeState(com.hazelcast.internal.partition.PartitionRuntimeState) ShutdownResponseOperation(com.hazelcast.internal.partition.operation.ShutdownResponseOperation) Preconditions(com.hazelcast.internal.util.Preconditions) ScheduledFuture(java.util.concurrent.ScheduledFuture) PartitionStateVersionMismatchException(com.hazelcast.internal.partition.PartitionStateVersionMismatchException) Clock(com.hazelcast.internal.util.Clock) MIGRATION_METRIC_MIGRATION_MANAGER_MIGRATION_ACTIVE(com.hazelcast.internal.metrics.MetricDescriptorConstants.MIGRATION_METRIC_MIGRATION_MANAGER_MIGRATION_ACTIVE) Member(com.hazelcast.cluster.Member) BiFunction(java.util.function.BiFunction) IntConsumer(java.util.function.IntConsumer) ASYNC_EXECUTOR(com.hazelcast.spi.impl.executionservice.ExecutionService.ASYNC_EXECUTOR) InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) MigrationStateImpl(com.hazelcast.internal.partition.MigrationStateImpl) Future(java.util.concurrent.Future) PartitionTableView(com.hazelcast.internal.partition.PartitionTableView) MigrationCommitOperation(com.hazelcast.internal.partition.operation.MigrationCommitOperation) DATA_MEMBER_SELECTOR(com.hazelcast.cluster.memberselector.MemberSelectors.DATA_MEMBER_SELECTOR) Int2ObjectHashMap(com.hazelcast.internal.util.collection.Int2ObjectHashMap) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MigrationRequestOperation(com.hazelcast.internal.partition.operation.MigrationRequestOperation) Map(java.util.Map) BOOLEAN(com.hazelcast.internal.metrics.ProbeUnit.BOOLEAN) PARTITIONS_PREFIX(com.hazelcast.internal.metrics.MetricDescriptorConstants.PARTITIONS_PREFIX) PersistenceConfig(com.hazelcast.config.PersistenceConfig) IntHashSet(com.hazelcast.internal.util.collection.IntHashSet) PARTITION_FRAGMENTED_MIGRATION_ENABLED(com.hazelcast.spi.properties.ClusterProperty.PARTITION_FRAGMENTED_MIGRATION_ENABLED) InternalPartition(com.hazelcast.internal.partition.InternalPartition) IPartitionLostEvent(com.hazelcast.internal.partition.IPartitionLostEvent) Probe(com.hazelcast.internal.metrics.Probe) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) BlockingQueue(java.util.concurrent.BlockingQueue) TargetNotMemberException(com.hazelcast.spi.exception.TargetNotMemberException) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) PARTITION_CHUNKED_MIGRATION_ENABLED(com.hazelcast.spi.properties.ClusterProperty.PARTITION_CHUNKED_MIGRATION_ENABLED) Node(com.hazelcast.instance.impl.Node) ClusterProperty(com.hazelcast.spi.properties.ClusterProperty) Objects(java.util.Objects) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) List(java.util.List) CompletionStage(java.util.concurrent.CompletionStage) OperationTimeoutException(com.hazelcast.core.OperationTimeoutException) PartitionIdSet(com.hazelcast.internal.util.collection.PartitionIdSet) Queue(java.util.Queue) MigrationStatus(com.hazelcast.internal.partition.MigrationInfo.MigrationStatus) MEGABYTES(com.hazelcast.memory.MemoryUnit.MEGABYTES) ReplicaMigrationEvent(com.hazelcast.partition.ReplicaMigrationEvent) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) ExecutionService(com.hazelcast.spi.impl.executionservice.ExecutionService) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) Level(java.util.logging.Level) MigrationEndpoint(com.hazelcast.internal.partition.MigrationEndpoint) HashSet(java.util.HashSet) PARTITION_MIGRATION_TIMEOUT(com.hazelcast.spi.properties.ClusterProperty.PARTITION_MIGRATION_TIMEOUT) ILogger(com.hazelcast.logging.ILogger) Operation(com.hazelcast.spi.impl.operationservice.Operation) PartitionReplica(com.hazelcast.internal.partition.PartitionReplica) FinalizeMigrationOperation(com.hazelcast.internal.partition.operation.FinalizeMigrationOperation) LinkedList(java.util.LinkedList) ClusterServiceImpl(com.hazelcast.internal.cluster.impl.ClusterServiceImpl) PartitionStateOperation(com.hazelcast.internal.partition.operation.PartitionStateOperation) LinkedHashSet(java.util.LinkedHashSet) Timer(com.hazelcast.internal.util.Timer) NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) CoalescingDelayedTrigger(com.hazelcast.internal.util.scheduler.CoalescingDelayedTrigger) Iterator(java.util.Iterator) Executor(java.util.concurrent.Executor) MigrationParticipant(com.hazelcast.internal.partition.impl.MigrationInterceptor.MigrationParticipant) MemberLeftException(com.hazelcast.core.MemberLeftException) HazelcastProperties(com.hazelcast.spi.properties.HazelcastProperties) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) PARTITION_CHUNKED_MAX_MIGRATING_DATA_IN_MB(com.hazelcast.spi.properties.ClusterProperty.PARTITION_CHUNKED_MAX_MIGRATING_DATA_IN_MB) PartitionReplicaSyncRequest(com.hazelcast.internal.partition.operation.PartitionReplicaSyncRequest) Lock(java.util.concurrent.locks.Lock) SERVICE_NAME(com.hazelcast.internal.partition.IPartitionService.SERVICE_NAME) MigrationDecisionCallback(com.hazelcast.internal.partition.impl.MigrationPlanner.MigrationDecisionCallback) PromotionCommitOperation(com.hazelcast.internal.partition.operation.PromotionCommitOperation) ClusterState(com.hazelcast.cluster.ClusterState) PublishCompletedMigrationsOperation(com.hazelcast.internal.partition.operation.PublishCompletedMigrationsOperation) MigrationInfo(com.hazelcast.internal.partition.MigrationInfo) PARTITION_MIGRATION_INTERVAL(com.hazelcast.spi.properties.ClusterProperty.PARTITION_MIGRATION_INTERVAL) OperationService(com.hazelcast.spi.impl.operationservice.OperationService) Comparator(java.util.Comparator) Collections(java.util.Collections) PartitionReplica(com.hazelcast.internal.partition.PartitionReplica) OperationTimeoutException(com.hazelcast.core.OperationTimeoutException) UUID(java.util.UUID) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Member(com.hazelcast.cluster.Member)

Aggregations

Address (com.hazelcast.cluster.Address)1 ClusterState (com.hazelcast.cluster.ClusterState)1 Member (com.hazelcast.cluster.Member)1 DATA_MEMBER_SELECTOR (com.hazelcast.cluster.memberselector.MemberSelectors.DATA_MEMBER_SELECTOR)1 PersistenceConfig (com.hazelcast.config.PersistenceConfig)1 HazelcastInstanceNotActiveException (com.hazelcast.core.HazelcastInstanceNotActiveException)1 MemberLeftException (com.hazelcast.core.MemberLeftException)1 OperationTimeoutException (com.hazelcast.core.OperationTimeoutException)1 Node (com.hazelcast.instance.impl.Node)1 ClusterServiceImpl (com.hazelcast.internal.cluster.impl.ClusterServiceImpl)1 MIGRATION_METRIC_MIGRATION_MANAGER_MIGRATION_ACTIVE (com.hazelcast.internal.metrics.MetricDescriptorConstants.MIGRATION_METRIC_MIGRATION_MANAGER_MIGRATION_ACTIVE)1 PARTITIONS_PREFIX (com.hazelcast.internal.metrics.MetricDescriptorConstants.PARTITIONS_PREFIX)1 Probe (com.hazelcast.internal.metrics.Probe)1 BOOLEAN (com.hazelcast.internal.metrics.ProbeUnit.BOOLEAN)1 IPartitionLostEvent (com.hazelcast.internal.partition.IPartitionLostEvent)1 SERVICE_NAME (com.hazelcast.internal.partition.IPartitionService.SERVICE_NAME)1 InternalPartition (com.hazelcast.internal.partition.InternalPartition)1 MigrationEndpoint (com.hazelcast.internal.partition.MigrationEndpoint)1 MigrationInfo (com.hazelcast.internal.partition.MigrationInfo)1 MigrationStatus (com.hazelcast.internal.partition.MigrationInfo.MigrationStatus)1