Search in sources :

Example 6 with ProcCtx

use of com.hazelcast.jet.impl.execution.init.Contexts.ProcCtx in project hazelcast by hazelcast.

the class ReadHadoopNewApiP method init.

@Override
protected void init(@Nonnull Context context) {
    InternalSerializationService serializationService = ((ProcCtx) context).serializationService();
    // we clone the projection of key/value if configured so because some of the
    // record-readers return the same object for `reader.getCurrentKey()`
    // and `reader.getCurrentValue()` which is mutated for each `reader.nextKeyValue()`.
    BiFunctionEx<K, V, R> projectionFn = this.projectionFn;
    if (configuration.getBoolean(COPY_ON_READ, true)) {
        BiFunctionEx<K, V, R> actualProjectionFn = projectionFn;
        projectionFn = (key, value) -> {
            R result = actualProjectionFn.apply(key, value);
            return result == null ? null : serializationService.toObject(serializationService.toData(result));
        };
    }
    traverser = new HadoopFileTraverser<>(configuration, splits, projectionFn);
}
Also used : INPUT_DIR(org.apache.hadoop.mapreduce.lib.input.FileInputFormat.INPUT_DIR) ProcCtx(com.hazelcast.jet.impl.execution.init.Contexts.ProcCtx) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService)

Example 7 with ProcCtx

use of com.hazelcast.jet.impl.execution.init.Contexts.ProcCtx in project hazelcast by hazelcast.

the class ProcessorWrapper method initContext.

protected Context initContext(Context context) {
    // and also other objects could be mocked or null, such as hazelcastInstance())
    if (context instanceof ProcCtx) {
        ProcCtx c = (ProcCtx) context;
        LoggingService loggingService = c.hazelcastInstance().getLoggingService();
        String prefix = prefix(c.jobConfig().getName(), c.jobId(), c.vertexName(), c.globalProcessorIndex());
        ILogger newLogger = prefixedLogger(loggingService.getLogger(wrapped.getClass()), prefix);
        context = new ProcCtx(c.nodeEngine(), c.jobId(), c.executionId(), c.jobConfig(), newLogger, c.vertexName(), c.localProcessorIndex(), c.globalProcessorIndex(), c.isLightJob(), c.partitionAssignment(), c.localParallelism(), c.memberIndex(), c.memberCount(), c.tempDirectories(), c.serializationService(), c.subject(), c.classLoader());
    }
    return context;
}
Also used : ProcCtx(com.hazelcast.jet.impl.execution.init.Contexts.ProcCtx) LoggingService(com.hazelcast.logging.LoggingService) ILogger(com.hazelcast.logging.ILogger)

Example 8 with ProcCtx

use of com.hazelcast.jet.impl.execution.init.Contexts.ProcCtx in project hazelcast by hazelcast.

the class ProcessorTasklet method provideDynamicMetrics.

