-
Notifications
You must be signed in to change notification settings - Fork 246
DRIVERS-2782: Expose snapshotTime #1843
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
papafe
wants to merge
16
commits into
mongodb:master
Choose a base branch
from
papafe:DRIVERS-2782
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
c9b29fe
[WIP] DRIVERS-2782 Expose snapshotTime
papafe 9765387
Fixed linting
papafe 364771e
Small fixes
papafe 1d581c6
Small fixes following review.
papafe 9d1da1b
Added prose test
papafe 610dc37
Added unified tests
papafe 63a6e0d
Added improvement to tests
papafe 4c4691c
Improved text.
papafe ff0582f
Corrected linting
papafe 4fdf701
Removed comments
papafe 48b70fc
Apply suggestion from @papafe
papafe de292a6
Added test
papafe df9d40d
Corrected test.
papafe d425f2b
Corrected test
papafe e640b2e
Added comment.
papafe 2f502f0
Moved comments
papafe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,24 +63,28 @@ response. The `atClusterTime` field represents the timestamp of the read and is | |
## Specification | ||
|
||
An application requests snapshot reads by creating a `ClientSession` with options that specify that snapshot reads are | ||
desired. An application then passes the session as an argument to methods in the `MongoDatabase` and `MongoCollection` | ||
classes. Read operations (find/aggregate/distinct) performed against that session will be read from the same snapshot. | ||
desired and optionally specifying a `snapshotTime`. An application then passes the session as an argument to methods in | ||
the `MongoDatabase` and `MongoCollection` classes. Read operations (find/aggregate/distinct) performed against that | ||
session will be read from the same snapshot. | ||
|
||
## High level summary of the API changes for snapshot reads | ||
|
||
Snapshot reads are built on top of client sessions. | ||
|
||
Applications will start a new client session for snapshot reads like this: | ||
Applications will start a new client session for snapshot reads and possibly retrieve the snapshot time like this: | ||
|
||
```typescript | ||
options = new SessionOptions(snapshot = true); | ||
options = new SessionOptions(snapshot = true, snapshotTime = timestampValue); | ||
session = client.startSession(options); | ||
snapshotTime = session.snapshotTime; | ||
``` | ||
|
||
All read operations performed using this session will be read from the same snapshot. | ||
|
||
If no value is provided for `snapshot` a value of false is implied. There are no MongoDatabase, MongoClient, or | ||
MongoCollection API changes. | ||
If no value is provided for `snapshot` a value of false is implied. `snapshotTime` is an optional parameter and if not | ||
passed the snapshot time will be set internally after the first find/aggregate/distinct operation inside the session. | ||
|
||
There are no MongoDatabase, MongoClient, or MongoCollection API changes. | ||
|
||
## SessionOptions changes | ||
|
||
|
@@ -89,13 +93,15 @@ MongoCollection API changes. | |
```typescript | ||
class SessionOptions { | ||
Optional<bool> snapshot; | ||
Optional<BsonTimestamp> snapshotTime; | ||
|
||
// other options defined by other specs | ||
} | ||
``` | ||
|
||
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 | ||
`SessionOptions`. Applications set `snapshot` when starting a client session to indicate whether they want snapshot | ||
reads and optionally set `snapshotTime` to specify the desired snapshot time beforehand. All read operations performed | ||
using that client session will share the same snapshot. | ||
|
||
Each new member is documented below. | ||
|
@@ -110,8 +116,29 @@ Snapshot reads and causal consistency are mutually exclusive. Therefore if `snap | |
`causalConsistency` must be false. Client MUST throw an error if both `snapshot` and `causalConsistency` are set to | ||
true. Snapshot reads are supported on both primaries and secondaries. | ||
|
||
### snapshotTime | ||
|
||
Applications set `snapshotTime` when starting a snapshot session to specify the desired snapshot time. | ||
|
||
Note that the `snapshotTime` property is optional. The default value of this property is null. | ||
|
||
Client MUST throw an error if `snapshotTime` is set and `snapshot` is not set to true. | ||
|
||
## ClientSession changes | ||
|
||
A new readonly property called `snapshotTime` will be added to `ClientSession` that allows applications to retrieve the | ||
papafe marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
snapshot time of the session: | ||
|
||
```typescript | ||
class ClientSession { | ||
readonly Optional<BsonTimestamp> snapshotTime; | ||
|
||
// other options defined by other specs | ||
} | ||
``` | ||
|
||
Getting the value of `snapshotTime` on a non-snapshot session MUST raise an error. | ||
|
||
Transactions are not allowed with snapshot sessions. Calling `session.startTransaction(options)` on a snapshot session | ||
MUST raise an error. | ||
|
||
|
@@ -123,10 +150,12 @@ MUST raise an error. | |
|
||
There are no new server commands related to snapshot reads. Instead, snapshot reads are implemented by: | ||
|
||
1. 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 MUST save `atClusterTime` in the `ClientSession` | ||
object. | ||
2. Passing that `snapshotTime` in the `atClusterTime` field of the `readConcern` field for subsequent snapshot read | ||
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 | ||
|
||
MUST save `atClusterTime` in the `ClientSession` object. | ||
3. Passing that `snapshotTime` in the `atClusterTime` field of the `readConcern` field for subsequent snapshot read | ||
operations (i.e. find/aggregate/distinct commands). | ||
|
||
## Server Command Responses | ||
|
@@ -241,6 +270,7 @@ C# driver will provide the reference implementation. The corresponding ticket is | |
|
||
## Changelog | ||
|
||
- 2025-09-23: Exposed snapshotTime to applications. | ||
- 2024-05-08: Migrated from reStructuredText to Markdown. | ||
- 2021-06-15: Initial version. | ||
- 2021-06-28: Raise client side error on < 5.0. | ||
|
Oops, something went wrong.
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.
There was a problem hiding this comment.
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" 😊 .
There was a problem hiding this comment.
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.