Skip to content

Conversation

papafe
Copy link

@papafe papafe commented Sep 23, 2025

C# driver implementation POC: mongodb/mongo-csharp-driver#1777

TODO:

  • Update changelog.
  • Test changes in at least one language driver.
  • Test these changes against all server versions and topologies (including standalone, replica set, and sharded
    clusters).
  • Add unified tests.
  • Add prose test for validation of input.
  • Create ticket for countDocument test.
  • Add information about the new getSnapshotTime operation (for unified tests).
  • Add information about the new snapshotTime parameter of sessionOptions and that it must be retrieved from the entity map (for unified tests).
  • Check that re-doing the query operation is best course of action for unified tests to verify that the snapshotTime does not get modified again.

1. If `snapshotTime` is specified in `SessionOptions`, saving the value in a `snapshotTime` property of the
`ClientSession`.
2. If `snapshotTime` is not specified in `SessionOptions`, saving the `atClusterTime` returned by 5.0+ servers for the
first find/aggregate/distinct operation in a private `snapshotTime` property of the `ClientSession` object. Drivers
Copy link
Member

Choose a reason for hiding this comment

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

It's not a private property anymore, right?

Copy link
Author

Choose a reason for hiding this comment

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

Definitely.


In order to support snapshot reads a new property named `snapshot` is added to `SessionOptions`. Applications set
`snapshot` when starting a client session to indicate whether they want snapshot reads. All read operations performed
In order to support snapshot reads two new properties called `snapshot` and `snapshotTime` are added to
Copy link
Member

Choose a reason for hiding this comment

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

I would avoid term "new", as that properties are new just for a little bit, but we are not going to change the spec just to mark them as "not new" 😊 .

Copy link
Author

Choose a reason for hiding this comment

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

I agree with that 😁
I was trying to be consistent with the previous phrasing, but I'll fix it.

atClusterTime:
"$$exists": true

## This test seems to be wrong
Copy link
Author

@papafe papafe Sep 25, 2025

Choose a reason for hiding this comment

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

TODO create ticket


Client MUST throw an error if `snapshotTime` is set and `snapshot` is not set to true.

Note that when parsing `snapshotTime` from `sessionOptions` for
Copy link
Author

Choose a reason for hiding this comment

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

Is this a good place to describe this behaviour?

Copy link
Member

Choose a reason for hiding this comment

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

I would say we have to mention this in tests/README.md file.

Copy link
Author

Choose a reason for hiding this comment

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

Makes sense

@papafe papafe marked this pull request as ready for review September 29, 2025 15:17
@papafe papafe requested a review from a team as a code owner September 29, 2025 15:17
@papafe papafe requested review from sanych-sun and removed request for a team September 29, 2025 15:17
@papafe papafe changed the title [WIP] DRIVERS-2782 Expose snapshotTime DRIVERS-2782: Expose snapshotTime Sep 29, 2025
@sanych-sun sanych-sun requested a review from qingyang-hu October 2, 2025 18:21
Snapshot sessions tests require server of version 5.0 or higher and replica set or a sharded cluster deployment.

- `client.startSession(snapshot = false)`
- `client.snapshotTime`
Copy link
Member

Choose a reason for hiding this comment

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

it suppose to be session, right?


Snapshot sessions tests require server of version 5.0 or higher and replica set or a sharded cluster deployment.

- `client.startSession(snapshot = false)`
Copy link
Member

Choose a reason for hiding this comment

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

I would prefer to have more verbal steps:

- Start a session by calling `startSession` with `snapshot = false`.
- Try to access the session's snapshot time.
- Assert that client side error was raised.

Copy link
Author

Choose a reason for hiding this comment

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

Sure.


Client MUST throw an error if `snapshotTime` is set and `snapshot` is not set to true.

Note that when parsing `snapshotTime` from `sessionOptions` for
Copy link
Member

Choose a reason for hiding this comment

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

I would say we have to mention this in tests/README.md file.

Transactions are not allowed with snapshot sessions. Calling `session.startTransaction(options)` on a snapshot session
MUST raise an error.

Note that a new operation on session called `getSnapshotTime` must be supported for
Copy link
Member

Choose a reason for hiding this comment

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

Same here, move top tests/README.md

Copy link
Author

Choose a reason for hiding this comment

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

Done

expectResult:
- { _id: 1, x: 11 }
- { _id: 2, x: 11 }
- name: find
Copy link
Member

Choose a reason for hiding this comment

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

Why do we making find with the session2 twice, or have I missed some differences in the operations? If this is because we want to make sure snapshot time will not be changes after the first call - then it might makes sense to add comments here (same with other tests below).

Copy link
Author

Choose a reason for hiding this comment

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

Yes, that's exactly the reason. Otherwise we'll have to resolve to creating more prose tests.
I'll add comments back in all the places where I'm doing this.

expectEvents:
- client: client0
events:
- commandStartedEvent:
Copy link
Member

Choose a reason for hiding this comment

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

Why don't we expect event for insertOne operation (here and in other tests).

Copy link
Author

Choose a reason for hiding this comment

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

They are ignored in ignoreCommandMonitoringEvents inside createEntities for the client used in this whole test file. I suppose those events were ignored as they were not the focus of these tests.

@papafe papafe requested a review from sanych-sun October 3, 2025 08:49
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.

2 participants