Search in sources :

Example 56 with InternalCompletableFuture

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

the class NearCachedClientMapProxy method submitToKeyInternal.

@Override
public <R> InternalCompletableFuture<R> submitToKeyInternal(Object key, EntryProcessor<K, V, R> entryProcessor) {
    key = toNearCacheKey(key);
    InternalCompletableFuture future;
    try {
        future = super.submitToKeyInternal(key, entryProcessor);
    } finally {
        invalidateNearCache(key);
    }
    return future;
}
Also used : InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture)

Example 57 with InternalCompletableFuture

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

the class RaftInvocationManager method invokeGetMembersToCreateRaftGroup.

private void invokeGetMembersToCreateRaftGroup(String groupName, int groupSize, InternalCompletableFuture<RaftGroupId> resultFuture) {
    RaftGroupId metadataGroupId = raftService.getMetadataGroupId();
    InternalCompletableFuture<List<CPMemberInfo>> f1 = query(metadataGroupId, new GetActiveCPMembersOp(), LINEARIZABLE);
    InternalCompletableFuture<Collection<RaftGroupId>> f2 = query(metadataGroupId, new GetRaftGroupIdsOp(), LINEARIZABLE);
    f1.thenCombineAsync(f2, (cpMembers, groupIds) -> {
        if (cpMembers.size() < groupSize) {
            Exception e = new IllegalArgumentException("There are not enough active CP members to create CP group " + groupName + ". Active CP members: " + cpMembers.size() + ", Requested CP group size: " + groupSize);
            resultFuture.completeExceptionally(e);
            return null;
        }
        long groupIndex = generateRandomGroupIndex(groupIds);
        List<RaftEndpoint> groupEndpoints = generateRandomGroupMembers(cpMembers, groupSize);
        invokeCreateRaftGroup(groupName, groupSize, groupIndex, groupEndpoints, resultFuture);
        return null;
    }).exceptionally(t -> {
        resultFuture.completeExceptionally(t);
        return null;
    });
}
Also used : Collections.shuffle(java.util.Collections.shuffle) ChangeRaftGroupMembershipOp(com.hazelcast.cp.internal.operation.ChangeRaftGroupMembershipOp) AbstractUnsafeRaftOp(com.hazelcast.cp.internal.operation.unsafe.AbstractUnsafeRaftOp) MembershipChangeMode(com.hazelcast.cp.internal.raft.MembershipChangeMode) DEFAULT_DESERIALIZE_RESULT(com.hazelcast.spi.impl.operationservice.InvocationBuilder.DEFAULT_DESERIALIZE_RESULT) RaftInvocationContext(com.hazelcast.spi.impl.operationservice.impl.RaftInvocationContext) CannotCreateRaftGroupException(com.hazelcast.cp.internal.exception.CannotCreateRaftGroupException) ExecutionService(com.hazelcast.spi.impl.executionservice.ExecutionService) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl) ArrayList(java.util.ArrayList) CreateRaftGroupOp(com.hazelcast.cp.internal.raftop.metadata.CreateRaftGroupOp) InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) ClusterService(com.hazelcast.internal.cluster.ClusterService) LINEARIZABLE(com.hazelcast.cp.internal.raft.QueryPolicy.LINEARIZABLE) ILogger(com.hazelcast.logging.ILogger) Operation(com.hazelcast.spi.impl.operationservice.Operation) Invocation(com.hazelcast.spi.impl.operationservice.impl.Invocation) CreateRaftNodeOp(com.hazelcast.cp.internal.raftop.metadata.CreateRaftNodeOp) GetRaftGroupIdsOp(com.hazelcast.cp.internal.raftop.metadata.GetRaftGroupIdsOp) CPGroupId(com.hazelcast.cp.CPGroupId) RaftEndpoint(com.hazelcast.cp.internal.raft.impl.RaftEndpoint) NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) HazelcastException(com.hazelcast.core.HazelcastException) NodeEngine(com.hazelcast.spi.impl.NodeEngine) DefaultRaftReplicateOp(com.hazelcast.cp.internal.operation.DefaultRaftReplicateOp) UnsafeRaftReplicateOp(com.hazelcast.cp.internal.operation.unsafe.UnsafeRaftReplicateOp) Collection(java.util.Collection) RandomPicker(com.hazelcast.internal.util.RandomPicker) QueryPolicy(com.hazelcast.cp.internal.raft.QueryPolicy) Collectors(java.util.stream.Collectors) DestroyRaftGroupOp(com.hazelcast.cp.internal.operation.DestroyRaftGroupOp) RaftQueryOp(com.hazelcast.cp.internal.operation.RaftQueryOp) GetActiveCPMembersOp(com.hazelcast.cp.internal.raftop.metadata.GetActiveCPMembersOp) ClusterProperty(com.hazelcast.spi.properties.ClusterProperty) CP_SUBSYSTEM_EXECUTOR(com.hazelcast.cp.internal.RaftService.CP_SUBSYSTEM_EXECUTOR) List(java.util.List) CPMember(com.hazelcast.cp.CPMember) RaftInvocation(com.hazelcast.spi.impl.operationservice.impl.RaftInvocation) OperationService(com.hazelcast.spi.impl.operationservice.OperationService) Comparator(java.util.Comparator) UnsafeRaftQueryOp(com.hazelcast.cp.internal.operation.unsafe.UnsafeRaftQueryOp) Collection(java.util.Collection) GetRaftGroupIdsOp(com.hazelcast.cp.internal.raftop.metadata.GetRaftGroupIdsOp) ArrayList(java.util.ArrayList) List(java.util.List) GetActiveCPMembersOp(com.hazelcast.cp.internal.raftop.metadata.GetActiveCPMembersOp) CannotCreateRaftGroupException(com.hazelcast.cp.internal.exception.CannotCreateRaftGroupException) HazelcastException(com.hazelcast.core.HazelcastException)

Example 58 with InternalCompletableFuture

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

the class AtomicLongProxy method localGetAsync.

public InternalCompletableFuture<Long> localGetAsync(QueryPolicy queryPolicy) {
    InternalCompletableFuture<Long> resultFuture = new InternalCompletableFuture<>();
    InternalCompletableFuture<Long> localFuture = invocationManager.queryLocally(groupId, new LocalGetOp(objectName), queryPolicy);
    localFuture.whenCompleteAsync((response, throwable) -> {
        if (throwable == null) {
            resultFuture.complete(response);
        } else {
            InternalCompletableFuture<Long> future = invocationManager.query(groupId, new LocalGetOp(objectName), queryPolicy);
            future.whenCompleteAsync(completingCallback(resultFuture));
        }
    });
    return resultFuture;
}
Also used : LocalGetOp(com.hazelcast.cp.internal.datastructures.atomiclong.operation.LocalGetOp) InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) IAtomicLong(com.hazelcast.cp.IAtomicLong)

Example 59 with InternalCompletableFuture

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

the class RaftNodeImpl method replicateMembershipChange.

@Override
public InternalCompletableFuture replicateMembershipChange(RaftEndpoint member, MembershipChangeMode mode, long groupMembersCommitIndex) {
    InternalCompletableFuture resultFuture = raftIntegration.newCompletableFuture();
    raftIntegration.execute(new MembershipChangeTask(this, resultFuture, member, mode, groupMembersCommitIndex));
    return resultFuture;
}
Also used : InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) MembershipChangeTask(com.hazelcast.cp.internal.raft.impl.task.MembershipChangeTask)

Example 60 with InternalCompletableFuture

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

the class RaftNodeImpl method tryRunQueries.

public boolean tryRunQueries() {
    QueryState queryState = state.leaderState().queryState();
    if (queryState.queryCount() == 0) {
        return false;
    }
    long commitIndex = state.commitIndex();
    if (!queryState.isMajorityAcked(commitIndex, state.majority())) {
        return true;
    }
    Collection<BiTuple<Object, InternalCompletableFuture>> operations = queryState.operations();
    if (logger.isFineEnabled()) {
        logger.fine("Running " + operations.size() + " queries at commit index: " + commitIndex + ", query round: " + queryState.queryRound());
    }
    for (BiTuple<Object, InternalCompletableFuture> t : operations) {
        runQuery(t.element1, t.element2);
    }
    queryState.reset();
    return false;
}
Also used : InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) QueryState(com.hazelcast.cp.internal.raft.impl.state.QueryState) BiTuple(com.hazelcast.internal.util.BiTuple)

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