@Override
public void provideDynamicMetrics(MetricDescriptor descriptor, MetricsCollectionContext mContext) {
    descriptor = descriptor.withTag(MetricTags.VERTEX, this.context.vertexName()).withTag(MetricTags.PROCESSOR_TYPE, this.processor.getClass().getSimpleName()).withTag(MetricTags.PROCESSOR, Integer.toString(this.context.globalProcessorIndex()));
    if (isSource) {
        descriptor = descriptor.withTag(MetricTags.SOURCE, "true");
    }
    if (outstreams.length == 0) {
        descriptor = descriptor.withTag(MetricTags.SINK, "true");
    }
    for (int i = 0; i < instreams.size(); i++) {
        MetricDescriptor descWithOrdinal = descriptor.copy().withTag(MetricTags.ORDINAL, String.valueOf(i));
        mContext.collect(descWithOrdinal, RECEIVED_COUNT, ProbeLevel.INFO, ProbeUnit.COUNT, receivedCounts.get(i));
        mContext.collect(descWithOrdinal, RECEIVED_BATCHES, ProbeLevel.INFO, ProbeUnit.COUNT, receivedBatches.get(i));
    }
    for (int i = 0; i < emittedCounts.length() - (this.context.snapshottingEnabled() ? 0 : 1); i++) {
        String ordinal = i == emittedCounts.length() - 1 ? "snapshot" : String.valueOf(i);
        MetricDescriptor descriptorWithOrdinal = descriptor.copy().withTag(MetricTags.ORDINAL, ordinal);
        mContext.collect(descriptorWithOrdinal, EMITTED_COUNT, ProbeLevel.INFO, ProbeUnit.COUNT, emittedCounts.get(i));
    }
    mContext.collect(descriptor, TOP_OBSERVED_WM, ProbeLevel.INFO, ProbeUnit.MS, watermarkCoalescer.topObservedWm());
    mContext.collect(descriptor, COALESCED_WM, ProbeLevel.INFO, ProbeUnit.MS, watermarkCoalescer.coalescedWm());
    mContext.collect(descriptor, LAST_FORWARDED_WM, ProbeLevel.INFO, ProbeUnit.MS, outbox.lastForwardedWm());
    mContext.collect(descriptor, LAST_FORWARDED_WM_LATENCY, ProbeLevel.INFO, ProbeUnit.MS, lastForwardedWmLatency());
    mContext.collect(descriptor, this);
    // collect static metrics from processor
    mContext.collect(descriptor, this.processor);
    // collect dynamic metrics from processor
    if (processor instanceof DynamicMetricsProvider) {
        ((DynamicMetricsProvider) processor).provideDynamicMetrics(descriptor.copy(), mContext);
    }
    if (context instanceof ProcCtx) {
        ((ProcCtx) context).metricsContext().provideDynamicMetrics(descriptor, mContext);
    }
}
Also used : MetricDescriptor(com.hazelcast.internal.metrics.MetricDescriptor) DynamicMetricsProvider(com.hazelcast.internal.metrics.DynamicMetricsProvider) ProcCtx(com.hazelcast.jet.impl.execution.init.Contexts.ProcCtx)

Example 9 with ProcCtx

use of com.hazelcast.jet.impl.execution.init.Contexts.ProcCtx in project hazelcast-jet by hazelcast.

the class ExecutionPlan method initialize.

