-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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
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 |
---|---|---|
|
@@ -34,7 +34,7 @@ test_session_opts_clone (void) | |
|
||
opts = mongoc_session_opts_new (); | ||
clone = mongoc_session_opts_clone (opts); | ||
/* causal is enabled by default */ | ||
/* causalConsistency is enabled by default if snapshot is not enabled */ | ||
BSON_ASSERT (mongoc_session_opts_get_causal_consistency (clone)); | ||
mongoc_session_opts_destroy (clone); | ||
|
||
|
@@ -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 commentThe 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. |
||
{ | ||
mongoc_session_opt_t *opts; | ||
|
||
opts = mongoc_session_opts_new (); | ||
/* causalConsistency is enabled by default if snapshot is not enabled */ | ||
BSON_ASSERT (mongoc_session_opts_get_causal_consistency (opts)); | ||
BSON_ASSERT (!mongoc_session_opts_get_snapshot (opts)); | ||
|
||
/* causalConsistency is disabled by default if snapshot is enabled */ | ||
mongoc_session_opts_set_snapshot (opts, true); | ||
BSON_ASSERT (!mongoc_session_opts_get_causal_consistency (opts)); | ||
BSON_ASSERT (mongoc_session_opts_get_snapshot (opts)); | ||
|
||
/* causalConsistency and snapshot can both be enabled, although this will | ||
* result in an error when starting the session. */ | ||
mongoc_session_opts_set_causal_consistency (opts, true); | ||
BSON_ASSERT (mongoc_session_opts_get_causal_consistency (opts)); | ||
BSON_ASSERT (mongoc_session_opts_get_snapshot (opts)); | ||
|
||
mongoc_session_opts_destroy (opts); | ||
} | ||
|
||
|
||
static void | ||
test_session_no_crypto (void *ctx) | ||
{ | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for moving this test. |
||
{ | ||
mongoc_client_t *client = NULL; | ||
mongoc_session_opt_t *session_opts = NULL; | ||
bson_error_t error; | ||
bool r; | ||
|
||
client = test_framework_new_default_client (); | ||
BSON_ASSERT (client); | ||
|
||
session_opts = mongoc_session_opts_new (); | ||
mongoc_session_opts_set_causal_consistency (session_opts, true); | ||
mongoc_session_opts_set_snapshot (session_opts, true); | ||
|
||
/* assert that starting session with causal consistency and snapshot enabled | ||
* results in an error. */ | ||
r = mongoc_client_start_session (client, session_opts, &error); | ||
ASSERT (!r); | ||
ASSERT_ERROR_CONTAINS ( | ||
error, | ||
MONGOC_ERROR_CLIENT, | ||
MONGOC_ERROR_CLIENT_SESSION_FAILURE, | ||
"Only one of causal consistency and snapshot can be enabled."); | ||
|
||
mongoc_session_opts_destroy (session_opts); | ||
mongoc_client_destroy (client); | ||
} | ||
|
||
void | ||
test_session_install (TestSuite *suite) | ||
{ | ||
char resolved[PATH_MAX]; | ||
|
||
TestSuite_Add (suite, "/Session/opts/clone", test_session_opts_clone); | ||
TestSuite_Add (suite, | ||
"/Session/opts/causal_consistency_and_snapshot", | ||
test_session_opts_causal_consistency_and_snapshot); | ||
TestSuite_AddFull (suite, | ||
"/Session/no_crypto", | ||
test_session_no_crypto, | ||
|
@@ -3079,4 +3136,12 @@ test_session_install (TestSuite *suite) | |
test_framework_skip_if_no_failpoint, | ||
/* Tests with retryable writes, requires non-standalone. */ | ||
test_framework_skip_if_single); | ||
|
||
TestSuite_AddFull (suite, | ||
"/Session/snapshot/prose_test_1", | ||
test_sessions_snapshot_prose_test_1, | ||
NULL, | ||
NULL, | ||
test_framework_skip_if_no_sessions, | ||
test_framework_skip_if_no_crypto); | ||
} |
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
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
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.
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 introducemongoc_optional_bool_t
alongsidemongoc_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
.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
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
andsnapshot
. 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.