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

Routing: Adds Parallel Request Hedging #4198

Open
wants to merge 136 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 120 commits
Commits
Show all changes
136 commits
Select commit Hold shift + click to select a range
ddaa261
initial commit
NaluTripician Oct 26, 2023
e5d809a
fix
NaluTripician Oct 26, 2023
675a65d
Merge branch 'master' into users/nalutripician/parallelHedgingPreview
NaluTripician Nov 27, 2023
560dbfb
Merge branch 'master' into users/nalutripician/parallelHedgingPreview
NaluTripician Dec 12, 2023
af63676
document client restore
NaluTripician Dec 12, 2023
72abdcb
document client changes
NaluTripician Dec 12, 2023
efd95dd
clientContextCore fix
NaluTripician Dec 12, 2023
4ab0003
global endpoint manager fix
NaluTripician Dec 12, 2023
289e947
pre test changes
NaluTripician Dec 12, 2023
833c18e
start of tests
NaluTripician Dec 18, 2023
2a5f904
added dispose for cancellation token source
NaluTripician Dec 23, 2023
564704d
test changes
NaluTripician Dec 27, 2023
36dd15b
working test
NaluTripician Dec 27, 2023
f022cb3
more testing
NaluTripician Dec 28, 2023
9b4fcce
Merge branch 'master' into users/nalutripician/parallelHedgingPreview
NaluTripician Dec 28, 2023
7b87763
removed unneeded changes
NaluTripician Dec 28, 2023
7bdbd7f
Merge branch 'users/nalutripician/parallelHedgingPreview' of https://…
NaluTripician Dec 28, 2023
b69bf71
revert changes to global endpoint manager (unneeded)
NaluTripician Dec 28, 2023
b027881
requested changes
NaluTripician Dec 31, 2023
d6906f3
Merge branch 'master' into users/nalutripician/parallelHedgingPreview
NaluTripician Dec 31, 2023
274d9cc
Merge branch 'master' into users/nalutripician/parallelHedgingPreview
NaluTripician Jan 2, 2024
0b074c0
requested changes
NaluTripician Jan 2, 2024
9bfd2ee
Merge branch 'master' into users/nalutripician/parallelHedgingPreview
NaluTripician Jan 3, 2024
edba3a3
moves logic into availability strategy
NaluTripician Jan 3, 2024
ee4b31a
adds disableStrategy type
NaluTripician Jan 4, 2024
11cdd87
fixed test
NaluTripician Jan 4, 2024
8662908
refactor should hedge
NaluTripician Jan 4, 2024
5563274
refactor should hedge/adds can use availability strat
NaluTripician Jan 4, 2024
ece4b75
fixed mocking test
NaluTripician Jan 4, 2024
eca29c5
Update Microsoft.Azure.Cosmos/src/Handler/RequestInvokerHandler.cs
NaluTripician Jan 5, 2024
c285f85
requested changes
NaluTripician Jan 5, 2024
0a02c02
Merge branch 'users/nalutripician/parallelHedgingPreview' of https://…
NaluTripician Jan 5, 2024
1993725
fix enabled
NaluTripician Jan 5, 2024
8f95d54
Merge branch 'master' into users/nalutripician/parallelHedgingPreview
NaluTripician Jan 10, 2024
9550a41
added preview flag
NaluTripician Jan 10, 2024
0e4e4b2
Merge branch 'users/nalutripician/parallelHedgingPreview' of https://…
NaluTripician Jan 10, 2024
12f542d
fixed XML
NaluTripician Jan 10, 2024
eda0c84
fixed preview flags
NaluTripician Jan 11, 2024
f308ecb
fixed bugs
NaluTripician Jan 11, 2024
b2a0fff
nit
NaluTripician Jan 11, 2024
2c78aec
changed preview flags + update contracts
NaluTripician Jan 12, 2024
96c71aa
revert file for whitespace
NaluTripician Jan 12, 2024
fef912b
changed file back after update contract
NaluTripician Jan 12, 2024
c1fd371
removed using
NaluTripician Jan 12, 2024
dc5bd43
Merge branch 'master' into users/nalutripician/parallelHedgingPreview
NaluTripician Jan 16, 2024
5d1881a
requested changes
NaluTripician Jan 16, 2024
8cb7c8f
fixed small bug
NaluTripician Jan 16, 2024
5ccbf41
fixed bug
NaluTripician Jan 16, 2024
efa1181
removed options from client builder
NaluTripician Jan 16, 2024
0d8e085
removed usings
NaluTripician Jan 16, 2024
a3c6131
constructor check
NaluTripician Jan 16, 2024
c796bb3
Merge branch 'master' into users/nalutripician/parallelHedgingPreview
NaluTripician Jan 17, 2024
52490a3
fixed test
NaluTripician Jan 17, 2024
77ab0ad
added exclude region to logs
NaluTripician Jan 17, 2024
5a0fe88
lazy task create
NaluTripician Jan 22, 2024
47482c2
rename + lazy
NaluTripician Jan 22, 2024
65e5e52
Merge branch 'master' into users/nalutripician/parallelHedgingPreview
NaluTripician Jan 22, 2024
58e03e2
improvements and fixes
NaluTripician Jan 23, 2024
47d3e5e
Added XML commentes
NaluTripician Jan 23, 2024
b45e682
Merge branch 'master' into users/nalutripician/parallelHedgingPreview
NaluTripician Jan 23, 2024
06cc8eb
fixed xml comments
NaluTripician Jan 23, 2024
2d621c3
Merge branch 'master' into users/nalutripician/parallelHedgingPreview
NaluTripician Jan 24, 2024
2d79339
small tweeks
NaluTripician Jan 25, 2024
03b5cf7
Merge branch 'users/nalutripician/parallelHedgingPreview' of https://…
NaluTripician Jan 25, 2024
b000e7b
Merge branch 'master' into users/nalutripician/parallelHedgingPreview
NaluTripician Feb 8, 2024
142e0ad
added fixes + tests
NaluTripician Feb 26, 2024
897ba32
added item check to tests
NaluTripician Feb 26, 2024
d3fe73c
changed test regions to match with CI accounts
NaluTripician Feb 26, 2024
a409fd3
Merge branch 'master' into users/nalutripician/parallelHedgingPreview
NaluTripician Feb 28, 2024
0e53e76
query test
NaluTripician Feb 28, 2024
9a4c7d4
Merge branch 'master' into users/nalutripician/parallelHedgingPreview
NaluTripician Mar 12, 2024
a87d4d4
update test for multiregion CI pipelines
NaluTripician Mar 14, 2024
bdae2cb
Merge branch 'master' into users/nalutripician/parallelHedgingPreview
NaluTripician Mar 14, 2024
8606848
Merge branch 'master' into users/nalutripician/parallelHedgingPreview
NaluTripician Mar 15, 2024
218d6c2
Merge branch 'master' into users/nalutripician/parallelHedgingPreview
NaluTripician Mar 20, 2024
a792bb5
Merge branch 'master' into users/nalutripician/parallelHedgingPreview
NaluTripician Mar 20, 2024
817932c
enviroment var null check
NaluTripician Mar 20, 2024
caa5806
null checks
NaluTripician Mar 20, 2024
e8e76c3
perf tests
NaluTripician Apr 1, 2024
f864da5
Merge branch 'master' into users/nalutripician/parallelHedgingPreview
NaluTripician Apr 4, 2024
b6aafbe
revert benchmark project
NaluTripician Apr 10, 2024
6d02561
possible memory saving
NaluTripician Apr 10, 2024
e4f60eb
Merge branch 'master' into users/nalutripician/parallelHedgingPreview
NaluTripician Apr 10, 2024
b9b94ea
Merge branch 'master' into users/nalutripician/parallelHedgingPreview
NaluTripician Apr 10, 2024
2c0d1ba
Tests/improvements
NaluTripician Apr 16, 2024
e3ac82e
Merge branch 'users/nalutripician/parallelHedgingPreview' of https://…
NaluTripician Apr 16, 2024
7c56e5c
Merge branch 'master' into users/nalutripician/parallelHedgingPreview
NaluTripician Apr 16, 2024
3ac0018
extensive testing improvements + bug fixes
NaluTripician Apr 19, 2024
3e6242b
Merge branch 'users/nalutripician/parallelHedgingPreview' of https://…
NaluTripician Apr 19, 2024
12f9cde
Merge branch 'master' into users/nalutripician/parallelHedgingPreview
NaluTripician Apr 19, 2024
e6452d6
removed unneeded changes
NaluTripician Apr 19, 2024
85419e9
Merge branch 'users/nalutripician/parallelHedgingPreview' of https://…
NaluTripician Apr 19, 2024
99de0c0
Merge branch 'master' into users/nalutripician/parallelHedgingPreview
NaluTripician Apr 23, 2024
7eb81e4
nits
NaluTripician Apr 24, 2024
92be22e
fix hedge regions
NaluTripician Apr 24, 2024
242a270
Merge branch 'master' into users/nalutripician/parallelHedgingPreview
NaluTripician Apr 24, 2024
d2141b4
update contracts
NaluTripician Apr 25, 2024
e2fd0b2
fix updatecontract
NaluTripician Apr 25, 2024
8ceed05
test fix
NaluTripician Apr 26, 2024
6564571
fixed areequal asserts
NaluTripician Apr 26, 2024
3d8dd81
Merge branch 'master' into users/nalutripician/parallelHedgingPreview
NaluTripician Apr 29, 2024
077d919
Merge branch 'master' into users/nalutripician/parallelHedgingPreview
NaluTripician Apr 29, 2024
f0ebcbb
ALTERNATE METHOD
NaluTripician May 1, 2024
0f4b5c6
Merge branch 'master' into users/nalutripician/parallelHedgingPreview
NaluTripician May 2, 2024
4e72248
added readfeed FI operation type to tests
NaluTripician May 2, 2024
ff9918d
requested changes and improvemtns
NaluTripician May 6, 2024
c95a546
list optimization
NaluTripician May 6, 2024
eecc2c2
Merge branch 'master' into users/nalutripician/parallelHedgingPreview
NaluTripician May 7, 2024
4c0750b
fixed edge case diagnostics
NaluTripician May 7, 2024
4a7282b
Merge branch 'users/nalutripician/parallelHedgingPreview' of https://…
NaluTripician May 7, 2024
f1738e0
small fix
NaluTripician May 7, 2024
f2512ea
small fixes
NaluTripician May 7, 2024
8cce6e2
refactor code
NaluTripician May 8, 2024
abc212a
fixed null issues
NaluTripician May 8, 2024
07034e2
null refrence
NaluTripician May 8, 2024
f49ad9e
bug fixes
NaluTripician May 9, 2024
25d4e25
Merge branch 'master' into users/nalutripician/parallelHedgingPreview
NaluTripician May 9, 2024
5094543
Merge branch 'master' into users/nalutripician/parallelHedgingPreview
NaluTripician May 9, 2024
98b8681
Merge branch 'master' into users/nalutripician/parallelHedgingPreview
NaluTripician May 9, 2024
b7b7349
Merge branch 'master' into users/nalutripician/parallelHedgingPreview
NaluTripician May 9, 2024
182f8b1
Merge branch 'master' into users/nalutripician/parallelHedgingPreview
NaluTripician May 13, 2024
14d970f
changed header clone to internal
NaluTripician May 13, 2024
98109e0
Merge branch 'users/nalutripician/parallelHedgingPreview' of https://…
NaluTripician May 13, 2024
dc4f5cb
fixed API doc + test change
NaluTripician May 13, 2024
fa8e88a
removed unused method
NaluTripician May 14, 2024
d42de99
Merge branch 'master' into users/nalutripician/parallelHedgingPreview
NaluTripician May 15, 2024
a3c5d61
changed to internal
NaluTripician May 15, 2024
6799236
fixed internal
NaluTripician May 15, 2024
f089c4b
removed contract changes
NaluTripician May 15, 2024
8abae58
updated abstract class
NaluTripician May 16, 2024
e499eae
suggested changes
NaluTripician May 16, 2024
cb26ed9
Merge branch 'master' into users/nalutripician/parallelHedgingPreview
NaluTripician May 16, 2024
9524c59
Merge branch 'master' into users/nalutripician/parallelHedgingPreview
NaluTripician May 21, 2024
b4d7fcf
Merge branch 'master' into users/nalutripician/parallelHedgingPreview
NaluTripician May 21, 2024
ce03e5b
Merge branch 'master' into users/nalutripician/parallelHedgingPreview
NaluTripician May 29, 2024
da1ef72
Merge branch 'master' into users/nalutripician/parallelHedgingPreview
NaluTripician May 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 11 additions & 2 deletions Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Microsoft.Azure.Cosmos
using System.Net.Http;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
using Microsoft.Azure.Cosmos.Fluent;
using Microsoft.Azure.Cosmos.Fluent;
NaluTripician marked this conversation as resolved.
Show resolved Hide resolved
using Microsoft.Azure.Documents;
using Microsoft.Azure.Documents.Client;
using Newtonsoft.Json;
Expand Down Expand Up @@ -650,7 +650,16 @@ public Func<HttpClient> HttpClientFactory

