Search in sources :

Example 1 with OperationServiceImpl

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

the class CPGroupRebalanceTest method getLeadershipsMap.

private Map<CPMember, Collection<CPGroupId>> getLeadershipsMap(HazelcastInstance instance, Collection<CPMember> members) {
    OperationServiceImpl operationService = getOperationService(instance);
    Map<CPMember, Collection<CPGroupId>> leaderships = new HashMap<>();
    for (CPMember member : members) {
        Collection<CPGroupId> groups = operationService.<Collection<CPGroupId>>invokeOnTarget(null, new GetLeadedGroupsOp(), member.getAddress()).join();
        leaderships.put(member, groups);
    }
    return leaderships;
}
Also used : CPGroupId(com.hazelcast.cp.CPGroupId) GetLeadedGroupsOp(com.hazelcast.cp.internal.operation.GetLeadedGroupsOp) HashMap(java.util.HashMap) Collection(java.util.Collection) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl) CPMember(com.hazelcast.cp.CPMember)

Example 2 with OperationServiceImpl

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

the class AbstractMapQueryMessageTask method createInvocations.

private List<Future> createInvocations(Collection<Member> members, Predicate predicate) {
    List<Future> futures = new ArrayList<>(members.size());
    final OperationServiceImpl operationService = nodeEngine.getOperationService();
    final Query query = buildQuery(predicate);
    MapService mapService = nodeEngine.getService(getServiceName());
    MapServiceContext mapServiceContext = mapService.getMapServiceContext();
    for (Member member : members) {
        try {
            Future future = operationService.createInvocationBuilder(SERVICE_NAME, createQueryOperation(query, mapServiceContext), member.getAddress()).invoke();
            futures.add(future);
        } catch (Throwable t) {
            if (!(t instanceof HazelcastException)) {
                // these are programmatic errors that needs to be visible
                throw rethrow(t);
            } else if (t.getCause() instanceof QueryResultSizeExceededException) {
                throw rethrow(t);
            } else {
                // the missing partition IDs will be queried anyway, so it's not a terminal failure
                if (logger.isFineEnabled()) {
                    logger.fine("Query invocation failed on member " + member, t);
                }
            }
        }
    }
    return futures;
}
Also used : HazelcastException(com.hazelcast.core.HazelcastException) Query(com.hazelcast.map.impl.query.Query) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) MapService(com.hazelcast.map.impl.MapService) QueryResultSizeExceededException(com.hazelcast.map.QueryResultSizeExceededException) Member(com.hazelcast.cluster.Member) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl) MapServiceContext(com.hazelcast.map.impl.MapServiceContext)

Example 3 with OperationServiceImpl

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

the class AbstractMapQueryMessageTask method invokeOnPartition.

private QueryResult invokeOnPartition(PartitionPredicate predicate, int partitionId) {
    final OperationServiceImpl operationService = nodeEngine.getOperationService();
    MapService mapService = nodeEngine.getService(getServiceName());
    MapServiceContext mapServiceContext = mapService.getMapServiceContext();
    Query query = buildQuery(predicate);
    MapOperation queryPartitionOperation = createQueryPartitionOperation(query, mapServiceContext);
    queryPartitionOperation.setPartitionId(partitionId);
    try {
        return (QueryResult) operationService.invokeOnPartition(SERVICE_NAME, queryPartitionOperation, partitionId).get();
    } catch (Throwable t) {
        throw rethrow(t);
    }
}
Also used : Query(com.hazelcast.map.impl.query.Query) MapService(com.hazelcast.map.impl.MapService) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl) MapServiceContext(com.hazelcast.map.impl.MapServiceContext) MapOperation(com.hazelcast.map.impl.operation.MapOperation)

Example 4 with OperationServiceImpl

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

the class RaftSessionService method getInactiveSessions.

private Map<CPGroupId, Collection<Long>> getInactiveSessions() {
    Map<CPGroupId, Collection<Long>> response = new ConcurrentHashMap<>();
    Semaphore semaphore = new Semaphore(0);
    OperationServiceImpl operationService = nodeEngine.getOperationService();
    Collection<RaftSessionRegistry> registries = new ArrayList<>(this.registries.values());
    for (RaftSessionRegistry registry : registries) {
        CPGroupId groupId = registry.groupId();
        operationService.execute(new PartitionSpecificRunnableAdaptor(() -> {
            Set<Long> activeSessionIds = new HashSet<>();
            for (SessionAwareService service : nodeEngine.getServices(SessionAwareService.class)) {
                activeSessionIds.addAll(service.getAttachedSessions(groupId));
            }
            Set<Long> inactiveSessionIds = new HashSet<>();
            for (CPSession session : registry.getSessions()) {
                if (!activeSessionIds.contains(session.id()) && session.creationTime() + getSessionTTLMillis() < Clock.currentTimeMillis()) {
                    inactiveSessionIds.add(session.id());
                }
            }
            if (inactiveSessionIds.size() > 0) {
                response.put(groupId, inactiveSessionIds);
            }
            semaphore.release();
        }, nodeEngine.getPartitionService().getPartitionId(groupId)));
    }
    try {
        semaphore.tryAcquire(registries.size(), COLLECT_INACTIVE_SESSIONS_TASK_TIMEOUT_SECONDS, SECONDS);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    }
    return response;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) ArrayList(java.util.ArrayList) Semaphore(java.util.concurrent.Semaphore) CPGroupId(com.hazelcast.cp.CPGroupId) PartitionSpecificRunnableAdaptor(com.hazelcast.cp.internal.util.PartitionSpecificRunnableAdaptor) Collections.unmodifiableCollection(java.util.Collections.unmodifiableCollection) Collection(java.util.Collection) CPSession(com.hazelcast.cp.session.CPSession) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl)