public void initialize(NodeEngine nodeEngine, long jobId, long executionId, SnapshotContext snapshotContext) {
    this.nodeEngine = nodeEngine;
    this.executionId = executionId;
    initProcSuppliers();
    initDag();
    this.ptionArrgmt = new PartitionArrangement(partitionOwners, nodeEngine.getThisAddress());
    JetInstance instance = getJetInstance(nodeEngine);
    for (VertexDef vertex : vertices) {
        Collection<? extends Processor> processors = createProcessors(vertex, vertex.localParallelism());
        // create StoreSnapshotTasklet and the queues to it
        QueuedPipe<Object>[] snapshotQueues = new QueuedPipe[vertex.localParallelism()];
        Arrays.setAll(snapshotQueues, i -> new OneToOneConcurrentArrayQueue<>(SNAPSHOT_QUEUE_SIZE));
        ConcurrentConveyor<Object> ssConveyor = ConcurrentConveyor.concurrentConveyor(null, snapshotQueues);
        StoreSnapshotTasklet ssTasklet = new StoreSnapshotTasklet(snapshotContext, jobId, new ConcurrentInboundEdgeStream(ssConveyor, 0, 0, lastSnapshotId, true, -1, "ssFrom:" + vertex.name()), nodeEngine, vertex.name(), vertex.isHigherPriorityUpstream());
        tasklets.add(ssTasklet);
        int localProcessorIdx = 0;
        for (Processor p : processors) {
            int globalProcessorIndex = vertex.getProcIdxOffset() + localProcessorIdx;
            String loggerName = createLoggerName(p.getClass().getName(), vertex.name(), globalProcessorIndex);
            ProcCtx context = new ProcCtx(instance, nodeEngine.getSerializationService(), nodeEngine.getLogger(loggerName), vertex.name(), globalProcessorIndex, jobConfig.getProcessingGuarantee(), vertex.localParallelism(), vertex.totalParallelism());
            String probePrefix = String.format("jet.job.%s.%s#%d", idToString(executionId), vertex.name(), localProcessorIdx);
            ((NodeEngineImpl) nodeEngine).getMetricsRegistry().scanAndRegister(p, probePrefix);
            // createOutboundEdgeStreams() populates localConveyorMap and edgeSenderConveyorMap.
            // Also populates instance fields: senderMap, receiverMap, tasklets.
            List<OutboundEdgeStream> outboundStreams = createOutboundEdgeStreams(vertex, localProcessorIdx);
            List<InboundEdgeStream> inboundStreams = createInboundEdgeStreams(vertex, localProcessorIdx);
            OutboundCollector snapshotCollector = new ConveyorCollector(ssConveyor, localProcessorIdx, null);
            ProcessorTasklet processorTasklet = new ProcessorTasklet(context, p, inboundStreams, outboundStreams, snapshotContext, snapshotCollector, jobConfig.getMaxWatermarkRetainMillis());
            tasklets.add(processorTasklet);
            this.processors.add(p);
            localProcessorIdx++;
        }
    }
    List<ReceiverTasklet> allReceivers = receiverMap.values().stream().flatMap(o -> o.values().stream()).flatMap(a -> a.values().stream()).collect(toList());
    tasklets.addAll(allReceivers);
}
Also used : Arrays(java.util.Arrays) SnapshotContext(com.hazelcast.jet.impl.execution.SnapshotContext) ConcurrentConveyor.concurrentConveyor(com.hazelcast.internal.util.concurrent.ConcurrentConveyor.concurrentConveyor) Processor(com.hazelcast.jet.core.Processor) Address(com.hazelcast.nio.Address) OutboundCollector.compositeCollector(com.hazelcast.jet.impl.execution.OutboundCollector.compositeCollector) Util.writeList(com.hazelcast.jet.impl.util.Util.writeList) Util.idToString(com.hazelcast.jet.impl.util.Util.idToString) ProcessorTasklet(com.hazelcast.jet.impl.execution.ProcessorTasklet) Collectors.toMap(java.util.stream.Collectors.toMap) ConcurrentConveyor(com.hazelcast.internal.util.concurrent.ConcurrentConveyor) Map(java.util.Map) Util.memoize(com.hazelcast.jet.impl.util.Util.memoize) ObjectDataInput(com.hazelcast.nio.ObjectDataInput) InboundEdgeStream(com.hazelcast.jet.impl.execution.InboundEdgeStream) Collection(java.util.Collection) Util.getJetInstance(com.hazelcast.jet.impl.util.Util.getJetInstance) JobConfig(com.hazelcast.jet.config.JobConfig) Set(java.util.Set) ConcurrentInboundEdgeStream(com.hazelcast.jet.impl.execution.ConcurrentInboundEdgeStream) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) Util.readList(com.hazelcast.jet.impl.util.Util.readList) List(java.util.List) DEFAULT_QUEUE_SIZE(com.hazelcast.jet.config.EdgeConfig.DEFAULT_QUEUE_SIZE) StoreSnapshotTasklet(com.hazelcast.jet.impl.execution.StoreSnapshotTasklet) ObjectDataOutput(com.hazelcast.nio.ObjectDataOutput) IntStream(java.util.stream.IntStream) IdentifiedDataSerializable(com.hazelcast.nio.serialization.IdentifiedDataSerializable) JetInstance(com.hazelcast.jet.JetInstance) OutboundEdgeStream(com.hazelcast.jet.impl.execution.OutboundEdgeStream) RoutingPolicy(com.hazelcast.jet.core.Edge.RoutingPolicy) SenderTasklet(com.hazelcast.jet.impl.execution.SenderTasklet) HashMap(java.util.HashMap) Supplier(java.util.function.Supplier) ProcSupplierCtx(com.hazelcast.jet.impl.execution.init.Contexts.ProcSupplierCtx) ArrayList(java.util.ArrayList) JetException(com.hazelcast.jet.JetException) ConveyorCollector(com.hazelcast.jet.impl.execution.ConveyorCollector) ReceiverTasklet(com.hazelcast.jet.impl.execution.ReceiverTasklet) ILogger(com.hazelcast.logging.ILogger) ProcessorSupplier(com.hazelcast.jet.core.ProcessorSupplier) QueuedPipe(com.hazelcast.internal.util.concurrent.QueuedPipe) JetConfig(com.hazelcast.jet.config.JetConfig) NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) OneToOneConcurrentArrayQueue(com.hazelcast.internal.util.concurrent.OneToOneConcurrentArrayQueue) Tasklet(com.hazelcast.jet.impl.execution.Tasklet) ProcCtx(com.hazelcast.jet.impl.execution.init.Contexts.ProcCtx) IPartitionService(com.hazelcast.spi.partition.IPartitionService) IOException(java.io.IOException) NodeEngine(com.hazelcast.spi.NodeEngine) ConveyorCollectorWithPartition(com.hazelcast.jet.impl.execution.ConveyorCollectorWithPartition) Collectors.toList(java.util.stream.Collectors.toList) OutboundCollector(com.hazelcast.jet.impl.execution.OutboundCollector) JetService(com.hazelcast.jet.impl.JetService) ProcessingGuarantee(com.hazelcast.jet.config.ProcessingGuarantee) Processor(com.hazelcast.jet.core.Processor) OutboundCollector(com.hazelcast.jet.impl.execution.OutboundCollector) Util.idToString(com.hazelcast.jet.impl.util.Util.idToString) ConcurrentInboundEdgeStream(com.hazelcast.jet.impl.execution.ConcurrentInboundEdgeStream) ConveyorCollector(com.hazelcast.jet.impl.execution.ConveyorCollector) ProcCtx(com.hazelcast.jet.impl.execution.init.Contexts.ProcCtx) InboundEdgeStream(com.hazelcast.jet.impl.execution.InboundEdgeStream) ConcurrentInboundEdgeStream(com.hazelcast.jet.impl.execution.ConcurrentInboundEdgeStream) StoreSnapshotTasklet(com.hazelcast.jet.impl.execution.StoreSnapshotTasklet) ProcessorTasklet(com.hazelcast.jet.impl.execution.ProcessorTasklet) Util.getJetInstance(com.hazelcast.jet.impl.util.Util.getJetInstance) JetInstance(com.hazelcast.jet.JetInstance) OutboundEdgeStream(com.hazelcast.jet.impl.execution.OutboundEdgeStream) ReceiverTasklet(com.hazelcast.jet.impl.execution.ReceiverTasklet) QueuedPipe(com.hazelcast.internal.util.concurrent.QueuedPipe)

