Search in sources :

Example 21 with InternalCompletableFuture

use of com.hazelcast.spi.impl.InternalCompletableFuture in project hazelcast by hazelcast.

the class ClientExecutorServiceProxy method submitToTargetInternal.

private <T> void submitToTargetInternal(@Nonnull Data task, Member member, @Nullable ExecutionCallback<T> callback) {
    checkNotNull(task, "task should not be null");
    UUID uuid = getUUID();
    ClientMessage request = ExecutorServiceSubmitToMemberCodec.encodeRequest(name, uuid, task, member.getUuid());
    ClientInvocationFuture f = invokeOnTarget(request, member);
    InternalCompletableFuture<T> delegatingFuture = (InternalCompletableFuture<T>) delegatingFuture(f, uuid, member, (T) null);
    if (callback != null) {
        delegatingFuture.whenCompleteAsync(new ExecutionCallbackAdapter<>(callback)).whenCompleteAsync((v, t) -> {
            if (t instanceof RejectedExecutionException) {
                callback.onFailure(t);
            }
        }, ConcurrencyUtil.getDefaultAsyncExecutor());
    }
}
Also used : ExecutionCallbackAdapter(com.hazelcast.executor.impl.ExecutionCallbackAdapter) InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) UUID(java.util.UUID) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ClientInvocationFuture(com.hazelcast.client.impl.spi.impl.ClientInvocationFuture)

Example 22 with InternalCompletableFuture

use of com.hazelcast.spi.impl.InternalCompletableFuture in project hazelcast by hazelcast.

the class RaftService method removeCPMember.

public InternalCompletableFuture<Void> removeCPMember(UUID cpMemberUuid) {
    ClusterService clusterService = nodeEngine.getClusterService();
    InternalCompletableFuture<Void> future = newCompletableFuture();
    BiConsumer<Void, Throwable> removeMemberCallback = (response, t) -> {
        if (t == null) {
            future.complete(null);
        } else {
            if (t instanceof CannotRemoveCPMemberException) {
                t = new IllegalStateException(t.getMessage());
            }
            complete(future, t);
        }
    };
    invocationManager.<Collection<CPMember>>invoke(getMetadataGroupId(), new GetActiveCPMembersOp()).whenCompleteAsync((cpMembers, t) -> {
        if (t == null) {
            CPMemberInfo cpMemberToRemove = null;
            for (CPMember cpMember : cpMembers) {
                if (cpMember.getUuid().equals(cpMemberUuid)) {
                    cpMemberToRemove = (CPMemberInfo) cpMember;
                    break;
                }
            }
            if (cpMemberToRemove == null) {
                complete(future, new IllegalArgumentException("No CPMember found with uuid: " + cpMemberUuid));
                return;
            } else {
                Member member = clusterService.getMember(cpMemberToRemove.getAddress());
                if (member != null) {
                    logger.warning("Only unreachable/crashed CP members should be removed. " + member + " is alive but " + cpMemberToRemove + " with the same address is being removed.");
                }
            }
            invokeTriggerRemoveMember(cpMemberToRemove).whenCompleteAsync(removeMemberCallback);
        } else {
            complete(future, t);
        }
    });
    return future;
}
Also used : RaftNodeStatus(com.hazelcast.cp.internal.raft.impl.RaftNodeStatus) AppendSuccessResponse(com.hazelcast.cp.internal.raft.impl.dto.AppendSuccessResponse) Clock(com.hazelcast.internal.util.Clock) CP_METRIC_RAFT_SERVICE_TERMINATED_RAFT_NODE_GROUP_IDS(com.hazelcast.internal.metrics.MetricDescriptorConstants.CP_METRIC_RAFT_SERVICE_TERMINATED_RAFT_NODE_GROUP_IDS) InstallSnapshot(com.hazelcast.cp.internal.raft.impl.dto.InstallSnapshot) RaftIntegration(com.hazelcast.cp.internal.raft.impl.RaftIntegration) ManagedService(com.hazelcast.internal.services.ManagedService) PartitionMigratingException(com.hazelcast.spi.exception.PartitionMigratingException) MemberImpl(com.hazelcast.cluster.impl.MemberImpl) VoteResponse(com.hazelcast.cp.internal.raft.impl.dto.VoteResponse) ClusterService(com.hazelcast.internal.cluster.ClusterService) Future(java.util.concurrent.Future) CPGroup(com.hazelcast.cp.CPGroup) CPGroupDestroyedException(com.hazelcast.cp.exception.CPGroupDestroyedException) RaftNodeImpl(com.hazelcast.cp.internal.raft.impl.RaftNodeImpl) Map(java.util.Map) CPSubsystemConfig(com.hazelcast.config.cp.CPSubsystemConfig) RaftAlgorithmConfig(com.hazelcast.config.cp.RaftAlgorithmConfig) StringUtil.equalsIgnoreCase(com.hazelcast.internal.util.StringUtil.equalsIgnoreCase) CP_PREFIX_RAFT_METADATA(com.hazelcast.internal.metrics.MetricDescriptorConstants.CP_PREFIX_RAFT_METADATA) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) RaftRemoteService(com.hazelcast.cp.internal.datastructures.spi.RaftRemoteService) CPPersistenceService(com.hazelcast.cp.internal.persistence.CPPersistenceService) ExceptionUtil(com.hazelcast.internal.util.ExceptionUtil) Set(java.util.Set) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) CP_PREFIX_RAFT_GROUP(com.hazelcast.internal.metrics.MetricDescriptorConstants.CP_PREFIX_RAFT_GROUP) EventListener(java.util.EventListener) PartitionReplicationEvent(com.hazelcast.internal.partition.PartitionReplicationEvent) CPMember(com.hazelcast.cp.CPMember) CP_DISCRIMINATOR_GROUPID(com.hazelcast.internal.metrics.MetricDescriptorConstants.CP_DISCRIMINATOR_GROUPID) GetActiveRaftGroupIdsOp(com.hazelcast.cp.internal.raftop.metadata.GetActiveRaftGroupIdsOp) CPGroupAvailabilityEventImpl(com.hazelcast.cp.event.impl.CPGroupAvailabilityEventImpl) Versions(com.hazelcast.internal.cluster.Versions) GetInitialRaftGroupMembersIfCurrentGroupMemberOp(com.hazelcast.cp.internal.raftop.GetInitialRaftGroupMembersIfCurrentGroupMemberOp) CP_METRIC_RAFT_SERVICE_NODES(com.hazelcast.internal.metrics.MetricDescriptorConstants.CP_METRIC_RAFT_SERVICE_NODES) RaftManagedService(com.hazelcast.cp.internal.datastructures.spi.RaftManagedService) VoteRequest(com.hazelcast.cp.internal.raft.impl.dto.VoteRequest) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) ArrayList(java.util.ArrayList) MigrationEndpoint(com.hazelcast.internal.partition.MigrationEndpoint) CP_PREFIX_RAFT(com.hazelcast.internal.metrics.MetricDescriptorConstants.CP_PREFIX_RAFT) SYSTEM_EXECUTOR(com.hazelcast.spi.impl.executionservice.ExecutionService.SYSTEM_EXECUTOR) RestoredRaftState(com.hazelcast.cp.internal.raft.impl.persistence.RestoredRaftState) LINEARIZABLE(com.hazelcast.cp.internal.raft.QueryPolicy.LINEARIZABLE) BiConsumer(java.util.function.BiConsumer) CPMembershipListener(com.hazelcast.cp.event.CPMembershipListener) RaftNode(com.hazelcast.cp.internal.raft.impl.RaftNode) GetRaftGroupIdsOp(com.hazelcast.cp.internal.raftop.metadata.GetRaftGroupIdsOp) MembershipServiceEvent(com.hazelcast.internal.services.MembershipServiceEvent) DEFAULT_GROUP_NAME(com.hazelcast.cp.CPGroup.DEFAULT_GROUP_NAME) NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) RaftState(com.hazelcast.cp.internal.raft.impl.state.RaftState) InternalCompletableFuture.newCompletedFuture(com.hazelcast.spi.impl.InternalCompletableFuture.newCompletedFuture) Properties(java.util.Properties) RaftLog(com.hazelcast.cp.internal.raft.impl.log.RaftLog) MetricsCollectionContext(com.hazelcast.internal.metrics.MetricsCollectionContext) MembershipAwareService(com.hazelcast.internal.services.MembershipAwareService) Preconditions.checkNotNull(com.hazelcast.internal.util.Preconditions.checkNotNull) GetActiveCPMembersOp(com.hazelcast.cp.internal.raftop.metadata.GetActiveCPMembersOp) ExecutionException(java.util.concurrent.ExecutionException) AddCPMemberOp(com.hazelcast.cp.internal.raftop.metadata.AddCPMemberOp) CPGroupAvailabilityEvent(com.hazelcast.cp.event.CPGroupAvailabilityEvent) ManagedExecutorService(com.hazelcast.internal.util.executor.ManagedExecutorService) RaftStateStore(com.hazelcast.cp.internal.raft.impl.persistence.RaftStateStore) Member(com.hazelcast.cluster.Member) ResetCPMemberOp(com.hazelcast.cp.internal.operation.ResetCPMemberOp) PreVoteRequest(com.hazelcast.cp.internal.raft.impl.dto.PreVoteRequest) ForceDestroyRaftGroupOp(com.hazelcast.cp.internal.raftop.metadata.ForceDestroyRaftGroupOp) SnapshotAwareService(com.hazelcast.cp.internal.raft.SnapshotAwareService) RaftServicePreJoinOp(com.hazelcast.cp.internal.raftop.metadata.RaftServicePreJoinOp) InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) AppendFailureResponse(com.hazelcast.cp.internal.raft.impl.dto.AppendFailureResponse) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CPGroupAvailabilityListener(com.hazelcast.cp.event.CPGroupAvailabilityListener) CannotRemoveCPMemberException(com.hazelcast.cp.internal.exception.CannotRemoveCPMemberException) DynamicMetricsProvider(com.hazelcast.internal.metrics.DynamicMetricsProvider) GetRaftGroupOp(com.hazelcast.cp.internal.raftop.metadata.GetRaftGroupOp) ProbeLevel(com.hazelcast.internal.metrics.ProbeLevel) CP_METRIC_RAFT_SERVICE_DESTROYED_GROUP_IDS(com.hazelcast.internal.metrics.MetricDescriptorConstants.CP_METRIC_RAFT_SERVICE_DESTROYED_GROUP_IDS) Preconditions.checkTrue(com.hazelcast.internal.util.Preconditions.checkTrue) ResponseAlreadySentException(com.hazelcast.spi.exception.ResponseAlreadySentException) UnsafeStateReplicationOp(com.hazelcast.cp.internal.operation.unsafe.UnsafeStateReplicationOp) RaftEndpoint(com.hazelcast.cp.internal.raft.impl.RaftEndpoint) ServiceInfo(com.hazelcast.spi.impl.servicemanager.ServiceInfo) LogFileStructure(com.hazelcast.cp.internal.raft.impl.persistence.LogFileStructure) Probe(com.hazelcast.internal.metrics.Probe) Collection(java.util.Collection) METADATA_CP_GROUP_NAME(com.hazelcast.cp.CPGroup.METADATA_CP_GROUP_NAME) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) TriggerLeaderElection(com.hazelcast.cp.internal.raft.impl.dto.TriggerLeaderElection) RaftRole(com.hazelcast.cp.internal.raft.impl.RaftRole) MetricsPlugin(com.hazelcast.internal.diagnostics.MetricsPlugin) UUID(java.util.UUID) RaftNodeImpl.newRaftNode(com.hazelcast.cp.internal.raft.impl.RaftNodeImpl.newRaftNode) List(java.util.List) LEADER_LOCAL(com.hazelcast.cp.internal.raft.QueryPolicy.LEADER_LOCAL) Entry(java.util.Map.Entry) Preconditions.checkFalse(com.hazelcast.internal.util.Preconditions.checkFalse) CP_METRIC_RAFT_SERVICE_MISSING_MEMBERS(com.hazelcast.internal.metrics.MetricDescriptorConstants.CP_METRIC_RAFT_SERVICE_MISSING_MEMBERS) PartitionMigrationEvent(com.hazelcast.internal.partition.PartitionMigrationEvent) MetricsRegistry(com.hazelcast.internal.metrics.MetricsRegistry) ExecutionService(com.hazelcast.spi.impl.executionservice.ExecutionService) UuidUtil.newUnsecureUUID(com.hazelcast.internal.util.UuidUtil.newUnsecureUUID) MigrationAwareService(com.hazelcast.internal.partition.MigrationAwareService) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl) PartitionOperationThread(com.hazelcast.spi.impl.operationexecutor.impl.PartitionOperationThread) ConcurrentMap(java.util.concurrent.ConcurrentMap) AppendRequest(com.hazelcast.cp.internal.raft.impl.dto.AppendRequest) MetricDescriptor(com.hazelcast.internal.metrics.MetricDescriptor) Collections.newSetFromMap(java.util.Collections.newSetFromMap) CPMembershipEvent(com.hazelcast.cp.event.CPMembershipEvent) ILogger(com.hazelcast.logging.ILogger) Operation(com.hazelcast.spi.impl.operationservice.Operation) EventPublishingService(com.hazelcast.spi.impl.eventservice.EventPublishingService) CPGroupId(com.hazelcast.cp.CPGroupId) Timer(com.hazelcast.internal.util.Timer) NodeEngine(com.hazelcast.spi.impl.NodeEngine) GetActiveRaftGroupByNameOp(com.hazelcast.cp.internal.raftop.metadata.GetActiveRaftGroupByNameOp) Data(com.hazelcast.internal.serialization.Data) NON_LOCAL_MEMBER_SELECTOR(com.hazelcast.cluster.memberselector.MemberSelectors.NON_LOCAL_MEMBER_SELECTOR) RemoveCPMemberOp(com.hazelcast.cp.internal.raftop.metadata.RemoveCPMemberOp) Preconditions.checkState(com.hazelcast.internal.util.Preconditions.checkState) ConfigValidator.checkCPSubsystemConfig(com.hazelcast.internal.config.ConfigValidator.checkCPSubsystemConfig) CP_TAG_NAME(com.hazelcast.internal.metrics.MetricDescriptorConstants.CP_TAG_NAME) TimeUnit(java.util.concurrent.TimeUnit) PreVoteResponse(com.hazelcast.cp.internal.raft.impl.dto.PreVoteResponse) GracefulShutdownAwareService(com.hazelcast.internal.services.GracefulShutdownAwareService) PreJoinAwareService(com.hazelcast.internal.services.PreJoinAwareService) Collections(java.util.Collections) SECONDS(java.util.concurrent.TimeUnit.SECONDS) MANAGEMENT_TASK_PERIOD_IN_MILLIS(com.hazelcast.cp.internal.RaftGroupMembershipManager.MANAGEMENT_TASK_PERIOD_IN_MILLIS) CannotRemoveCPMemberException(com.hazelcast.cp.internal.exception.CannotRemoveCPMemberException) GetActiveCPMembersOp(com.hazelcast.cp.internal.raftop.metadata.GetActiveCPMembersOp) CPMember(com.hazelcast.cp.CPMember) ClusterService(com.hazelcast.internal.cluster.ClusterService) CPMember(com.hazelcast.cp.CPMember) Member(com.hazelcast.cluster.Member)

