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

Batch API: Adds Session token support #1870

Merged
merged 20 commits into from
Feb 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
cfe4738
Session token support for transactional batch
rakkuma Sep 23, 2020
b6c01d5
Contract change
rakkuma Sep 23, 2020
1dfb49d
code review fix
rakkuma Sep 29, 2020
c48272e
Merge branch 'master' of https://github.com/Azure/azure-cosmos-dotnet…
rakkuma Sep 29, 2020
d41ed17
Merging with master
rakkuma Oct 8, 2020
aa409fd
Merge branch 'master' into users/rakkuma/batch-session-token
ealsur Oct 16, 2020
833efad
Merge branch 'master' of https://github.com/Azure/azure-cosmos-dotnet…
rakkuma Oct 19, 2020
a32289b
Merge branch 'users/rakkuma/batch-session-token' of https://github.co…
rakkuma Oct 19, 2020
4d52111
Merge branch 'master' into users/rakkuma/batch-session-token
rakkuma Nov 23, 2020
6207741
Merge branch 'master' of https://github.com/Azure/azure-cosmos-dotnet…
rakkuma Nov 23, 2020
54a1560
Merge branch 'master' into users/rakkuma/batch-session-token
rakkuma Dec 7, 2020
523f740
Merge branch 'users/rakkuma/batch-session-token' of https://github.co…
rakkuma Dec 7, 2020
51352c5
Session token error message less strict check
rakkuma Dec 7, 2020
0dafa45
Change
rakkuma Dec 7, 2020
66132e6
Merge branch 'master' into users/rakkuma/batch-session-token
rakkuma Feb 1, 2021
0ed92ae
Merge branch 'master' of https://github.com/Azure/azure-cosmos-dotnet…
rakkuma Feb 10, 2021
fa03ca5
Merge branch 'master' into users/rakkuma/batch-session-token
rakkuma Feb 10, 2021
46bf64b
Merge branch 'master' of https://github.com/Azure/azure-cosmos-dotnet…
rakkuma Feb 12, 2021
9b99a27
Merge branch 'users/rakkuma/batch-session-token' of https://github.co…
rakkuma Feb 12, 2021
014c97e
Adding session consistency
rakkuma Feb 12, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,39 @@ namespace Microsoft.Azure.Cosmos
/// </summary>
public class TransactionalBatchRequestOptions : RequestOptions
{
/// <summary>
/// Gets or sets the token for use with session consistency in the Azure Cosmos DB service.
/// </summary>
/// <value>
/// The token for use with session consistency.
/// </value>
///
/// <remarks>
/// One of the <see cref="ConsistencyLevel"/> for Azure Cosmos DB is Session. In fact, this is the default level applied to accounts.
/// <para>
/// When working with Session consistency, each batch request with write operation to Azure Cosmos DB is assigned a new SessionToken.
/// The CosmosClient will use this token internally with each read/query/batch request to ensure that the set
/// consistency level is maintained.
///
/// <para>
/// In some scenarios you need to manage this Session yourself;
/// Consider a web application with multiple nodes, each node will have its own instance of <see cref="CosmosClient"/>
/// If you wanted these nodes to participate in the same session (to be able read your own writes consistently across web tiers)
/// you would have to send the SessionToken from <see cref="TransactionalBatchResponse"/> of the write action on one node
/// to the client tier, using a cookie or some other mechanism, and have that token flow back to the web tier for subsequent reads.
/// If you are using a round-robin load balancer which does not maintain session affinity between requests, such as the Azure Load Balancer,
/// the read could potentially land on a different node to the write request, where the session was created.
/// </para>
///
/// <para>
/// If you do not flow the Azure Cosmos DB SessionToken across as described above you could end up with inconsistent read results for a period of time.
/// </para>
///
/// </para>
/// <see href="https://docs.microsoft.com/azure/cosmos-db/consistency-levels" />
/// </remarks>
rakkuma marked this conversation as resolved.
Show resolved Hide resolved
public string SessionToken { get; set; }
rakkuma marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// Gets or sets the consistency level required for the request in the Azure Cosmos DB service.
/// </summary>
Expand All @@ -34,6 +67,8 @@ public ConsistencyLevel? ConsistencyLevel
/// <param name="request">The <see cref="RequestMessage"/></param>
internal override void PopulateRequestOptions(RequestMessage request)
{
RequestOptions.SetSessionToken(request, this.SessionToken);

base.PopulateRequestOptions(request);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ private static async Task<TransactionalBatchResponse> PopulateFromContentAsync(
{
foreach (TransactionalBatchOperationResult result in results)
{
if ((int)result.StatusCode != (int)StatusCodes.FailedDependency)
if ((int)result.StatusCode != (int)StatusCodes.FailedDependency && (int)result.StatusCode >= (int)StatusCodes.StartingErrorCode)
ealsur marked this conversation as resolved.
Show resolved Hide resolved
{
responseStatusCode = result.StatusCode;
responseSubStatusCode = result.SubStatusCode;
Expand Down
Loading