Example 5 with OperationServiceImpl

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

the class PromotionCommitOperation method beforePromotion.

/**
 * Sends {@link BeforePromotionOperation}s for all promotions and register a callback on each operation to track when
 * operations are finished.
 */
private CallStatus beforePromotion() {
    NodeEngineImpl nodeEngine = (NodeEngineImpl) getNodeEngine();
    OperationServiceImpl operationService = nodeEngine.getOperationService();
    InternalPartitionServiceImpl partitionService = getService();
    if (!partitionService.getMigrationManager().acquirePromotionPermit()) {
        throw new RetryableHazelcastException("Another promotion is being run currently. " + "This is only expected when promotion is retried to an unresponsive destination.");
    }
    long partitionStateStamp;
    partitionStateStamp = partitionService.getPartitionStateStamp();
    if (partitionState.getStamp() == partitionStateStamp) {
        return alreadyAppliedAllPromotions();
    }
    filterAlreadyAppliedPromotions();
    if (promotions.isEmpty()) {
        return alreadyAppliedAllPromotions();
    }
    ILogger logger = getLogger();
    migrationState = new MigrationStateImpl(Clock.currentTimeMillis(), promotions.size(), 0, 0L);
    partitionService.getMigrationInterceptor().onPromotionStart(MigrationParticipant.DESTINATION, promotions);
    partitionService.getPartitionEventManager().sendMigrationProcessStartedEvent(migrationState);
    if (logger.isFineEnabled()) {
        logger.fine("Submitting BeforePromotionOperations for " + promotions.size() + " promotions. " + "Promotion partition state stamp: " + partitionState.getStamp() + ", current partition state stamp: " + partitionStateStamp);
    }
    PromotionOperationCallback beforePromotionsCallback = new BeforePromotionOperationCallback(this, promotions.size());
    for (MigrationInfo promotion : promotions) {
        if (logger.isFinestEnabled()) {
            logger.finest("Submitting BeforePromotionOperation for promotion: " + promotion);
        }
        Operation op = new BeforePromotionOperation(promotion, beforePromotionsCallback);
        op.setPartitionId(promotion.getPartitionId()).setNodeEngine(nodeEngine).setService(partitionService);
        operationService.execute(op);
    }
    return CallStatus.VOID;
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) MigrationInfo(com.hazelcast.internal.partition.MigrationInfo) RetryableHazelcastException(com.hazelcast.spi.exception.RetryableHazelcastException) InternalPartitionServiceImpl(com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl) ILogger(com.hazelcast.logging.ILogger) MigrationStateImpl(com.hazelcast.internal.partition.MigrationStateImpl) Operation(com.hazelcast.spi.impl.operationservice.Operation) MigrationCycleOperation(com.hazelcast.internal.partition.MigrationCycleOperation) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl)

Aggregations

OperationServiceImpl (com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl)70 Test (org.junit.Test)29 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)26 QuickTest (com.hazelcast.test.annotation.QuickTest)25 Address (com.hazelcast.cluster.Address)22 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)16 HazelcastInstance (com.hazelcast.core.HazelcastInstance)15 Operation (com.hazelcast.spi.impl.operationservice.Operation)12 PartitionIdSet (com.hazelcast.internal.util.collection.PartitionIdSet)11 IndexIterationPointer (com.hazelcast.internal.iteration.IndexIterationPointer)10 MapFetchIndexOperationResult (com.hazelcast.map.impl.operation.MapFetchIndexOperation.MapFetchIndexOperationResult)10 Config (com.hazelcast.config.Config)9 ExecutionException (java.util.concurrent.ExecutionException)9 Accessors.getNodeEngineImpl (com.hazelcast.test.Accessors.getNodeEngineImpl)8 AssertTask (com.hazelcast.test.AssertTask)7 CountDownLatch (java.util.concurrent.CountDownLatch)7 Member (com.hazelcast.cluster.Member)5 Data (com.hazelcast.internal.serialization.Data)5 MapService (com.hazelcast.map.impl.MapService)5 MapServiceContext (com.hazelcast.map.impl.MapServiceContext)5