Example 23 with InternalCompletableFuture

use of com.hazelcast.spi.impl.InternalCompletableFuture in project hazelcast by hazelcast.

the class RaftInvocationManager method completeExceptionallyIfCPSubsystemNotAvailable.

private <V> InternalCompletableFuture<V> completeExceptionallyIfCPSubsystemNotAvailable() {
    if (!cpSubsystemEnabled) {
        InternalCompletableFuture<V> future = new InternalCompletableFuture<>();
        future.completeExceptionally(new HazelcastException("CP Subsystem is not enabled!"));
        return future;
    }
    return null;
}
Also used : HazelcastException(com.hazelcast.core.HazelcastException) InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture)

Example 24 with InternalCompletableFuture

use of com.hazelcast.spi.impl.InternalCompletableFuture in project hazelcast by hazelcast.

the class RaftService method resetLocalRaftState.

private void resetLocalRaftState() {
    // node.forceSetTerminatedStatus() will trigger RaftNodeLifecycleAwareService.onRaftGroupDestroyed()
    // which will attempt to acquire the read lock on nodeLock. In order to prevent it, we first
    // add group ids into destroyedGroupIds to short-cut RaftNodeLifecycleAwareService.onRaftGroupDestroyed()
    List<InternalCompletableFuture> futures = new ArrayList<>(nodes.size());
    destroyedGroupIds.addAll(nodes.keySet());
    for (RaftNode node : nodes.values()) {
        InternalCompletableFuture f = node.forceSetTerminatedStatus();
        futures.add(f);
    }
    for (InternalCompletableFuture future : futures) {
        try {
            future.get();
        } catch (Exception e) {
            logger.warning(e);
        }
    }
    nodes.clear();
    for (ServiceInfo serviceInfo : nodeEngine.getServiceInfos(RaftRemoteService.class)) {
        if (serviceInfo.getService() instanceof RaftManagedService) {
            ((RaftManagedService) serviceInfo.getService()).onCPSubsystemRestart();
        }
    }
    nodeMetrics.clear();
    missingMembers.clear();
    invocationManager.reset();
}
Also used : ServiceInfo(com.hazelcast.spi.impl.servicemanager.ServiceInfo) InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) ArrayList(java.util.ArrayList) RaftManagedService(com.hazelcast.cp.internal.datastructures.spi.RaftManagedService) RaftNode(com.hazelcast.cp.internal.raft.impl.RaftNode) RaftNodeImpl.newRaftNode(com.hazelcast.cp.internal.raft.impl.RaftNodeImpl.newRaftNode) PartitionMigratingException(com.hazelcast.spi.exception.PartitionMigratingException) CPGroupDestroyedException(com.hazelcast.cp.exception.CPGroupDestroyedException) ExecutionException(java.util.concurrent.ExecutionException) CannotRemoveCPMemberException(com.hazelcast.cp.internal.exception.CannotRemoveCPMemberException) ResponseAlreadySentException(com.hazelcast.spi.exception.ResponseAlreadySentException)