this.httpClientFactory = value;
}
}
}
/// <summary>
/// Availability Strategy to be used for periods of high latency
/// </summary>
#if PREVIEW
public
#else
internal
#endif
AvailabilityStrategy AvailabilityStrategy { get; set; }

/// <summary>
/// Enable partition key level failover
Expand Down
4 changes: 4 additions & 0 deletions Microsoft.Azure.Cosmos/src/DocumentClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ internal partial class DocumentClient : IDisposable, IAuthorizationTokenProvider

private readonly bool IsLocalQuorumConsistency = false;
private readonly bool isReplicaAddressValidationEnabled;
private readonly AvailabilityStrategy availabilityStrategy;

NaluTripician marked this conversation as resolved.
Show resolved Hide resolved
//Fault Injection
private readonly IChaosInterceptorFactory chaosInterceptorFactory;
Expand Down Expand Up @@ -439,6 +440,7 @@ internal partial class DocumentClient : IDisposable, IAuthorizationTokenProvider
/// <param name="cosmosClientId"></param>
/// <param name="remoteCertificateValidationCallback">This delegate responsible for validating the third party certificate. </param>
/// <param name="cosmosClientTelemetryOptions">This is distributed tracing flag</param>
/// <param name="availabilityStrategy">This is the availability strategy for the client</param>"
/// <param name="chaosInterceptorFactory">This is the chaos interceptor used for fault injection</param>
/// <remarks>
/// The service endpoint can be obtained from the Azure Management Portal.
Expand Down Expand Up @@ -468,6 +470,7 @@ internal partial class DocumentClient : IDisposable, IAuthorizationTokenProvider
string cosmosClientId = null,
RemoteCertificateValidationCallback remoteCertificateValidationCallback = null,
CosmosClientTelemetryOptions cosmosClientTelemetryOptions = null,
AvailabilityStrategy availabilityStrategy = null,
IChaosInterceptorFactory chaosInterceptorFactory = null)
{
if (sendingRequestEventArgs != null)
Expand All @@ -491,6 +494,7 @@ internal partial class DocumentClient : IDisposable, IAuthorizationTokenProvider
this.transportClientHandlerFactory = transportClientHandlerFactory;
this.IsLocalQuorumConsistency = isLocalQuorumConsistency;
this.initTaskCache = new AsyncCacheNonBlocking<string, bool>(cancellationToken: this.cancellationTokenSource.Token);
this.availabilityStrategy = availabilityStrategy;
this.chaosInterceptorFactory = chaosInterceptorFactory;
this.chaosInterceptor = chaosInterceptorFactory?.CreateInterceptor(this);

Expand Down
18 changes: 17 additions & 1 deletion Microsoft.Azure.Cosmos/src/Fluent/CosmosClientBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Microsoft.Azure.Cosmos.Fluent
using System.Threading.Tasks;
using global::Azure;
using global::Azure.Core;
using Microsoft.Azure.Cosmos.Core.Trace;
using Microsoft.Azure.Cosmos.Core.Trace;
using Microsoft.Azure.Documents;
using Microsoft.Azure.Documents.Client;

Expand Down Expand Up @@ -683,6 +683,22 @@ internal CosmosClientBuilder WithApiType(ApiType apiType)
{
this.clientOptions.ApiType = apiType;
return this;
}

/// <summary>
/// Availability Stragey to be used for periods of high latency
/// </summary>
/// <param name="strategy"></param>
/// <returns>The CosmosClientBuilder</returns>
#if PREVIEW
public
#else
internal
#endif
CosmosClientBuilder WithAvailibilityStrategy(AvailabilityStrategy strategy)
{
this.clientOptions.AvailabilityStrategy = strategy;
return this;
}

/// <summary>
Expand Down
61 changes: 55 additions & 6 deletions Microsoft.Azure.Cosmos/src/Handler/RequestInvokerHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace Microsoft.Azure.Cosmos.Handlers
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Azure.Cosmos.Diagnostics;
using Microsoft.Azure.Cosmos.Routing;
using Microsoft.Azure.Cosmos.Tracing;
using Microsoft.Azure.Documents;
Expand All @@ -38,6 +39,7 @@ internal class RequestInvokerHandler : RequestHandler
Cosmos.PriorityLevel? requestedClientPriorityLevel)
{
this.client = client;

this.RequestedClientConsistencyLevel = requestedClientConsistencyLevel;
this.RequestedClientPriorityLevel = requestedClientPriorityLevel;
}
Expand All @@ -52,11 +54,8 @@ internal class RequestInvokerHandler : RequestHandler
}

RequestOptions promotedRequestOptions = request.RequestOptions;
if (promotedRequestOptions != null)
{
// Fill request options
promotedRequestOptions.PopulateRequestOptions(request);
}
// Fill request options
promotedRequestOptions?.PopulateRequestOptions(request);

// Adds the NoContent header if not already added based on Client Level flag
if (RequestInvokerHandler.ShouldSetNoContentResponseHeaders(
Expand All @@ -79,7 +78,57 @@ internal class RequestInvokerHandler : RequestHandler

await request.AssertPartitioningDetailsAsync(this.client, cancellationToken, request.Trace);
this.FillMultiMasterContext(request);
return await base.SendAsync(request, cancellationToken);

if (this.CanUseAvailabilityStrategy(request))
{
AvailabilityStrategy strategy = request.RequestOptions?.AvailabilityStrategy ?? this.client.ClientOptions.AvailabilityStrategy;

return await strategy.ExecuteAvailablityStrategyAsync(
this.BaseSendAsync,
this.client,
request,
cancellationToken);
}

return await this.BaseSendAsync(request, cancellationToken);
}

/// <summary>
/// This method determines if there is an availability strategy that the request can use.
/// Note that the request level availability strategy options override the client level options.
/// </summary>
/// <param name="request"></param>
/// <returns>whether the request should be a parallel hedging request.</returns>
public bool CanUseAvailabilityStrategy(RequestMessage request)
{
//No availability strategy options
if (request.RequestOptions?.AvailabilityStrategy == null && this.client.ClientOptions.AvailabilityStrategy == null)
{
return false;
}

AvailabilityStrategy strategyOptions = request.RequestOptions?.AvailabilityStrategy
?? this.client.ClientOptions.AvailabilityStrategy;

//Request level availability strategy options are disabled/override client level
if (!strategyOptions.Enabled())
{
return false;
}

return true;
}

public virtual async Task<ResponseMessage> BaseSendAsync(
RequestMessage request,
CancellationToken cancellationToken)
{
ResponseMessage response = await base.SendAsync(request, cancellationToken);
if (request.RequestOptions?.ExcludeRegions != null)
{
((CosmosTraceDiagnostics)response.Diagnostics).Value.AddDatum("ExcludedRegions", request.RequestOptions.ExcludeRegions);
}
return response;
}

public virtual async Task<T> SendAsync<T>(
Expand Down
88 changes: 84 additions & 4 deletions Microsoft.Azure.Cosmos/src/Handler/RequestMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
namespace Microsoft.Azure.Cosmos
{
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.IO;
using System.Linq;
using System.Net;
NaluTripician marked this conversation as resolved.
Show resolved Hide resolved
using System.Net.Http;
using System.Threading;
Expand Down Expand Up @@ -62,6 +63,28 @@ public RequestMessage(HttpMethod method, Uri requestUri)
this.Method = method;
this.RequestUriString = requestUriString;
this.Trace = trace ?? throw new ArgumentNullException(nameof(trace));
}

/// <summary>
/// Create a <see cref="RequestMessage"/>, used for Clone() method.
/// </summary>
/// <param name="method">The http method</param>
/// <param name="requestUriString">The requested URI</param>
/// <param name="trace">The trace node to append traces to.</param>
/// <param name="headers">The headers to use.</param>
/// <param name="properties">The properties to use.</param>
private RequestMessage(
HttpMethod method,
string requestUriString,
ITrace trace,
Headers headers,
Dictionary<string, object> properties)
{
this.Method = method;
this.RequestUriString = requestUriString;
this.Trace = trace ?? throw new ArgumentNullException(nameof(trace));
this.headers = new Lazy<Headers>(() => headers);
NaluTripician marked this conversation as resolved.
Show resolved Hide resolved
this.properties = new Lazy<Dictionary<string, object>>(() => properties);
}

/// <summary>
Expand Down Expand Up @@ -138,7 +161,8 @@ public virtual Stream Content
this.Headers.PartitionKey == null;

internal string ContainerId { get; set; }
internal string DatabaseId { get; set; }
internal string DatabaseId { get; set; }
internal Uri LocationEndpointToRoute { get; set; }

/// <summary>
/// Request properties Per request context available to handlers.
Expand Down Expand Up @@ -274,7 +298,11 @@ internal DocumentServiceRequest ToDocumentServiceRequest()
serviceRequest.UseStatusCodeForFailures = true;
serviceRequest.UseStatusCodeFor429 = true;
serviceRequest.Properties = this.Properties;
this.DocumentServiceRequest = serviceRequest;
this.DocumentServiceRequest = serviceRequest;
if (this.LocationEndpointToRoute != null)
{
this.DocumentServiceRequest.RequestContext.RouteToLocation(this.LocationEndpointToRoute);
}
}

// Routing to a particular PartitionKeyRangeId
Expand All @@ -286,6 +314,58 @@ internal DocumentServiceRequest ToDocumentServiceRequest()
this.DocumentServiceRequest.RequestContext.ExcludeRegions = this.RequestOptions?.ExcludeRegions;
this.OnBeforeRequestHandler(this.DocumentServiceRequest);
return this.DocumentServiceRequest;
}

