use of com.hazelcast.internal.partition.IPartitionService in project hazelcast by hazelcast.
the class XATransaction method putTransactionInfoRemote.
private void putTransactionInfoRemote() throws ExecutionException, InterruptedException {
PutRemoteTransactionOperation operation = new PutRemoteTransactionOperation(transactionLog.getRecords(), txnId, xid, txOwnerUuid, timeoutMillis, startTime);
OperationService operationService = nodeEngine.getOperationService();
IPartitionService partitionService = nodeEngine.getPartitionService();
int partitionId = partitionService.getPartitionId(xid);
InternalCompletableFuture<Object> future = operationService.invokeOnPartition(SERVICE_NAME, operation, partitionId);
future.get();
}
use of com.hazelcast.internal.partition.IPartitionService in project hazelcast by hazelcast.
the class ExecutionPlanBuilder method getPartitionAssignment.
/**
* Assign the partitions to their owners. Partitions whose owner isn't in
* the {@code memberList}, are assigned to one of the members in a
* round-robin way.
*/
public static Map<MemberInfo, int[]> getPartitionAssignment(NodeEngine nodeEngine, List<MemberInfo> memberList) {
IPartitionService partitionService = nodeEngine.getPartitionService();
Map<Address, MemberInfo> membersByAddress = memberList.stream().collect(toMap(MemberInfo::getAddress, identity()));
final MemberInfo[] partitionOwners = new MemberInfo[partitionService.getPartitionCount()];
int memberIndex = 0;
for (int partitionId = 0; partitionId < partitionOwners.length; partitionId++) {
Address address = partitionService.getPartitionOwnerOrWait(partitionId);
MemberInfo member = membersByAddress.get(address);
if (member == null) {
// if the partition owner isn't in the current memberList, assign to one of the other members in
// round-robin fashion
member = memberList.get(memberIndex++ % memberList.size());
}
partitionOwners[partitionId] = member;
}
return IntStream.range(0, partitionOwners.length).mapToObj(i -> tuple2(partitionOwners[i], i)).collect(Collectors.groupingBy(Tuple2::f0, Collectors.mapping(Tuple2::f1, Collectors.collectingAndThen(Collectors.<Integer>toList(), intList -> intList.stream().mapToInt(Integer::intValue).toArray()))));
}
use of com.hazelcast.internal.partition.IPartitionService in project hazelcast by hazelcast.
the class ExecutionPlan method initDag.
private void initDag(InternalSerializationService jobSerializationService) {
final Map<Integer, VertexDef> vMap = vertices.stream().collect(toMap(VertexDef::vertexId, v -> v));
for (VertexDef v : vertices) {
v.inboundEdges().forEach(e -> e.initTransientFields(vMap, v, false));
v.outboundEdges().forEach(e -> e.initTransientFields(vMap, v, true));
}
final IPartitionService partitionService = nodeEngine.getPartitionService();
vertices.stream().map(VertexDef::outboundEdges).flatMap(List::stream).map(EdgeDef::partitioner).filter(Objects::nonNull).forEach(partitioner -> {
if (partitioner instanceof SerializationServiceAware) {
((SerializationServiceAware) partitioner).setSerializationService(jobSerializationService);
}
partitioner.init(object -> partitionService.getPartitionId(jobSerializationService.toData(object)));
});
}
use of com.hazelcast.internal.partition.IPartitionService in project hazelcast by hazelcast.
the class ScheduledExecutorServiceProxy method accumulateTaskHandlersAsScheduledFutures.
@SuppressWarnings("unchecked")
private <V> void accumulateTaskHandlersAsScheduledFutures(Map<Member, List<IScheduledFuture<V>>> accumulator, Map<?, ?> taskHandlersMap) {
ClusterService clusterService = getNodeEngine().getClusterService();
IPartitionService partitionService = getNodeEngine().getPartitionService();
for (Map.Entry<?, ?> entry : taskHandlersMap.entrySet()) {
Member owner;
Object key = entry.getKey();
if (key instanceof Number) {
owner = clusterService.getMember(partitionService.getPartitionOwner((Integer) key));
} else {
owner = (Member) key;
}
List<ScheduledTaskHandler> handlers = (List<ScheduledTaskHandler>) entry.getValue();
List<IScheduledFuture<V>> futures = new ArrayList<>();
for (ScheduledTaskHandler handler : handlers) {
IScheduledFuture future = new ScheduledFutureProxy(handler, this);
futures.add(initializeManagedContext(future));
}
if (accumulator.containsKey(owner)) {
List<IScheduledFuture<V>> memberFutures = accumulator.get(owner);
memberFutures.addAll(futures);
} else {
accumulator.put(owner, futures);
}
}
}
use of com.hazelcast.internal.partition.IPartitionService in project hazelcast by hazelcast.
the class MapExecuteOnKeysMessageTask method getPartitions.
@Override
public PartitionIdSet getPartitions() {
IPartitionService partitionService = nodeEngine.getPartitionService();
int partitions = partitionService.getPartitionCount();
PartitionIdSet partitionIds = new PartitionIdSet(partitions);
Iterator<Data> iterator = parameters.keys.iterator();
int addedPartitions = 0;
while (iterator.hasNext() && addedPartitions < partitions) {
Data key = iterator.next();
if (partitionIds.add(partitionService.getPartitionId(key))) {
addedPartitions++;
}
}
return partitionIds;
}
Aggregations