Example 10 with ProcCtx

use of com.hazelcast.jet.impl.execution.init.Contexts.ProcCtx in project hazelcast-jet by hazelcast.

the class ProcessorTaskletTest method setUp.

@Before
public void setUp() {
    this.mockInput = IntStream.range(0, MOCK_INPUT_SIZE).boxed().collect(toList());
    this.processor = new PassThroughProcessor();
    this.context = new ProcCtx(null, new DefaultSerializationServiceBuilder().build(), null, null, 0, NONE, 1, 1);
    this.instreams = new ArrayList<>();
    this.outstreams = new ArrayList<>();
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) ProcCtx(com.hazelcast.jet.impl.execution.init.Contexts.ProcCtx) Before(org.junit.Before)

Aggregations

ProcCtx (com.hazelcast.jet.impl.execution.init.Contexts.ProcCtx)10 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)4 ILogger (com.hazelcast.logging.ILogger)4 Before (org.junit.Before)3 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)2 ConcurrentConveyor (com.hazelcast.internal.util.concurrent.ConcurrentConveyor)2 ConcurrentConveyor.concurrentConveyor (com.hazelcast.internal.util.concurrent.ConcurrentConveyor.concurrentConveyor)2 OneToOneConcurrentArrayQueue (com.hazelcast.internal.util.concurrent.OneToOneConcurrentArrayQueue)2 QueuedPipe (com.hazelcast.internal.util.concurrent.QueuedPipe)2 JetException (com.hazelcast.jet.JetException)2 DEFAULT_QUEUE_SIZE (com.hazelcast.jet.config.EdgeConfig.DEFAULT_QUEUE_SIZE)2 JetConfig (com.hazelcast.jet.config.JetConfig)2 JobConfig (com.hazelcast.jet.config.JobConfig)2 ProcessingGuarantee (com.hazelcast.jet.config.ProcessingGuarantee)2 RoutingPolicy (com.hazelcast.jet.core.Edge.RoutingPolicy)2 Processor (com.hazelcast.jet.core.Processor)2 ProcessorSupplier (com.hazelcast.jet.core.ProcessorSupplier)2 ConcurrentInboundEdgeStream (com.hazelcast.jet.impl.execution.ConcurrentInboundEdgeStream)2 ConveyorCollector (com.hazelcast.jet.impl.execution.ConveyorCollector)2 ConveyorCollectorWithPartition (com.hazelcast.jet.impl.execution.ConveyorCollectorWithPartition)2