/// <summary>
/// Clone the request message
/// </summary>
/// <returns>a cloned copy of the RequestMessage</returns>
internal RequestMessage Clone(ITrace newTrace)
{
RequestMessage clone = new RequestMessage(
this.Method,
this.RequestUriString,
newTrace,
this.Headers.Clone(),
this.Properties.ToDictionary(entry => entry.Key, entry => entry.Value));

if (this.Content != null)
{
Stream cloneContent = new MemoryStream((int)this.Content.Length);
this.Content.Position = 0;
NaluTripician marked this conversation as resolved.
Show resolved Hide resolved
this.Content.CopyTo(cloneContent);
clone.Content = cloneContent;
}

if (this.RequestOptions != null)
{
clone.RequestOptions = this.RequestOptions.ShallowCopy();
}

clone.ResourceType = this.ResourceType;

clone.OperationType = this.OperationType;

if (this.PartitionKeyRangeId != null)
{
clone.PartitionKeyRangeId = string.IsNullOrEmpty(this.PartitionKeyRangeId.CollectionRid)
? new PartitionKeyRangeIdentity(this.PartitionKeyRangeId.PartitionKeyRangeId)
: new PartitionKeyRangeIdentity(this.PartitionKeyRangeId.CollectionRid, this.PartitionKeyRangeId.PartitionKeyRangeId);
}

clone.UseGatewayMode = this.UseGatewayMode;

clone.ContainerId = this.ContainerId;

clone.DatabaseId = this.DatabaseId;

return clone;
}

