Skip to content

Commit

Permalink
[FLINK-20443][API/DataStream] ContinuousEventTimeTrigger optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
hililiwei authored and AHeise committed Nov 1, 2021
1 parent a7e1526 commit 3b163c7
Showing 1 changed file with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,10 @@ public TriggerResult onElement(Object element, long timestamp, W window, Trigger
ctx.registerEventTimeTimer(window.maxTimestamp());
}

ReducingState<Long> fireTimestamp = ctx.getPartitionedState(stateDesc);
if (fireTimestamp.get() == null) {
long start = timestamp - (timestamp % interval);
long nextFireTimestamp = start + interval;
ctx.registerEventTimeTimer(nextFireTimestamp);
fireTimestamp.add(nextFireTimestamp);
ReducingState<Long> fireTimestampState = ctx.getPartitionedState(stateDesc);
if (fireTimestampState.get() == null) {
registerNextFireTimestamp(
timestamp - (timestamp % interval), window, ctx, fireTimestampState);
}

return TriggerResult.CONTINUE;
Expand All @@ -83,8 +81,7 @@ public TriggerResult onEventTime(long time, W window, TriggerContext ctx) throws

if (fireTimestamp != null && fireTimestamp == time) {
fireTimestampState.clear();
fireTimestampState.add(time + interval);
ctx.registerEventTimeTimer(time + interval);
registerNextFireTimestamp(time, window, ctx, fireTimestampState);
return TriggerResult.FIRE;
}

Expand Down Expand Up @@ -149,4 +146,12 @@ public Long reduce(Long value1, Long value2) throws Exception {
return Math.min(value1, value2);
}
}

private void registerNextFireTimestamp(
long time, W window, TriggerContext ctx, ReducingState<Long> fireTimestampState)
throws Exception {
long nextFireTimestamp = Math.min(time + interval, window.maxTimestamp());
fireTimestampState.add(nextFireTimestamp);
ctx.registerEventTimeTimer(nextFireTimestamp);
}
}

0 comments on commit 3b163c7

Please sign in to comment.