Skip to content

RUBY-3712 Expose atClusterTime in snapshot sessions#3035

Merged
comandeo-mongo merged 1 commit intomongodb:masterfrom
comandeo-mongo:3712
May 4, 2026
Merged

RUBY-3712 Expose atClusterTime in snapshot sessions#3035
comandeo-mongo merged 1 commit intomongodb:masterfrom
comandeo-mongo:3712

Conversation

@comandeo-mongo
Copy link
Copy Markdown
Contributor

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_timestamp is now public and returns the BSON::Timestamp captured for the session, or nil for 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_time requires :snapshot: true and that the value is a BSON::Timestamp.
  • The writer is idempotent (@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 in executable.rb.
  • Unified test runner: added getSnapshotTime operation handler and entity-reference resolution for snapshotTime in sessionOptions, per unified-test-format.md §getSnapshotTime.
  • Refreshed snapshot-sessions.yml fixtures from the spec repo.

Test plan

  • bundle exec rubocop clean on all changed files
  • MONGODB_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
  • New unit specs cover the validation paths (:snapshot_time without :snapshot, non-Timestamp value) that aren't expressible in the unified test format
  • New YAML fixtures (Find/Distinct/Aggregate/countDocuments/Mixed with snapshot_time) all pass

Jira

RUBY-3712 (split from DRIVERS-2782)

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.
@comandeo-mongo comandeo-mongo added the feature A PR for a new feature label Apr 29, 2026
@comandeo-mongo comandeo-mongo marked this pull request as ready for review April 30, 2026 16:29
@comandeo-mongo comandeo-mongo requested a review from a team as a code owner April 30, 2026 16:29
@comandeo-mongo comandeo-mongo requested review from Copilot and jamis April 30, 2026 16:29
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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_time session option validation and initialize @snapshot_timestamp from it; make snapshot_timestamp publicly readable and the writer idempotent.
  • Unified test runner: resolve sessionOptions.snapshotTime entity references and add a getSnapshotTime operation 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 thread lib/mongo/session.rb
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
@comandeo-mongo comandeo-mongo merged commit b15712e into mongodb:master May 4, 2026
202 checks passed
@comandeo-mongo comandeo-mongo added bug and removed feature A PR for a new feature labels May 7, 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.

3 participants