internal void RouteToLocation(Uri location)
{
this.LocationEndpointToRoute = location;
this.DocumentServiceRequest?.RequestContext.RouteToLocation(location);
}

private static Dictionary<string, object> CreateDictionary()
Expand Down
22 changes: 21 additions & 1 deletion Microsoft.Azure.Cosmos/src/Headers/Headers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Microsoft.Azure.Cosmos
{
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Globalization;
using Microsoft.Azure.Documents;
using Microsoft.Azure.Documents.Collections;
Expand Down Expand Up @@ -285,6 +285,11 @@ internal Headers(INameValueCollection nameValueCollection)
HttpResponseHeadersWrapper httpResponseHeaders => httpResponseHeaders,
_ => new NameValueResponseHeaders(nameValueCollection),
};
}

internal Headers(CosmosMessageHeadersInternal cosmosMessageHeaders)
{
this.CosmosMessageHeaders = cosmosMessageHeaders;
}

/// <summary>
Expand Down Expand Up @@ -404,6 +409,21 @@ public virtual T GetHeaderValue<T>(string headerName)
{
return this.CosmosMessageHeaders.GetHeaderValue<T>(headerName);
}

/// <summary>
/// Clones the current <see cref="Headers"/>.
/// </summary>
/// <returns>a cloned copy of the current <see cref="Headers"/></returns>
public Headers Clone()
NaluTripician marked this conversation as resolved.
Show resolved Hide resolved
{
StoreRequestHeaders clone = new StoreRequestHeaders();
foreach (string key in this.CosmosMessageHeaders.AllKeys())
{
clone.Add(key, this.CosmosMessageHeaders[key]);
}
NaluTripician marked this conversation as resolved.
Show resolved Hide resolved

return new Headers(clone);
}

