Skip to content

Support withTimestampCursor for Java FileIO.matchContinuously - #41518

Open
Abacn wants to merge 4 commits into
apache:masterfrom
Abacn:fileio-timestamp-cursor
Open

Abacn wants to merge 4 commits into
apache:masterfrom
Abacn:fileio-timestamp-cursor

Conversation

@Abacn

@Abacn Abacn commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Port #39461 to Java

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📋 Review Summary

This PR ports withTimestampCursor() and withTimestampCursor(Duration) from Python (#39461) to Java's FileIO.MatchConfiguration, FileIO.Match, and FileIO.MatchAll, wiring continuous file matching into Watch.Growth.withTimestampCursor with event-time watermarking based on file modification times. The implementation and end-to-end tests are well structured, with a couple of issues to address around unused test imports and per-filepattern watermark tracking in MatchPollFn.

🔍 General Feedback

  • FileIOTest.java includes five unused imports (hasDisplayItem, not, assertNull, assertThrows, DisplayData) that will cause Checkstyle/Spotless checks to fail; it looks like a unit test for MatchConfiguration.withTimestampCursor validation and DisplayData was either omitted or removed.
  • In FileIO.MatchAll.MatchPollFn, newestMtime is stored as a single field on the PollFn instance rather than keyed by the watched filepattern element, which can cause cross-pattern interference when FileIO.matchAll() watches multiple filepatterns.

💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.

@github-actions github-actions Bot added java core size/m M: 50-249 lines changed labels Nov 20, 2026
@Abacn
Abacn force-pushed the fileio-timestamp-cursor branch from 9a34f2b to 8f7d086 Compare November 20, 2026 18:10
@Abacn

Abacn commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

Tested in Dataflow job 2026-11-20_10_33_52-14158542678150362827 watch two paths with timeStampCursor enabled, work as intended

@github-actions

Copy link
Copy Markdown
Contributor

Assigning reviewers:

R: @damccorm for label java.
Backup reviewer: kennknowles (if the main reviewer is unresponsive, you can escalate to them by tagging their username)

This pull request likely touches a core component ("core" label). Please review with scrutiny.

Note: If you would like to opt out of this review, comment assign to next reviewer.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

The PR bot will only process comments in the main thread (not review comments).

@codecov

codecov Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 57.99%. Comparing base (5341c0f) to head (689076b).
⚠️ Report is 56 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##             master   #41518   +/-   ##
=========================================
  Coverage     57.99%   57.99%           
  Complexity     2831     2831           
=========================================
  Files          1209     1209           
  Lines        173011   173011           
  Branches       2320     2320           
=========================================
  Hits         100334   100334           
  Misses        69968    69968           
  Partials       2709     2709           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.


Instant newest = null;
for (MatchResult.Metadata metadata : metadataList) {
Instant mtime = new Instant(ensureLastModifiedMillis(metadata));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of throwing an exception is there some conservative behavior we can take, like assuming it was just modified? or keep the previous modified time for the file?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

// takes the poll time so a quiet directory does not stall downstream event-time windows.
boolean foundNewer = newest != null && updateNewestMtime(newest);
Instant baseWatermark =
(foundNewer && newest != null && newest.isBefore(now)) ? newest : now;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we additionally delay the watermark some to account for possible skew between local times and the file system times? getting it wrong could lead to data-loss if late data is not handled by the pipeline.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree and in general, inconsistency of element timestamp and worker clock always exists in Beam

Regardless of this situation, now set poll watermark delta to now - max(pollInterval, allowedLateness) (previously was now - allowedLateness) which defaults to now

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, this will make new element watermark too conservative such that it's delayed by pollInterval. Now use an "idleWatermarkDelta" that tracks the case when no new elements in:

  • if there are new elements, watermark = newest - allowedLateness

  • if no new element, watermark = now - idleWatermarkDelta = now - max(pollInterval, allowedLateness)

Because poll happens with interval pollInterval, this still guarantees non-decreasing watermark while a poll has new element, then subsequent poll doesn't

@damccorm

Copy link
Copy Markdown
Contributor

R: @scwhittle (keeping sticky)

@github-actions

Copy link
Copy Markdown
Contributor

Stopping reviewer notifications for this pull request: review requested by someone other than the bot, ceding control. If you'd like to restart, comment assign set of reviewers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants