Skip to content

Commit 882b608

Browse files
authored
Merge pull request #21944 from [cherry-pick][release-2.40.0][21941] Fix no output timestamp case
[cherry-pick][release-2.40.0][21941] Fix no output timestamp case
2 parents 6afcb5b + c85af81 commit 882b608

1 file changed

Lines changed: 19 additions & 2 deletions

File tree

runners/google-cloud-dataflow-java/worker/src/main/java/org/apache/beam/runners/dataflow/worker/WindmillTimerInternals.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@
5353
"nullness" // TODO(https://github.com/apache/beam/issues/20497)
5454
})
5555
class WindmillTimerInternals implements TimerInternals {
56+
private static final Instant OUTPUT_TIMESTAMP_MAX_WINDMILL_VALUE =
57+
GlobalWindow.INSTANCE.maxTimestamp().plus(Duration.millis(1));
58+
59+
private static final Instant OUTPUT_TIMESTAMP_MAX_VALUE =
60+
BoundedWindow.TIMESTAMP_MAX_VALUE.plus(Duration.millis(1));
5661

5762
private static final String TIMER_HOLD_PREFIX = "/h";
5863
// Map from timer id to its TimerData. If it is to be deleted, we still need
@@ -286,8 +291,14 @@ static Timer.Builder buildWindmillTimerFromTimerData(
286291
builder.setTimestamp(WindmillTimeUtils.harnessToWindmillTimestamp(timerData.getTimestamp()));
287292

288293
// Store the output timestamp in the metadata timestamp.
289-
builder.setMetadataTimestamp(
290-
WindmillTimeUtils.harnessToWindmillTimestamp(timerData.getOutputTimestamp()));
294+
Instant outputTimestamp = timerData.getOutputTimestamp();
295+
if (outputTimestamp.isAfter(BoundedWindow.TIMESTAMP_MAX_VALUE)) {
296+
// We can't encode any value larger than BoundedWindow.TIMESTAMP_MAX_VALUE, so use the end of
297+
// the global window
298+
// here instead.
299+
outputTimestamp = OUTPUT_TIMESTAMP_MAX_WINDMILL_VALUE;
300+
}
301+
builder.setMetadataTimestamp(WindmillTimeUtils.harnessToWindmillTimestamp(outputTimestamp));
291302
return builder;
292303
}
293304

@@ -375,7 +386,13 @@ public static TimerData windmillTimerToTimerData(
375386
throw new RuntimeException(e);
376387
}
377388
} else if (timer.hasMetadataTimestamp()) {
389+
// We use BoundedWindow.TIMESTAMP_MAX_VALUE+1 to indicate "no output timestamp" so make sure
390+
// to change the upper
391+
// bound.
378392
outputTimestamp = WindmillTimeUtils.windmillToHarnessTimestamp(timer.getMetadataTimestamp());
393+
if (outputTimestamp.equals(OUTPUT_TIMESTAMP_MAX_WINDMILL_VALUE)) {
394+
outputTimestamp = OUTPUT_TIMESTAMP_MAX_VALUE;
395+
}
379396
}
380397

381398
StateNamespace namespace = StateNamespaces.fromString(namespaceString, windowCoder);

0 commit comments

Comments
 (0)