Using ApplicationIntent=ReadOnly in SQL read operations#56
Open
andrebires wants to merge 12 commits intomasterfrom
Open
Using ApplicationIntent=ReadOnly in SQL read operations#56andrebires wants to merge 12 commits intomasterfrom
andrebires wants to merge 12 commits intomasterfrom
Conversation
…d server doesn't support 6.0
andre-ss6
reviewed
Jan 25, 2022
| public virtual IAsyncEnumerator<T> GetAsyncEnumerator(CancellationToken cancellationToken) | ||
| { | ||
| return GetEnumeratorAsync(cancellationToken).Result; | ||
| // TODO: This is a blocking operation in a async context. How may we fix this? |
Contributor
There was a problem hiding this comment.
The implementation is flawed. The GetEnumeratorAsync method above should not exist. Instead, this method should prepare all the dependencies and send them to the enumerator. DbDataReaderAsyncEnumerator.MoveNextAsync implementation will be a state machine; When invoked on its initial state, it will create and OpenAsync the connection and then ExecuteReaderAsync. Following invocations would use the current implementation.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR introduces a proposal for segregating read and write operations in Elephant's basic storage structures on SQL Server, for enabling the use of secondary replicas for read-only operations.
To allow that, this PR adds three new SQL storages structures:
ApplicationIntentSqlMap,ApplicationIntentSqlSetandApplicationIntentSqlSetMap. Every one of these structures contains a read-only and a write instance of the "real" SQL implementation of the data structure, with the read-only structure receiving an additionalApplicationIntent=ReadOnlysuffix in the connection string. And every method call just forwards the invocation to the adequate instance, according to the method type: queries go to the read-only instance and writes (adding, deleting, updating) go to the writable one.For extending data structures, a new
GetReadOnlyConnectionAsyncbase method was added, and it should be used in specific map implementations, like the ones that currently use SQLKata for queries.For testing, an
AuditableDatabaseDrivedecorator was implemented to allow us to assert if the correct connection string was passed for every operation.The idea of adding new structures instead of changing the current ones was to avoid introducing bugs. But this comes with a limitation: in the
ApplicationIntentSqlSetMapimplementation, theISet<T>value returned by theGetValueOrDefaultAsyncandGetValueOrEmptyAsyncdo not segregate the calls by read-only and writable, so implementations that relies on this method will only use writable connections.More information:
SQL Azure: https://docs.microsoft.com/en-us/azure/azure-sql/database/read-scale-out
SQL Server: https://docs.microsoft.com/en-us/sql/database-engine/availability-groups/windows/configure-read-only-routing-for-an-availability-group-sql-server