-
Notifications
You must be signed in to change notification settings - Fork 455
CDRIVER-4110: Default for causal_consistency depends on snapshot #838
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
Conversation
…ot=true This was originally added in d5f73e1
This prose test is defined in the sessions spec, not transactions. It also does not require the server to support transactions.
Use mongoc_optional_t for causal_consistency and snapshot session opts to track whether or not values have been set. This also removes explicitly setting causal_consistency to true in _mongoc_client_session_new, since mongoc_session_opts_get_causal_consistency now enforces the default value.
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.
LGTM!
struct _mongoc_session_opt_t { | ||
mongoc_session_flag_t flags; | ||
mongoc_optional_t causal_consistency; | ||
mongoc_optional_t snapshot; |
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.
Seems better to have these as optionals instead of on the same flag, thanks. Should the type be mongoc_optional_bool_t
or is that type name change API-breaking?
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 brought that up with @kevinAlbs in Slack last week and we concluded that the ship has sailed since mongoc_optional_t
is already in the public API (shipped with Versioned API in 1.18.0). If we end up introducing an optional int type down the line, perhaps we can deprecate the original name and introduce mongoc_optional_bool_t
alongside mongoc_optional_int_t
, but I don't think there's anything to do presently.
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.
Good catch @jmikola!
Here is my understanding.
Before snapshot reads:
mongoc_session_opts_new
setscausalConsistency=true
.
After snapshot reads:
mongoc_session_opts_new
setscausalConsistency=true
andsnapshot=false
.- Validation occurs in
mongoc_client_start_session
(i.e. both being true is an error).
The new behavior proposed in this PR:
mongoc_session_opts_new
setscausalConsistency=unset
andsnapshot=unset
- Defaults are applied in
mongoc_client_start_session
if the values are unset. Validation occurs inmongoc_client_start_session
.
Admittedly, when reviewing the snapshot reads changes, I had thought the behavior was correct since it built off of the previous behavior. I had not considered introducing an unset value for causalConsistency
and snapshot
. This seems correct.
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.
Your understanding is correct.
I think much of the confusion actually relates in some way to SPEC-936, which added the technical equivalent of legalese to state that the causalConsistency
session option doesn't get a default value (which would require modeling it as a trilean), but instead inherits some default. In practice, I think some drivers (libmongoc included) just defaulted it to true as that had a functionally equivalent effect.
@@ -47,6 +47,31 @@ test_session_opts_clone (void) | |||
} | |||
|
|||
|
|||
static void | |||
test_session_opts_causal_consistency_and_snapshot (void) |
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.
Thanks for adding this test, we now have a similar one in the Go driver.
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.
LGTM!
struct _mongoc_session_opt_t { | ||
mongoc_session_flag_t flags; | ||
mongoc_optional_t causal_consistency; | ||
mongoc_optional_t snapshot; |
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.
Good catch @jmikola!
Here is my understanding.
Before snapshot reads:
mongoc_session_opts_new
setscausalConsistency=true
.
After snapshot reads:
mongoc_session_opts_new
setscausalConsistency=true
andsnapshot=false
.- Validation occurs in
mongoc_client_start_session
(i.e. both being true is an error).
The new behavior proposed in this PR:
mongoc_session_opts_new
setscausalConsistency=unset
andsnapshot=unset
- Defaults are applied in
mongoc_client_start_session
if the values are unset. Validation occurs inmongoc_client_start_session
.
Admittedly, when reviewing the snapshot reads changes, I had thought the behavior was correct since it built off of the previous behavior. I had not considered introducing an unset value for causalConsistency
and snapshot
. This seems correct.
@@ -2707,12 +2732,44 @@ test_session_dirty (void *unused) | |||
_test_session_dirty_helper (false /* retry succceeds */); | |||
} | |||
|
|||
void | |||
test_sessions_snapshot_prose_test_1 (void *ctx) |
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.
Thank you for moving this test.
https://jira.mongodb.org/browse/CDRIVER-4110
mongoc_optional_t
inmongoc_session_opt_t
to track values forcausalConsistency
andsnapshot
options, and enforce thecausalConsistency
logic in the corresponding getter method.