Skip to content

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 3 commits into from
Aug 4, 2021

Conversation

jmikola
Copy link
Member

@jmikola jmikola commented Jul 30, 2021

https://jira.mongodb.org/browse/CDRIVER-4110

  • Removes a work-around from the unified test runner originally introduced in d5f73e1.
  • Relocates the snapshot prose test, since it's part of the session spec (not transactions)
  • Use mongoc_optional_t in mongoc_session_opt_t to track values for causalConsistency and snapshot options, and enforce the causalConsistency logic in the corresponding getter method.

jmikola added 3 commits July 30, 2021 09:26
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.
Copy link
Contributor

@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.

LGTM!

struct _mongoc_session_opt_t {
mongoc_session_flag_t flags;
mongoc_optional_t causal_consistency;
mongoc_optional_t snapshot;
Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Collaborator

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 sets causalConsistency=true.

After snapshot reads:

  • mongoc_session_opts_new sets causalConsistency=true and snapshot=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 sets causalConsistency=unset and snapshot=unset
  • Defaults are applied in mongoc_client_start_session if the values are unset. Validation occurs in mongoc_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.

Copy link
Member Author

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)
Copy link
Contributor

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.

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.

LGTM!

struct _mongoc_session_opt_t {
mongoc_session_flag_t flags;
mongoc_optional_t causal_consistency;
mongoc_optional_t snapshot;
Copy link
Collaborator

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 sets causalConsistency=true.

After snapshot reads:

  • mongoc_session_opts_new sets causalConsistency=true and snapshot=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 sets causalConsistency=unset and snapshot=unset
  • Defaults are applied in mongoc_client_start_session if the values are unset. Validation occurs in mongoc_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)
Copy link
Collaborator

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.

@jmikola jmikola merged commit 230369c into mongodb:master Aug 4, 2021
@jmikola jmikola deleted the cdriver-4110 branch August 4, 2021 17:36
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