Search in sources :

Example 1 with Timer

use of org.apache.beam.runners.dataflow.worker.windmill.Windmill.Timer in project beam by apache.

the class StreamingModeExecutionContext method start.

public void start(@Nullable Object key, Windmill.WorkItem work, Instant inputDataWatermark, @Nullable Instant outputDataWatermark, @Nullable Instant synchronizedProcessingTime, WindmillStateReader stateReader, StateFetcher stateFetcher, Windmill.WorkItemCommitRequest.Builder outputBuilder) {
    this.key = key;
    this.work = work;
    this.computationKey = WindmillComputationKey.create(computationId, work.getKey(), work.getShardingKey());
    this.stateFetcher = stateFetcher;
    this.outputBuilder = outputBuilder;
    this.sideInputCache.clear();
    clearSinkFullHint();
    Instant processingTime = Instant.now();
    // timers.  Otherwise a trigger could ignore the timer and orphan the window.
    for (Windmill.Timer timer : work.getTimers().getTimersList()) {
        if (timer.getType() == Windmill.Timer.Type.REALTIME) {
            Instant inferredFiringTime = WindmillTimeUtils.windmillToHarnessTimestamp(timer.getTimestamp()).plus(Duration.millis(1));
            if (inferredFiringTime.isAfter(processingTime)) {
                processingTime = inferredFiringTime;
            }
        }
    }
    Collection<? extends StepContext> stepContexts = getAllStepContexts();
    if (!stepContexts.isEmpty()) {
        // This must be only created once for the workItem as token validation will fail if the same
        // work token is reused.
        WindmillStateCache.ForKey cacheForKey = stateCache.forKey(getComputationKey(), getWork().getCacheToken(), getWorkToken());
        for (StepContext stepContext : stepContexts) {
            stepContext.start(stateReader, inputDataWatermark, processingTime, cacheForKey, outputDataWatermark, synchronizedProcessingTime);
        }
    }
}
Also used : StepContext(org.apache.beam.runners.dataflow.worker.StreamingModeExecutionContext.StepContext) Timer(org.apache.beam.runners.dataflow.worker.windmill.Windmill.Timer) Instant(org.joda.time.Instant) Windmill(org.apache.beam.runners.dataflow.worker.windmill.Windmill)

Aggregations

StepContext (org.apache.beam.runners.dataflow.worker.StreamingModeExecutionContext.StepContext)1 Windmill (org.apache.beam.runners.dataflow.worker.windmill.Windmill)1 Timer (org.apache.beam.runners.dataflow.worker.windmill.Windmill.Timer)1 Instant (org.joda.time.Instant)1