Skip to content

CDRIVER-4034 Allow snapshot reads through sessions #807

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

Merged
merged 16 commits into from
Jul 12, 2021
Merged

CDRIVER-4034 Allow snapshot reads through sessions #807

merged 16 commits into from
Jul 12, 2021

Conversation

benjirewis
Copy link
Contributor

CDRIVER-4034

Adds MONGOC_SESSION_SNAPSHOT flag option to mongoc_session_opt_t. Setting this flag will mean:

  • The first read operation (find or aggregate) will be sent with read concern level "snapshot"
  • The server will return atClusterTime in the reply cursor
  • atClusterTime will be stored as new fields snapshot_time_timestamp and snapshot_time_increment on the mongoc_client_session_t
  • Subsequent read operations (find or aggregate) will also be sent with read concern level "snapshot" and atClusterTime set to the snapshot_time stored on the client session.

These changes will allow users to read from a single point in time (a snapshot) during a session.

Adds new at_cluster_time_timestamp and at_cluster_time_increment fields to read concern (along with getters) and a new mongoc_read_concern_set_at_cluster_time setter. Allows setting MONGOC_SESSION_SNAPSHOT with isSnapshot in the unified test runner. Syncs sessions spec tests.

@benjirewis benjirewis requested review from kevinAlbs and alcaeus June 23, 2021 18:45
@benjirewis benjirewis marked this pull request as ready for review June 23, 2021 18:45
Copy link
Member

@alcaeus alcaeus left a comment

Choose a reason for hiding this comment

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

A few comments after an initial read. Functionality looks sound, just a few minor suggestions regarding the API.

@benjirewis benjirewis requested a review from alcaeus June 24, 2021 15:30
Copy link
Collaborator

@kevinAlbs kevinAlbs left a comment

Choose a reason for hiding this comment

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

This is looking like a great start!

I have not done a line-by-line review, but I have high level questions about:

  • Can we hide the API for setting atClusterTime on a read concern?
  • Can we handle atClusterTime similarly to afterClusterTime to simplify how the read concern is appended?

Copy link
Contributor Author

@benjirewis benjirewis left a comment

Choose a reason for hiding this comment

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

Refactored slightly to append snapshot to read_concern in _mongoc_client_session_append_read_concern. This seems simpler and more accurate to me; thanks for the suggestion @kevinAlbs.

Implemented the one prose test, too (CDRIVER-4037). I had mentioned offline there may be Evergreen changes for the test to set minSnapshotHistoryWindowInSeconds on the server, but I'm unsure if this is strictly necessary.

@benjirewis benjirewis requested a review from kevinAlbs June 24, 2021 19:36
Copy link
Collaborator

@kevinAlbs kevinAlbs left a comment

Choose a reason for hiding this comment

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

I still need to review the prose test, but this is looking great. Modeling this from causal consistency seems much simpler!

Copy link
Contributor Author

@benjirewis benjirewis left a comment

Choose a reason for hiding this comment

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

Looks like the prose test no longer requires that we set minSnapshotHistoryWindowInSeconds, so it should be all set to review.

@benjirewis benjirewis requested a review from kevinAlbs June 25, 2021 16:17
MONGOC_ERROR_TRANSACTION_INVALID_STATE,
"Transactions are not supported in snapshot sessions");
ret = false;
GOTO (done);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This new error is an alteration to the spec accompanied by a new spec test "StartTransaction fails in snapshot session".

Copy link
Collaborator

@kevinAlbs kevinAlbs left a comment

Choose a reason for hiding this comment

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

Fantastic work. LGTM with a minor test tweak. Let's wait until https://github.com/mongodb/specifications/pull/1022/files/dfb2472e96e1e3f4f374eb526c5190c8282239b0..e1e0672414ff7756de2a2fb9a5d4b7ddea7c1066 is merged to merge this in case there are any spec / test changes to add.

is_snapshot =
is_read_command && mongoc_session_opts_get_snapshot (&cs->opts);
is_snapshot = is_find_aggregate_distinct &&
txn_state == MONGOC_INTERNAL_TRANSACTION_NONE &&
Copy link
Collaborator

Choose a reason for hiding this comment

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

No need to change. But IIUC, this transaction check should be unnecessary. It is impossible to start a transaction on a session with snapshot enabled.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep! Now that we explicitly error in mongoc_client_session_start_transaction when snapshot is enabled on the session, I believe this check is pointless. Removed.

Copy link
Member

@alcaeus alcaeus left a comment

Choose a reason for hiding this comment

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

LGTM besides what @kevinAlbs mentioned

@benjirewis benjirewis merged commit d5f73e1 into mongodb:master Jul 12, 2021
@benjirewis benjirewis deleted the snapshotReads.4034 branch July 12, 2021 20:56
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.

3 participants