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;
}
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;
}
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);
}
}
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;
}
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;
}
Aggregations