/// <summary>
/// Enumerates all the HTTP headers names in the <see cref="Headers"/>.
Expand Down
18 changes: 16 additions & 2 deletions Microsoft.Azure.Cosmos/src/RequestOptions/RequestOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
namespace Microsoft.Azure.Cosmos
{
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using Microsoft.Azure.Cosmos.Routing;
using Microsoft.Azure.Documents;
using Telemetry;

Expand Down Expand Up @@ -69,7 +70,20 @@ public class RequestOptions
/// This can be used to route a request to a specific region by excluding all other regions.
/// If all regions are excluded, then the request will be routed to the primary/hub region.
/// </summary>
public List<string> ExcludeRegions { get; set; }
public List<string> ExcludeRegions { get; set; }

/// <summary>
/// Cosmos availability strategy.
/// Availability strategy allows the SDK to send out additional cross region requests to help
/// reduce latency and increase availability. Currently there is one type of availability strategy, parallel request hedging.
/// If there is a globally enabled availability strategy, setting one in the request options will override the global one.
/// </summary>
#if PREVIEW
public
#else
internal
#endif
AvailabilityStrategy AvailabilityStrategy { get; set; }

/// <summary>
/// Gets or sets the boolean to use effective partition key routing in the cosmos db request.
Expand Down
1 change: 1 addition & 0 deletions Microsoft.Azure.Cosmos/src/Resource/ClientContextCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ internal class ClientContextCore : CosmosClientContext
cosmosClientId: cosmosClient.Id,
remoteCertificateValidationCallback: ClientContextCore.SslCustomValidationCallBack(clientOptions.GetServerCertificateCustomValidationCallback()),
cosmosClientTelemetryOptions: clientOptions.CosmosClientTelemetryOptions,
availabilityStrategy: clientOptions.AvailabilityStrategy,
chaosInterceptorFactory: clientOptions.ChaosInterceptorFactory);

return ClientContextCore.Create(
Expand Down