-
Notifications
You must be signed in to change notification settings - Fork 33
Feature/31 readcommitedlock #39
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
Open
AGiorgetti
wants to merge
2
commits into
develop
Choose a base branch
from
feature/31_READCOMMITEDLOCK
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 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
14 changes: 7 additions & 7 deletions
14
src/NEventStore.Persistence.MsSql.Tests/PersistenceEngineFixture.cs
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 | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,78 +2,77 @@ | |||||||
| using System.Transactions; | ||||||||
| using IsolationLevel = System.Data.IsolationLevel; | ||||||||
|
|
||||||||
| namespace NEventStore.Persistence.Sql.SqlDialects | ||||||||
| { | ||||||||
| namespace NEventStore.Persistence.Sql.SqlDialects { | ||||||||
| using System; | ||||||||
| using System.Data.SqlClient; | ||||||||
|
|
||||||||
| public class MsSqlDialect : CommonSqlDialect | ||||||||
| { | ||||||||
| public class MsSqlDialect : CommonSqlDialect { | ||||||||
| private const int UniqueIndexViolation = 2601; | ||||||||
| private const int UniqueKeyViolation = 2627; | ||||||||
|
|
||||||||
| public override string InitializeStorage | ||||||||
| { | ||||||||
| /// <summary> | ||||||||
| /// Add "WITH (READCOMMITTEDLOCK)" hint to any "FROM Commits" clause | ||||||||
| /// (#31) Make MsSqlDialect compatible with AzureSql and READ COMMITTED SNAPSHOT | ||||||||
| /// </summary> | ||||||||
| private readonly bool _addReadCommittedLockToFromCommits; | ||||||||
|
|
||||||||
| /// <summary> | ||||||||
| /// Constructor | ||||||||
| /// </summary> | ||||||||
| /// <param name="addReadCommittedLockToFromCommits">Add "WITH (READCOMMITTEDLOCK)" hint to any "FROM Commits" clause, can have an impact on multiple transactions scenarios</param> | ||||||||
| public MsSqlDialect(bool addReadCommittedLockToFromCommits = false) { | ||||||||
| _addReadCommittedLockToFromCommits = addReadCommittedLockToFromCommits; | ||||||||
| } | ||||||||
|
|
||||||||
| public override string InitializeStorage { | ||||||||
| get { return MsSqlStatements.InitializeStorage; } | ||||||||
| } | ||||||||
|
|
||||||||
| public override string GetSnapshot | ||||||||
| { | ||||||||
| public override string GetSnapshot { | ||||||||
| get { return "SET ROWCOUNT 1;\n" + base.GetSnapshot.Replace("LIMIT 1;", ";"); } | ||||||||
| } | ||||||||
|
|
||||||||
| public override string GetCommitsFromStartingRevision | ||||||||
| { | ||||||||
| get { return NaturalPaging(base.GetCommitsFromStartingRevision); } | ||||||||
| public override string GetCommitsFromStartingRevision { | ||||||||
| get { return AddReadCommittedLockToFromCommits(NaturalPaging(base.GetCommitsFromStartingRevision)); } | ||||||||
| } | ||||||||
|
|
||||||||
| public override string GetCommitsFromInstant | ||||||||
| { | ||||||||
| get { return CommonTableExpressionPaging(base.GetCommitsFromInstant); } | ||||||||
| public override string GetCommitsFromInstant { | ||||||||
| get { return AddReadCommittedLockToFromCommits(CommonTableExpressionPaging(base.GetCommitsFromInstant)); } | ||||||||
| } | ||||||||
|
|
||||||||
| public override string GetCommitsFromToInstant | ||||||||
| { | ||||||||
| get { return CommonTableExpressionPaging(base.GetCommitsFromToInstant); } | ||||||||
| public override string GetCommitsFromToInstant { | ||||||||
| get { return AddReadCommittedLockToFromCommits(CommonTableExpressionPaging(base.GetCommitsFromToInstant)); } | ||||||||
| } | ||||||||
|
|
||||||||
| public override string PersistCommit | ||||||||
| { | ||||||||
| public override string PersistCommit { | ||||||||
| get { return MsSqlStatements.PersistCommits; } | ||||||||
| } | ||||||||
|
|
||||||||
| public override string GetCommitsFromCheckpoint | ||||||||
| { | ||||||||
| get { return CommonTableExpressionPaging(base.GetCommitsFromCheckpoint); } | ||||||||
| public override string GetCommitsFromCheckpoint { | ||||||||
| get { return AddReadCommittedLockToFromCommits(CommonTableExpressionPaging(base.GetCommitsFromCheckpoint)); } | ||||||||
| } | ||||||||
|
|
||||||||
| public override string GetCommitsFromToCheckpoint | ||||||||
| { | ||||||||
| get { return CommonTableExpressionPaging(base.GetCommitsFromToCheckpoint); } | ||||||||
| public override string GetCommitsFromToCheckpoint { | ||||||||
| get { return AddReadCommittedLockToFromCommits(CommonTableExpressionPaging(base.GetCommitsFromToCheckpoint)); } | ||||||||
| } | ||||||||
|
|
||||||||
| public override string GetCommitsFromBucketAndCheckpoint | ||||||||
| { | ||||||||
| get { return CommonTableExpressionPaging(base.GetCommitsFromBucketAndCheckpoint); } | ||||||||
| public override string GetCommitsFromBucketAndCheckpoint { | ||||||||
| get { return AddReadCommittedLockToFromCommits(CommonTableExpressionPaging(base.GetCommitsFromBucketAndCheckpoint)); } | ||||||||
| } | ||||||||
|
|
||||||||
| public override string GetCommitsFromToBucketAndCheckpoint | ||||||||
| { | ||||||||
| get { return CommonTableExpressionPaging(base.GetCommitsFromToBucketAndCheckpoint); } | ||||||||
| public override string GetCommitsFromToBucketAndCheckpoint { | ||||||||
| get { return AddReadCommittedLockToFromCommits(CommonTableExpressionPaging(base.GetCommitsFromToBucketAndCheckpoint)); } | ||||||||
| } | ||||||||
|
|
||||||||
| public override string GetStreamsRequiringSnapshots | ||||||||
| { | ||||||||
| public override string GetStreamsRequiringSnapshots { | ||||||||
| get { return NaturalPaging(base.GetStreamsRequiringSnapshots); } | ||||||||
| } | ||||||||
|
|
||||||||
| private static string NaturalPaging(string query) | ||||||||
| { | ||||||||
| private static string NaturalPaging(string query) { | ||||||||
| return "SET ROWCOUNT @Limit;\n" + RemovePaging(query); | ||||||||
| } | ||||||||
|
|
||||||||
| private static string CommonTableExpressionPaging(string query) | ||||||||
| { | ||||||||
| private static string CommonTableExpressionPaging(string query) { | ||||||||
| query = RemovePaging(query); | ||||||||
| int orderByIndex = query.IndexOf("ORDER BY"); | ||||||||
| string orderBy = query.Substring(orderByIndex).Replace(";", string.Empty); | ||||||||
|
|
@@ -83,37 +82,45 @@ private static string CommonTableExpressionPaging(string query) | |||||||
| string from = query.Substring(fromIndex); | ||||||||
| string select = query.Substring(0, fromIndex); | ||||||||
|
|
||||||||
| string value = MsSqlStatements.PagedQueryFormat.FormatWith(select, orderBy, from); | ||||||||
| return value; | ||||||||
| return MsSqlStatements.PagedQueryFormat.FormatWith(select, orderBy, from); | ||||||||
|
||||||||
| return MsSqlStatements.PagedQueryFormat.FormatWith(select, orderBy, from); | |
| var value = MsSqlStatements.PagedQueryFormat.FormatWith(select, orderBy, from); | |
| return value; |
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.
Uh oh!
There was an error while loading. Please reload this page.
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 think this could even be made a default. It does no harm outside of Azure SQL. In fact, it will also make NEventStore more robust with local SQL Server, too, when someone enabled the
READ COMMITTED SNAPSHOToption on the database.