use of com.hazelcast.cluster.Address in project hazelcast by hazelcast.
the class ExecutionPlan method initialize.
/**
* A method called on the members as part of the InitExecutionOperation.
* Creates tasklets, inboxes/outboxes and connects these to make them ready
* for a later StartExecutionOperation.
*/
public void initialize(NodeEngineImpl nodeEngine, long jobId, long executionId, @Nonnull SnapshotContext snapshotContext, ConcurrentHashMap<String, File> tempDirectories, InternalSerializationService jobSerializationService) {
this.nodeEngine = nodeEngine;
this.jobClassLoaderService = ((JetServiceBackend) nodeEngine.getService(JetServiceBackend.SERVICE_NAME)).getJobClassLoaderService();
this.executionId = executionId;
initProcSuppliers(jobId, tempDirectories, jobSerializationService);
initDag(jobSerializationService);
this.ptionArrgmt = new PartitionArrangement(partitionAssignment, nodeEngine.getThisAddress());
Set<Integer> higherPriorityVertices = VertexDef.getHigherPriorityVertices(vertices);
for (Address destAddr : remoteMembers.get()) {
Connection conn = getMemberConnection(nodeEngine, destAddr);
if (conn == null) {
throw new TopologyChangedException("no connection to job participant: " + destAddr);
}
memberConnections.put(destAddr, conn);
}
for (VertexDef vertex : vertices) {
ClassLoader processorClassLoader = isLightJob ? null : jobClassLoaderService.getProcessorClassLoader(jobId, vertex.name());
Collection<? extends Processor> processors = doWithClassLoader(processorClassLoader, () -> createProcessors(vertex, vertex.localParallelism()));
String jobPrefix = prefix(jobConfig.getName(), jobId, vertex.name());
// create StoreSnapshotTasklet and the queues to it
ConcurrentConveyor<Object> ssConveyor = null;
if (!isLightJob) {
// Note that we create the snapshot queues for all non-light jobs, even if they don't have
// processing guarantee enabled, because in EE one can request a snapshot also for
// non-snapshotted jobs.
@SuppressWarnings("unchecked") QueuedPipe<Object>[] snapshotQueues = new QueuedPipe[vertex.localParallelism()];
Arrays.setAll(snapshotQueues, i -> new OneToOneConcurrentArrayQueue<>(SNAPSHOT_QUEUE_SIZE));
ssConveyor = ConcurrentConveyor.concurrentConveyor(null, snapshotQueues);
ILogger storeSnapshotLogger = prefixedLogger(nodeEngine.getLogger(StoreSnapshotTasklet.class), jobPrefix);
StoreSnapshotTasklet ssTasklet = new StoreSnapshotTasklet(snapshotContext, ConcurrentInboundEdgeStream.create(ssConveyor, 0, 0, true, jobPrefix + "/ssFrom", null), new AsyncSnapshotWriterImpl(nodeEngine, snapshotContext, vertex.name(), memberIndex, memberCount, jobSerializationService), storeSnapshotLogger, vertex.name(), higherPriorityVertices.contains(vertex.vertexId()));
tasklets.add(ssTasklet);
}
int localProcessorIdx = 0;
for (Processor processor : processors) {
int globalProcessorIndex = memberIndex * vertex.localParallelism() + localProcessorIdx;
String processorPrefix = prefix(jobConfig.getName(), jobId, vertex.name(), globalProcessorIndex);
ILogger logger = prefixedLogger(nodeEngine.getLogger(processor.getClass()), processorPrefix);
ProcCtx context = new ProcCtx(nodeEngine, jobId, executionId, getJobConfig(), logger, vertex.name(), localProcessorIdx, globalProcessorIndex, isLightJob, partitionAssignment, vertex.localParallelism(), memberIndex, memberCount, tempDirectories, jobSerializationService, subject, processorClassLoader);
// createOutboundEdgeStreams() populates localConveyorMap and edgeSenderConveyorMap.
// Also populates instance fields: senderMap, receiverMap, tasklets.
List<OutboundEdgeStream> outboundStreams = createOutboundEdgeStreams(vertex, localProcessorIdx, jobPrefix, jobSerializationService);
List<InboundEdgeStream> inboundStreams = createInboundEdgeStreams(vertex, localProcessorIdx, jobPrefix, globalProcessorIndex);
OutboundCollector snapshotCollector = ssConveyor == null ? null : new ConveyorCollector(ssConveyor, localProcessorIdx, null);
// vertices which are only used for snapshot restore will not be marked as "source=true" in metrics
// also do not consider snapshot restore edges for determining source tag
boolean isSource = vertex.inboundEdges().stream().allMatch(EdgeDef::isSnapshotRestoreEdge) && !vertex.isSnapshotVertex();
ProcessorTasklet processorTasklet = new ProcessorTasklet(context, nodeEngine.getExecutionService().getExecutor(TASKLET_INIT_CLOSE_EXECUTOR_NAME), jobSerializationService, processor, inboundStreams, outboundStreams, snapshotContext, snapshotCollector, isSource);
tasklets.add(processorTasklet);
this.processors.add(processor);
localProcessorIdx++;
}
}
List<ReceiverTasklet> allReceivers = receiverMap.values().stream().flatMap(o -> o.values().stream()).flatMap(a -> a.values().stream()).collect(toList());
tasklets.addAll(allReceivers);
}
use of com.hazelcast.cluster.Address in project hazelcast by hazelcast.
the class ExecutionPlan method createRemoteOutboundCollectors.
private OutboundCollector[] createRemoteOutboundCollectors(EdgeDef edge, String jobPrefix, int processorIndex, int totalPartitionCount, int[][] partitionsPerProcessor, InternalSerializationService jobSerializationService) {
// the distributed-to-one edge must be partitioned and the target member must be present
if (!edge.getDistributedTo().equals(DISTRIBUTE_TO_ALL)) {
if (edge.routingPolicy() != RoutingPolicy.PARTITIONED) {
throw new JetException("An edge distributing to a specific member must be partitioned: " + edge);
}
if (!ptionArrgmt.getRemotePartitionAssignment().containsKey(edge.getDistributedTo()) && !edge.getDistributedTo().equals(nodeEngine.getThisAddress())) {
throw new JetException("The target member of an edge is not present in the cluster or is a lite member: " + edge);
}
}
Map<Address, ConcurrentConveyor<Object>> senderConveyorMap = memberToSenderConveyorMap(edgeSenderConveyorMap, edge, jobPrefix, jobSerializationService);
createIfAbsentReceiverTasklet(edge, jobPrefix, partitionsPerProcessor, totalPartitionCount, jobSerializationService);
// assign remote partitions to outbound data collectors
Address distributeTo = edge.getDistributedTo();
Map<Address, int[]> memberToPartitions = distributeTo.equals(DISTRIBUTE_TO_ALL) ? ptionArrgmt.getRemotePartitionAssignment() : ptionArrgmt.remotePartitionAssignmentToOne(distributeTo);
OutboundCollector[] remoteCollectors = new OutboundCollector[memberToPartitions.size()];
int index = 0;
for (Map.Entry<Address, int[]> entry : memberToPartitions.entrySet()) {
Address memberAddress = entry.getKey();
int[] memberPartitions = entry.getValue();
ConcurrentConveyor<Object> conveyor = senderConveyorMap.get(memberAddress);
remoteCollectors[index++] = new ConveyorCollectorWithPartition(conveyor, processorIndex, memberPartitions);
}
return remoteCollectors;
}
use of com.hazelcast.cluster.Address in project hazelcast by hazelcast.
the class TerminateExecutionOperation method run.
@Override
public void run() {
JetServiceBackend service = getJetServiceBackend();
JobExecutionService executionService = service.getJobExecutionService();
Address callerAddress = getCallerAddress();
executionService.terminateExecution(jobId(), executionId, callerAddress, mode);
}
use of com.hazelcast.cluster.Address in project hazelcast by hazelcast.
the class LocalMapStatsProvider method getReplicaAddress.
/**
* Gets replica address. Waits if necessary.
*
* @see #waitForReplicaAddress
*/
private Address getReplicaAddress(int partitionId, int replicaNumber, int backupCount) {
IPartition partition = partitionService.getPartition(partitionId);
Address replicaAddress = partition.getReplicaAddress(replicaNumber);
if (replicaAddress == null) {
replicaAddress = waitForReplicaAddress(replicaNumber, partition, backupCount);
}
return replicaAddress;
}
use of com.hazelcast.cluster.Address in project hazelcast by hazelcast.
the class LocalMapStatsProvider method waitForReplicaAddress.
/**
* Waits partition table update to get replica address if current replica address is null.
*/
private Address waitForReplicaAddress(int replica, IPartition partition, int backupCount) {
int tryCount = RETRY_COUNT;
Address replicaAddress = null;
while (replicaAddress == null && partitionService.getMaxAllowedBackupCount() >= backupCount && tryCount-- > 0) {
sleep();
replicaAddress = partition.getReplicaAddress(replica);
}
return replicaAddress;
}
Aggregations