private void setTimer(WindowedValue timerElement, TimerInternals.TimerData timerData) { try { currentTimerKey = keySelector.getKey(timerElement); timerInternals.setTimer(timerData); } catch (Exception e) { throw new RuntimeException("Couldn't set timer", e); } finally { currentTimerKey = null; } }
/** Clear any remaining holds. */ public void clearHolds(ReduceFn<?, ?, ?, W>.Context context) { WindowTracing.debug( "WatermarkHold.clearHolds: For key:{}; window:{}; inputWatermark:{}; outputWatermark:{}", context.key(), context.window(), timerInternals.currentInputWatermarkTime(), timerInternals.currentOutputWatermarkTime()); context.state().access(elementHoldTag).clear(); context.state().access(EXTRA_HOLD_TAG).clear(); }
when(mockTimerInternals.currentInputWatermarkTime()).thenReturn(currentTime); .setTimer( StateNamespaces.window(new GlobalWindows().windowCoder(), GlobalWindow.INSTANCE), DoFnWithTimers.TIMER_ID,
@Override public Instant currentInputWatermarkTime() { return timerInternals.currentInputWatermarkTime(); }
timerInternals.currentProcessingTime().plus(result.getContinuation().resumeDelay()); holdState.add(futureOutputWatermark); timerInternals.setTimer( TimerInternals.TimerData.of(stateNamespace, wakeupTime, TimeDomain.PROCESSING_TIME));
/** Is {@code window} expired w.r.t. the garbage collection watermark? */ private boolean canDropDueToExpiredWindow(BoundedWindow window) { Instant inputWM = timerInternals.currentInputWatermarkTime(); return LateDataUtils.garbageCollectionTime(window, windowingStrategy).isBefore(inputWM); } }
key, window, timerInternals.currentInputWatermarkTime(), timerInternals.currentOutputWatermarkTime());
@Override public void onTimer( String timerId, BoundedWindow window, Instant timestamp, TimeDomain timeDomain) { // The effective timestamp is when derived elements will have their timestamp set, if not // otherwise specified. If this is an event time timer, then they have the timestamp of the // timer itself. Otherwise, they are set to the input timestamp, which is by definition // non-late. Instant effectiveTimestamp; switch (timeDomain) { case EVENT_TIME: effectiveTimestamp = timestamp; break; case PROCESSING_TIME: case SYNCHRONIZED_PROCESSING_TIME: effectiveTimestamp = stepContext.timerInternals().currentInputWatermarkTime(); break; default: throw new IllegalArgumentException(String.format("Unknown time domain: %s", timeDomain)); } OnTimerArgumentProvider argumentProvider = new OnTimerArgumentProvider(window, effectiveTimestamp, timeDomain); invoker.invokeOnTimer(timerId, argumentProvider); }
@Override public void setForWindow(BoundedWindow window) { Instant gcTime = LateDataUtils.garbageCollectionTime(window, windowingStrategy); // make sure this fires after any window.maxTimestamp() timers gcTime = gcTime.plus(GC_DELAY_MS); timerInternals.setTimer( StateNamespaces.window(windowCoder, window), GC_TIMER_ID, gcTime, TimeDomain.EVENT_TIME); }
/** * Schedule a timer to garbage collect the window. * * <p>The timer: * * <ul> * <li>...must be fired strictly after the expiration of the window. * <li>...should be as close to the expiration as possible, to have a timely output of remaining * buffered data, and GC. * </ul> */ private void scheduleGarbageCollectionTimer(ReduceFn<?, ?, ?, W>.Context directContext) { Instant inputWM = timerInternals.currentInputWatermarkTime(); Instant gcTime = LateDataUtils.garbageCollectionTime(directContext.window(), windowingStrategy); WindowTracing.trace( "ReduceFnRunner.scheduleGarbageCollectionTimer: Scheduling at {} for " + "key:{}; window:{} where inputWatermark:{}; outputWatermark:{}", gcTime, key, directContext.window(), inputWM, timerInternals.currentOutputWatermarkTime()); checkState( !gcTime.isAfter(BoundedWindow.TIMESTAMP_MAX_VALUE), "Timer %s is beyond end-of-time", gcTime); directContext.timers().setTimer(gcTime, TimeDomain.EVENT_TIME); }
private boolean windowIsExpired(BoundedWindow w) { return timerInternals .currentInputWatermarkTime() .isAfter(w.maxTimestamp().plus(windowingStrategy.getAllowedLateness())); } }
private void cancelEndOfWindowAndGarbageCollectionTimers( ReduceFn<?, ?, ?, W>.Context directContext) { WindowTracing.debug( "ReduceFnRunner.cancelEndOfWindowAndGarbageCollectionTimers: Deleting timers for " + "key:{}; window:{} where inputWatermark:{}; outputWatermark:{}", key, directContext.window(), timerInternals.currentInputWatermarkTime(), timerInternals.currentOutputWatermarkTime()); Instant eow = directContext.window().maxTimestamp(); directContext.timers().deleteTimer(eow, TimeDomain.EVENT_TIME); Instant gc = LateDataUtils.garbageCollectionTime(directContext.window(), windowingStrategy); if (gc.isAfter(eow)) { directContext.timers().deleteTimer(gc, TimeDomain.EVENT_TIME); } }
.maxTimestamp() .plus(windowingStrategy.getAllowedLateness()) .isBefore(timerInternals.currentInputWatermarkTime()); if (expired) { key, window, timerInternals.currentInputWatermarkTime());
context.key(), context.window(), timerInternals.currentInputWatermarkTime(), timerInternals.currentOutputWatermarkTime()); final WatermarkHoldState elementHoldState = context.state().access(elementHoldTag); final WatermarkHoldState extraHoldState = context.state().access(EXTRA_HOLD_TAG);
Instant inputWM = timerInternals.currentInputWatermarkTime(); if (newHold != null) {
window, timer, timerInternals.currentInputWatermarkTime(), timerInternals.currentOutputWatermarkTime()); key, directContext.window(), timerInternals.currentInputWatermarkTime(), timerInternals.currentOutputWatermarkTime()); key, directContext.window(), timerInternals.currentInputWatermarkTime(), timerInternals.currentOutputWatermarkTime()); if (windowActivation.windowIsActiveAndOpen() && triggerRunner.shouldFire( directContext.window(), cleanupTime, timerInternals.currentInputWatermarkTime(), timerInternals.currentOutputWatermarkTime()); checkState( !cleanupTime.isAfter(BoundedWindow.TIMESTAMP_MAX_VALUE),
MetricsContainerImpl container = new MetricsContainerImpl("any"); MetricsEnvironment.setCurrentContainer(container); when(mockTimerInternals.currentInputWatermarkTime()).thenReturn(new Instant(15L));
Instant outputWM = timerInternals.currentOutputWatermarkTime(); Instant inputWM = timerInternals.currentInputWatermarkTime();
long index = isFirst ? 0 : previousPane.getIndex() + 1; long nonSpeculativeIndex = isFirst ? 0 : previousPane.getNonSpeculativeIndex() + 1; Instant outputWM = timerInternals.currentOutputWatermarkTime(); Instant inputWM = timerInternals.currentInputWatermarkTime();
context.key(), context.window(), timerInternals.currentInputWatermarkTime(), timerInternals.currentOutputWatermarkTime()); Collection<WatermarkHoldState> sources = context.state().accessInEachMergingWindow(elementHoldTag).values();