RUBY-3712 Expose atClusterTime in snapshot sessions#3035
Open
comandeo-mongo wants to merge 1 commit intomongodb:masterfrom
Open
RUBY-3712 Expose atClusterTime in snapshot sessions#3035comandeo-mongo wants to merge 1 commit intomongodb:masterfrom
comandeo-mongo wants to merge 1 commit intomongodb:masterfrom
Conversation
Add a public, read-only snapshot_timestamp accessor on Mongo::Session and a :snapshot_time option to Client#start_session, so applications can both inspect and pre-seed the atClusterTime used by snapshot reads. The setter is idempotent: snapshotTime is established at most once per session, either from the option at construction or from the first server response. Update the unified test runner with a getSnapshotTime operation and entity-reference resolution for snapshotTime in sessionOptions, and refresh the YAML fixtures from the spec repo.
Contributor
There was a problem hiding this comment.
Pull request overview
Exposes snapshot session atClusterTime (“snapshot time”) through Mongo::Session#snapshot_timestamp and adds unified-test-format support for getSnapshotTime plus fixture updates to validate pre-seeding snapshot time into new snapshot sessions.
Changes:
- Add
snapshot_timesession option validation and initialize@snapshot_timestampfrom it; makesnapshot_timestamppublicly readable and the writer idempotent. - Unified test runner: resolve
sessionOptions.snapshotTimeentity references and add agetSnapshotTimeoperation handler. - Refresh snapshot sessions unified YAML fixtures to cover “pre-seeded snapshotTime” scenarios across multiple operations.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| spec/spec_tests/data/sessions_unified/snapshot-sessions.yml | Adds unified spec cases validating getSnapshotTime + snapshotTime pre-seeding behavior. |
| spec/runners/unified/test.rb | Builds session options with snapshotTime entity-reference resolution. |
| spec/runners/unified/support_operations.rb | Implements getSnapshotTime unified operation mapping. |
| spec/mongo/session_spec.rb | Adds unit tests for snapshot_time validation and timestamp exposure/idempotence. |
| lib/mongo/session.rb | Adds snapshot_time validation, stores initial snapshot timestamp, exposes snapshot_timestamp and makes writer idempotent. |
| lib/mongo/operation/shared/executable.rb | Simplifies snapshot timestamp capture to always attempt assignment for snapshot sessions. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+1301
to
+1303
| def snapshot_timestamp=(value) | ||
| @snapshot_timestamp ||= value | ||
| end |
|
|
||
| if session.snapshot? && !session.snapshot_timestamp | ||
| if session.snapshot? | ||
| session.snapshot_timestamp = result.snapshot_timestamp |
| let(:options) { { snapshot: true, snapshot_time: initial_timestamp } } | ||
|
|
||
| it 'is a no-op once a snapshot timestamp is set' do | ||
| session.snapshot_timestamp = later_timestamp |
jamis
approved these changes
Apr 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds the ability to read and pre-seed the snapshot timestamp on a snapshot session, per the snapshot-sessions spec and the unified-test-format addition for
getSnapshotTime.Changes
Mongo::Session#snapshot_timestampis now public and returns the BSON::Timestamp captured for the session, ornilfor a non-snapshot session and for snapshot sessions that haven't yet performed a read.Client#start_session(snapshot: true, snapshot_time: ts)accepts a pre-set snapshot time. Validates that:snapshot_timerequires:snapshot: trueand that the value is aBSON::Timestamp.@snapshot_timestamp ||= value), enforcing the spec's "snapshotTime must be read-only" rationale at the source of truth rather than at one call site. Removed the now-redundant guard inexecutable.rb.getSnapshotTimeoperation handler and entity-reference resolution forsnapshotTimeinsessionOptions, per unified-test-format.md §getSnapshotTime.snapshot-sessions.ymlfixtures from the spec repo.Test plan
bundle exec rubocopclean on all changed filesMONGODB_URI=... bundle exec rspec spec/spec_tests/sessions_unified_spec.rb spec/mongo/session_spec.rb spec/integration/snapshot_query_examples_spec.rb— 78 examples, 0 failures, 7 pre-existing pending:snapshot_timewithout:snapshot, non-Timestamp value) that aren't expressible in the unified test formatsnapshot_time) all passJira
RUBY-3712 (split from DRIVERS-2782)