Abacn commented on code in PR #41518:
URL: https://github.com/apache/beam/pull/41518#discussion_r4668538264
##########
sdks/java/core/src/main/java/org/apache/beam/sdk/io/FileIO.java:
##########
@@ -776,14 +865,92 @@ public void process(ProcessContext c) throws Exception {
}
}
- private static class MatchPollFn extends PollFn<String,
MatchResult.Metadata> {
+ @VisibleForTesting
+ static long ensureLastModifiedMillis(MatchResult.Metadata input) {
+ long timestamp = input.lastModifiedMillis();
+ if (0L == timestamp) {
+ throw new RuntimeException(
+ String.format(
+ "Extract file timestamp failed: got file timestamp == 0 for
%s.",
+ input.resourceId()));
+ }
+ return timestamp;
+ }
+
+ @VisibleForTesting
+ static class MatchPollFn extends PollFn<String, MatchResult.Metadata> {
+ private final @Nullable Duration timestampCursorAllowedLateness;
+
+ // Best-effort watermark tracking (not deduplication, which lives in
Watch's checkpointed
+ // restriction): remembers the greatest last-modified time seen so far
so a poll that
+ // discovers newer files holds the watermark at the filesystem clock,
while a quiet poll
+ // releases it to poll time.
+ private transient @Nullable Instant newestMtime;
+
+ MatchPollFn() {
+ this(null);
+ }
+
+ MatchPollFn(@Nullable Duration timestampCursorAllowedLateness) {
+ this.timestampCursorAllowedLateness = timestampCursorAllowedLateness;
+ }
+
+ private synchronized boolean updateNewestMtime(Instant candidate) {
+ if (newestMtime == null || candidate.isAfter(newestMtime)) {
+ newestMtime = candidate;
+ return true;
+ }
+ return false;
+ }
+
+ private static Instant saturatingMinus(Instant instant, Duration
duration) {
+ long millis;
+ try {
+ millis = Math.subtractExact(instant.getMillis(),
duration.getMillis());
+ } catch (ArithmeticException e) {
+ millis = BoundedWindow.TIMESTAMP_MIN_VALUE.getMillis();
+ }
+ return new Instant(Math.max(millis,
BoundedWindow.TIMESTAMP_MIN_VALUE.getMillis()));
+ }
+
+ @VisibleForTesting
+ KV<List<TimestampedValue<MatchResult.Metadata>>, Instant> poll(String
element, Instant now)
+ throws Exception {
+ List<MatchResult.Metadata> metadataList =
+ FileSystems.match(element, EmptyMatchTreatment.ALLOW).metadata();
+ List<TimestampedValue<MatchResult.Metadata>> outputs = new
ArrayList<>(metadataList.size());
+ if (timestampCursorAllowedLateness == null) {
+ for (MatchResult.Metadata metadata : metadataList) {
+ outputs.add(TimestampedValue.of(metadata, now));
+ }
+ return KV.of(outputs, now);
+ }
+
+ Instant newest = null;
+ for (MatchResult.Metadata metadata : metadataList) {
+ Instant mtime = new Instant(ensureLastModifiedMillis(metadata));
Review Comment:
timeStampCursor relies on last monotonic mtime for new modifications to work
- if assume just modified, it degrades to matchContinuously that emit every
time on poll (matchUpdated = false)
- keep the previous modified time: unavailable due to finite allowedLateness
any mtime not reflecting the real modification time have already break the
assumption and could cause data loss, and I think exception is justified here
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]