Skip to content
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

[5.0.1] Disable savepoints on SQL Server when MARS is enabled #23305

Merged
merged 2 commits into from
Nov 17, 2020

Conversation

roji
Copy link
Member

@roji roji commented Nov 13, 2020

Fixes #23269

Additional context for Tactics

This is a tricky one, because it is a regression in 5.0 resulting in an exception, the root cause of which is new feature added in 5.0. We don't want to break this new feature in 5.0.1 for people who are using it successfully in 5.0.0. Therefore, we are:

  • Reverting the behavior here to that of 3.1, but only in the specific case that is broken. (This kind of pivot isn't ideal, but this is a tricky case.)
  • Rather than doing this silently, we also generate a warning in the logs when we do this.

Description

EF Core 5.0 adds transaction savepoint support, and automatically uses savepoints to make SaveChanges better when an external transaction is used. Unfortunately savepoints do not work in SQL Server when the Multiple Active Result Set (MARS) feature is enabled.

Customer Impact

Regression for users who have turned on MARS and are using external transactions receive an error when attempting to save changes.

How found

User-reported on 5.0

Test coverage

Added in this PR. We will also revisit coverage for MARS in general.

Regression?

Yes, from 3.1.

Risk

Low. There was already infrastructure in place for checking whether savepoints are supported by the database provider or not; this PR modifies that check for SQL Server to check if MARS is enabled. When savepoints aren't supported, we revert back to the previous, 3.1 behavior.

@roji roji requested a review from a team November 13, 2020 10:30
@roji roji changed the base branch from main to release/5.0 November 13, 2020 10:30
@@ -249,6 +249,10 @@
<value>Skipping foreign key '{foreignKeyName}' on table '{tableName}' since all of its columns reference themselves.</value>
<comment>Debug SqlServerEventId.ReflexiveConstraintIgnored string string</comment>
</data>
<data name="LogSavepointsDisabledBecauseOfMARS" xml:space="preserve">
<value>Savepoints are disabled because Multiple Active Result Sets is enabled. When saving changes, the transaction will not be rolled back if error occurs, and may be left in an unknown state. See https://docs.microsoft.com/en-us/ef/core/saving/transactions#savepoints for more information. To identify the code which triggers this warning, call 'ConfigureWarnings(w =&gt; w.Throw(RelationalEventId.SavepointsDisabledBecauseOfMARS))'.</value>
Copy link
Member Author

@roji roji Nov 13, 2020

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Great, thanks @JeremyLikness!

Copy link
Member Author

Choose a reason for hiding this comment

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

One more thing @JeremyLikness, can you please make it point specifically to the savepoints section of that page (https://docs.microsoft.com/en-us/ef/core/saving/transactions#savepoints)?

@ajcvickers ajcvickers added this to the 5.0.x milestone Nov 13, 2020
@roji
Copy link
Member Author

roji commented Nov 15, 2020

@AndriySvyryd as discussed offline, TransactionSqlServerTest no longer disables MARS for the entire test suite. I looked at an attribute to not run a test if MARS is enabled/disabled, but ran into difficulties for retrieving the actual test class instance (in order to get the TestStore and check the connection string). However, there's currently exactly one inherited test which relies on MARS being disabled, so I just overrode and added that as a condition in the test for now. Let me know what you think.

@smitpatel
Copy link
Member

Are we adding a warning log in patch?

@roji
Copy link
Member Author

roji commented Nov 16, 2020

Are we adding a warning log in patch?

IIRC we agreed to do this when discussing, as the warning would be emitted in cases where 5.0.0 currently fails.

@ajcvickers
Copy link
Member

ajcvickers commented Nov 16, 2020

I missed that the warning happens only when asking is savepoints are enabled, which we only do when we're about to use one.

@roji When we discussed this, it was my understanding that we would only generate the warning if you actually hit the case where we would now fail. Otherwise if people are treating warnings as errors, then this becomes a break for applications that are not currently broken. So I think we need to do this at the time that we're going to create a savepoint when MARS is on. We can't do it just because MARS is on, since if they never create their own transaction, or indeed never call SaveChanges, then there should be no issue, right?

I think we might need to discuss this again.

@ajcvickers
Copy link
Member

Approved by Tactics for 5.0.1. Let's get the forward link done and agree on any wording before merging.

@roji roji force-pushed the DisableSavepointsWithMARS5.0 branch from fd9bcb6 to 361ae11 Compare November 17, 2020 18:28
roji added a commit that referenced this pull request Nov 17, 2020
@roji roji force-pushed the DisableSavepointsWithMARS5.0 branch from 361ae11 to be99532 Compare November 17, 2020 18:30
roji added a commit that referenced this pull request Nov 17, 2020
@roji roji force-pushed the DisableSavepointsWithMARS5.0 branch from be99532 to 8e7bb1f Compare November 17, 2020 18:31
roji added a commit that referenced this pull request Nov 17, 2020
@roji roji force-pushed the DisableSavepointsWithMARS5.0 branch from 8e7bb1f to 89f9315 Compare November 17, 2020 19:35
@roji roji force-pushed the DisableSavepointsWithMARS5.0 branch from 89f9315 to 34239e7 Compare November 17, 2020 19:43
@roji roji merged commit 34239e7 into release/5.0 Nov 17, 2020
@roji roji deleted the DisableSavepointsWithMARS5.0 branch November 17, 2020 20:39
@ajcvickers ajcvickers removed this from the 5.0.1 milestone Dec 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants