Skip to content

[Spanner Change Stream] Use inclusive CreatedAt filter for partition discovery on split boundaries - #40887

Draft
jiangzzhu wants to merge 1 commit into
apache:masterfrom
jiangzzhu:fix-changestream-get-partitions-created-at-boundary
Draft

jiangzzhu wants to merge 1 commit into
apache:masterfrom
jiangzzhu:fix-changestream-get-partitions-created-at-boundary

Conversation

@jiangzzhu

Copy link
Copy Markdown
Contributor

Summary

  • DetectNewPartitionsDoFn tracks partition discovery over half-open TimestampRange intervals [from, to), where from is inclusive and to is exclusive (TimestampRangeTracker.tryClaim(pos) accepts from <= pos < to).
  • Previously, PartitionMetadataDao.getAllPartitionsCreatedAfter(timestamp) and PartitionMetadataDao.countPartitionsCreatedAfter(timestamp) queried Spanner using strict > (WHERE CreatedAt > @timestamp in GoogleSQL and WHERE "CreatedAt" > $1 in PostgreSQL).
  • When a runner splits [from, to) into a primary [from, T_split) and residual [T_split, to) where a partition has CreatedAt == T_split, the primary rejects T_split (tryClaim(T_split) == false) and the residual skipped T_split (CreatedAt > T_split), stranding that partition in CREATED indefinitely and stalling the watermark.
  • Fix both getAllPartitionsCreatedAfter and countPartitionsCreatedAfter (for both GoogleSQL and PostgreSQL) to use >=, and update the corresponding Javadocs.
    • Normal SDF checkpoints remain duplicate-free on the already-claimed position because TimestampRangeTracker.trySplit(0.0) advances the residual start to lastAttempted + 1ns (or leaves from unchanged if nothing was claimed), while initial startup begins at createdAt(initialPartition) - 1ns.
    • Intentionally preserves querying without a State = 'CREATED' filter so retried detector bundles continue to emit partitions whose Spanner state transition already committed in a failed bundle attempt.

Testing

  • Added unit tests in PartitionMetadataDaoTest covering getAllPartitionsCreatedAfter and countPartitionsCreatedAfter for both GoogleSQL and PostgreSQL dialects.
  • Updated mock SQL matchers in SpannerChangeStreamErrorTest.
  • Verified :sdks:java:io:google-cloud-platform:test --tests "org.apache.beam.sdk.io.gcp.spanner.changestreams.*", spotlessApply, checkstyleMain, and checkstyleTest.

Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:

  • Mention the appropriate issue in your description (for example: fixes #123), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, comment fixes #<ISSUE NUMBER> instead.
  • Update CHANGES.md with noteworthy changes.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

See the Contributor Guide for more tips on how to make review process smoother.

To check the build health, please visit https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md

GitHub Actions Tests Status (on master branch)

Build python source distribution and wheels
Python tests
Java tests
Go tests

See CI.md for more information about GitHub Actions CI or the workflows README to see a list of phrases to trigger workflows.

@github-actions github-actions Bot added java io gcp spanner size/m M: 50-249 lines changed labels Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant