Skip to content

[core] Validate watermark-based tag names before publishing snapshots - #11302

Open
taoran92 wants to merge 3 commits into
apache:masterfrom
taoran92:fix/automatic-tag-watermark-11301
Open

taoran92 wants to merge 3 commits into
apache:masterfrom
taoran92:fix/automatic-tag-watermark-11301

Conversation

@taoran92

@taoran92 taoran92 commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Fixes #11301.

Purpose

With tag.automatic-creation=watermark, a Flink batch write that supplies epoch microseconds to end-input.watermark can produce an hourly tag in year 56664. The snapshot is published before tag creation fails, and later writes inherit its watermark even when they supply valid epoch milliseconds.

Changes

  • Validate an advancing watermark before publishing its snapshot, using the configured tag period, time zone, and creation delay. Preserve the actual tag year when aligning extreme timestamps.
  • With automatic completion, check the delayed boundary even when the next missing tag is printable. Account for the minute precision of custom-period tag names when restoring progress.
  • For write-only writers with a separate tag maintainer, check the immediate boundary for the first usable watermark, including after an unset watermark. Once tag progress exists, the creation delay can make the preceding year's tag valid.
  • Document epoch milliseconds as the unit for Flink's end-input.watermark.

Tests

Core tests cover rejection before publication, recovery on the next valid write, and period alignment at extreme timestamps. Flink 1.20.3 batch SQL also verified that a rejected write preserves the snapshot and tags and that the next valid write can create its hourly tag.

@taoran92
taoran92 marked this pull request as ready for review November 20, 2026 11:55
@taoran92
taoran92 force-pushed the fix/automatic-tag-watermark-11301 branch from 2a5a535 to bb0f4fe Compare November 20, 2026 12:57
@taoran92 taoran92 changed the title [core] A microsecond end-input.watermark can cause automatic tag creation to fail on later writes [core] Validate watermark-based tag names before publishing snapshots Nov 20, 2026

@JingsongLi JingsongLi 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.

The primary fix has end-to-end value. All 27 Core tag tests and four existing Flink 1.20.1 watermark tests passed locally. An additional Flink SQL case confirmed that the default writer rejects the invalid first watermark before publishing a snapshot and creates the expected tag on the next valid write. Two supported configurations still reproduce the poisoned watermark in Flink SQL.

@taoran92
taoran92 force-pushed the fix/automatic-tag-watermark-11301 branch 2 times, most recently from 9dc3f15 to 6cd7c55 Compare November 20, 2026 16:46
@taoran92
taoran92 force-pushed the fix/automatic-tag-watermark-11301 branch from 6cd7c55 to 42eeb06 Compare November 21, 2026 03:58
@taoran92

Copy link
Copy Markdown
Member Author

@JingsongLi CI is green and comments are addressed. Another look when you have a chance? Thanks!

@JingsongLi JingsongLi 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.

The two previous cases pass on this revision. All 46 cases in TagAutoManagerTest and TagPeriodHandlerTest passed locally.

Comment on lines +177 to +180
tagPeriodHandler.timeToTag(firstTag);
if (!firstTag.equals(delayedTag)) {
tagPeriodHandler.timeToTag(delayedTag);
}

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.

[P2] Validate the completion tag due after a restart. With UTC, tag.creation-period-duration=70 s, and tag.automatic-completion=true, I committed watermark 253402300830000 and got tag 999912312359. I then reopened the committer and committed 253402300880000. The watermark-derived boundary still falls in year 9999, so validation passes and snapshot 2 is published. Restoring progress from the minute-precision tag name makes +10000-01-01T00:00:10 the next tag, and that tag is due at snapshot 2. Maintenance throws a DateTimeException and remains stuck on that snapshot. Please validate the tag due under the restored completion progress before publishing the snapshot.

Comment on lines +187 to +191
if (latestSnapshot != null && !exceedsTagRange) {
if (creation == null) {
if (options.writeOnly()) {
// A dedicated creator can remember tags that have already expired.
return;

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.

[P2] Validate the first usable watermark for write-only writers. With hourly UTC tags, a 15-minute creation delay, and write-only=true, I committed Long.MIN_VALUE and then 253402304700000 to a table with no tags. The delayed boundary is printable, so this branch accepts the write. The separate maintainer creates its first tag from the immediate boundary and throws a DateTimeException for year 10000. A later write with a valid 2024 watermark still inherits the larger value. This branch can also let an extreme negative watermark wrap into a bogus future tag. Please require evidence of existing tag progress before allowing this fallback. When that progress is unknown, validate the immediate first-tag boundary.

@taoran92
taoran92 force-pushed the fix/automatic-tag-watermark-11301 branch from 9ceffaf to 5aeb6fa Compare November 23, 2026 03:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] An out-of-range tag year can prevent automatic tag creation on later writes

2 participants