Example 25 with InternalCompletableFuture

use of com.hazelcast.spi.impl.InternalCompletableFuture in project hazelcast by hazelcast.

the class InvocationFuture_IsDoneTest method isDone_whenNoResponse.

@Test
public void isDone_whenNoResponse() {
    DummyOperation op = new GetLostPartitionOperation();
    InternalCompletableFuture future = operationService.invokeOnTarget(null, op, getAddress(local));
    assertFalse(future.isDone());
}
Also used : InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

InternalCompletableFuture (com.hazelcast.spi.impl.InternalCompletableFuture)90 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)47 QuickTest (com.hazelcast.test.annotation.QuickTest)47 Test (org.junit.Test)47 OperationService (com.hazelcast.spi.impl.operationservice.OperationService)19 HazelcastInstance (com.hazelcast.core.HazelcastInstance)17 Accessors.getOperationService (com.hazelcast.test.Accessors.getOperationService)15 Data (com.hazelcast.internal.serialization.Data)10 ArrayList (java.util.ArrayList)10 Map (java.util.Map)10 Operation (com.hazelcast.spi.impl.operationservice.Operation)9 UUID (java.util.UUID)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)8 Member (com.hazelcast.cluster.Member)7 ApplyRaftRunnable (com.hazelcast.cp.internal.raft.impl.dataservice.ApplyRaftRunnable)7 Future (java.util.concurrent.Future)7 Address (com.hazelcast.cluster.Address)6 List (java.util.List)6 BiConsumer (java.util.function.BiConsumer)6 Nonnull (javax.annotation.Nonnull)6