Skip to content

Commit 447eaca

Browse files
Releases: Fixes release branch by reverting previous commit. (#4957)
This reverts commit ee83a58. # Pull Request Template ## Description The commit was breaking the release branch, so this PR reverts the commit to fix the issue. The commit would have needed additional commits to work, will postpone that commit until the next release. ## Type of change Please delete options that are not relevant. - [] Bug fix (non-breaking change which fixes an issue) ## Closing issues To automatically close an issue: closes #IssueNumber
1 parent ee83a58 commit 447eaca

10 files changed

Lines changed: 170 additions & 657 deletions

File tree

Microsoft.Azure.Cosmos/src/ClientRetryPolicy.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ public void OnBeforeSendRequest(DocumentServiceRequest request)
193193
this.canUseMultipleWriteLocations = this.globalEndpointManager.CanUseMultipleWriteLocations(request);
194194
this.documentServiceRequest = request;
195195
this.isMultiMasterWriteRequest = !this.isReadRequest
196-
&& (this.globalEndpointManager?.CanSupportMultipleWriteLocations(request.ResourceType, request.OperationType) ?? false);
196+
&& (this.globalEndpointManager?.CanSupportMultipleWriteLocations(request) ?? false);
197197

198198
// clear previous location-based routing directive
199199
request.RequestContext.ClearRouteToLocation();

Microsoft.Azure.Cosmos/src/DocumentClient.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ internal partial class DocumentClient : IDisposable, IAuthorizationTokenProvider
115115

116116
private readonly bool IsLocalQuorumConsistency = false;
117117
private readonly bool isReplicaAddressValidationEnabled;
118+
private readonly AvailabilityStrategy availabilityStrategy;
118119

119120
//Fault Injection
120121
private readonly IChaosInterceptorFactory chaosInterceptorFactory;
@@ -440,6 +441,7 @@ internal DocumentClient(Uri serviceEndpoint,
440441
/// <param name="cosmosClientId"></param>
441442
/// <param name="remoteCertificateValidationCallback">This delegate responsible for validating the third party certificate. </param>
442443
/// <param name="cosmosClientTelemetryOptions">This is distributed tracing flag</param>
444+
/// <param name="availabilityStrategy">This is the availability strategy for the client</param>"
443445
/// <param name="chaosInterceptorFactory">This is the chaos interceptor used for fault injection</param>
444446
/// <remarks>
445447
/// The service endpoint can be obtained from the Azure Management Portal.
@@ -469,6 +471,7 @@ internal DocumentClient(Uri serviceEndpoint,
469471
string cosmosClientId = null,
470472
RemoteCertificateValidationCallback remoteCertificateValidationCallback = null,
471473
CosmosClientTelemetryOptions cosmosClientTelemetryOptions = null,
474+
AvailabilityStrategy availabilityStrategy = null,
472475
IChaosInterceptorFactory chaosInterceptorFactory = null)
473476
{
474477
if (sendingRequestEventArgs != null)
@@ -492,6 +495,7 @@ internal DocumentClient(Uri serviceEndpoint,
492495
this.transportClientHandlerFactory = transportClientHandlerFactory;
493496
this.IsLocalQuorumConsistency = isLocalQuorumConsistency;
494497
this.initTaskCache = new AsyncCacheNonBlocking<string, bool>(cancellationToken: this.cancellationTokenSource.Token);
498+
this.availabilityStrategy = availabilityStrategy;
495499
this.chaosInterceptorFactory = chaosInterceptorFactory;
496500
this.chaosInterceptor = chaosInterceptorFactory?.CreateInterceptor(this);
497501

Microsoft.Azure.Cosmos/src/Resource/ClientContextCore.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ internal static CosmosClientContext Create(
8484
cosmosClientId: cosmosClient.Id,
8585
remoteCertificateValidationCallback: ClientContextCore.SslCustomValidationCallBack(clientOptions.GetServerCertificateCustomValidationCallback()),
8686
cosmosClientTelemetryOptions: clientOptions.CosmosClientTelemetryOptions,
87+
availabilityStrategy: clientOptions.AvailabilityStrategy,
8788
chaosInterceptorFactory: clientOptions.ChaosInterceptorFactory);
8889

8990
return ClientContextCore.Create(

Microsoft.Azure.Cosmos/src/Routing/AvailabilityStrategy/AvailabilityStrategy.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,11 @@ internal static AvailabilityStrategy DisabledStrategy()
3939
/// </summary>
4040
/// <param name="threshold"> how long before SDK begins hedging</param>
4141
/// <param name="thresholdStep">Period of time between first hedge and next hedging attempts</param>
42-
/// <param name="enableMultiWriteRegionHedge">Whether hedging for write requests on accounts with multi-region writes are enabled
43-
/// Note that this does come with the caveat that there will be more 409 / 412 errors thrown by the SDK.
44-
/// This is expected and applications that adopt this feature should be prepared to handle these exceptions.
45-
/// Application might not be able to be deterministic on Create vs Replace in the case of Upsert Operations</param>
4642
/// <returns>something</returns>
47-
public static AvailabilityStrategy CrossRegionHedgingStrategy(
48-
TimeSpan threshold,
49-
TimeSpan? thresholdStep,
50-
bool enableMultiWriteRegionHedge = false)
43+
public static AvailabilityStrategy CrossRegionHedgingStrategy(TimeSpan threshold,
44+
TimeSpan? thresholdStep)
5145
{
52-
return new CrossRegionHedgingAvailabilityStrategy(threshold, thresholdStep, enableMultiWriteRegionHedge);
46+
return new CrossRegionHedgingAvailabilityStrategy(threshold, thresholdStep);
5347
}
5448
}
5549
}

Microsoft.Azure.Cosmos/src/Routing/AvailabilityStrategy/CrossRegionHedgingAvailabilityStrategy.cs

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -36,24 +36,14 @@ internal class CrossRegionHedgingAvailabilityStrategy : AvailabilityStrategyInte
3636
/// </summary>
3737
public TimeSpan ThresholdStep { get; private set; }
3838

39-
/// <summary>
40-
/// Whether hedging for write requests on accounts with multi-region writes is enabled.
41-
/// Note that this does come with the caveat that there will be more 409 / 412 errors thrown by the SDK.
42-
/// This is expected and applications that adopt this feature should be prepared to handle these exceptions.
43-
/// Application might not be able to be deterministic on Create vs Replace in the case of Upsert Operations
44-
/// </summary>
45-
public bool EnableMultiWriteRegionHedge { get; private set; }
46-
4739
/// <summary>
4840
/// Constructor for hedging availability strategy
4941
/// </summary>
5042
/// <param name="threshold"></param>
5143
/// <param name="thresholdStep"></param>
52-
/// <param name="enableMultiWriteRegionHedge"></param>
5344
public CrossRegionHedgingAvailabilityStrategy(
5445
TimeSpan threshold,
55-
TimeSpan? thresholdStep,
56-
bool enableMultiWriteRegionHedge = false)
46+
TimeSpan? thresholdStep)
5747
{
5848
if (threshold <= TimeSpan.Zero)
5949
{
@@ -67,7 +57,6 @@ public CrossRegionHedgingAvailabilityStrategy(
6757

6858
this.Threshold = threshold;
6959
this.ThresholdStep = thresholdStep ?? TimeSpan.FromMilliseconds(-1);
70-
this.EnableMultiWriteRegionHedge = enableMultiWriteRegionHedge;
7160
}
7261

7362
/// <inheritdoc/>
@@ -81,24 +70,18 @@ internal override bool Enabled()
8170
/// This availability strategy can only be used if the request is a read-only request on a document request.
8271
/// </summary>
8372
/// <param name="request"></param>
84-
/// <param name="client"></param>
8573
/// <returns>whether the request should be a hedging request.</returns>
86-
internal bool ShouldHedge(RequestMessage request, CosmosClient client)
74+
internal bool ShouldHedge(RequestMessage request)
8775
{
8876
//Only use availability strategy for document point operations
8977
if (request.ResourceType != ResourceType.Document)
9078
{
9179
return false;
9280
}
9381

94-
//check to see if it is a not a read-only request/ if multimaster writes are enabled
82+
//check to see if it is a not a read-only request
9583
if (!OperationTypeExtensions.IsReadOperation(request.OperationType))
9684
{
97-
if (this.EnableMultiWriteRegionHedge
98-
&& client.DocumentClient.GlobalEndpointManager.CanSupportMultipleWriteLocations(request.ResourceType, request.OperationType))
99-
{
100-
return true;
101-
}
10285
return false;
10386
}
10487

@@ -119,7 +102,7 @@ internal override async Task<ResponseMessage> ExecuteAvailabilityStrategyAsync(
119102
RequestMessage request,
120103
CancellationToken cancellationToken)
121104
{
122-
if (!this.ShouldHedge(request, client)
105+
if (!this.ShouldHedge(request)
123106
|| client.DocumentClient.GlobalEndpointManager.ReadEndpoints.Count == 1)
124107
{
125108
return await sender(request, cancellationToken);
@@ -130,7 +113,7 @@ internal override async Task<ResponseMessage> ExecuteAvailabilityStrategyAsync(
130113
using (CancellationTokenSource cancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken))
131114
{
132115
using (CloneableStream clonedBody = (CloneableStream)(request.Content == null
133-
? null
116+
? null//new CloneableStream(new MemoryStream())
134117
: await StreamExtension.AsClonableStreamAsync(request.Content)))
135118
{
136119
IReadOnlyCollection<string> hedgeRegions = client.DocumentClient.GlobalEndpointManager
@@ -160,8 +143,7 @@ internal override async Task<ResponseMessage> ExecuteAvailabilityStrategyAsync(
160143
request,
161144
hedgeRegions.ElementAt(requestNumber),
162145
cancellationToken,
163-
cancellationTokenSource,
164-
trace);
146+
cancellationTokenSource);
165147

166148
requestTasks.Add(primaryRequest);
167149
}
@@ -280,8 +262,7 @@ private async Task<HedgingResponse> CloneAndSendAsync(
280262
clonedRequest,
281263
region,
282264
cancellationToken,
283-
cancellationTokenSource,
284-
trace);
265+
cancellationTokenSource);
285266
}
286267
}
287268

@@ -290,8 +271,7 @@ private async Task<HedgingResponse> RequestSenderAndResultCheckAsync(
290271
RequestMessage request,
291272
string hedgedRegion,
292273
CancellationToken cancellationToken,
293-
CancellationTokenSource cancellationTokenSource,
294-
ITrace trace)
274+
CancellationTokenSource cancellationTokenSource)
295275
{
296276
try
297277
{
@@ -308,9 +288,9 @@ private async Task<HedgingResponse> RequestSenderAndResultCheckAsync(
308288

309289
return new HedgingResponse(false, response, hedgedRegion);
310290
}
311-
catch (OperationCanceledException oce ) when (cancellationTokenSource.IsCancellationRequested)
291+
catch (OperationCanceledException) when (cancellationTokenSource.IsCancellationRequested)
312292
{
313-
throw new CosmosOperationCanceledException(oce, trace);
293+
return new HedgingResponse(false, null, hedgedRegion);
314294
}
315295
catch (Exception ex)
316296
{

Microsoft.Azure.Cosmos/src/Routing/GlobalEndpointManager.cs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -546,17 +546,14 @@ public virtual async Task RefreshLocationAsync(bool forceRefresh = false)
546546
/// Determines whether the current configuration and state of the service allow for supporting multiple write locations.
547547
/// This method returns True is the AvailableWriteLocations in LocationCache is more than 1. Otherwise, it returns False.
548548
/// </summary>
549-
/// <param name="resourceType"> resource type of the request</param>
550-
/// <param name="operationType"> operation type of the request</param>
551-
/// <returns>A boolean flag indicating if the available write locations are more than one.</returns>
552-
public bool CanSupportMultipleWriteLocations(
553-
ResourceType resourceType,
554-
OperationType operationType)
549+
/// <param name="request">The document service request for which the write location support is being evaluated.</param>
550+
/// <returns>A boolean flag indicating if the available write locations are more than one.</returns>
551+
public bool CanSupportMultipleWriteLocations(DocumentServiceRequest request)
555552
{
556553
return this.locationCache.CanUseMultipleWriteLocations()
557554
&& this.locationCache.GetAvailableAccountLevelWriteLocations()?.Count > 1
558-
&& (resourceType == ResourceType.Document ||
559-
(resourceType == ResourceType.StoredProcedure && operationType == OperationType.Execute));
555+
&& (request.ResourceType == ResourceType.Document ||
556+
(request.ResourceType == ResourceType.StoredProcedure && request.OperationType == OperationType.Execute));
560557
}
561558

562559
#pragma warning disable VSTHRD100 // Avoid async void methods

Microsoft.Azure.Cosmos/src/Routing/IGlobalEndpointManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,6 @@ internal interface IGlobalEndpointManager : IDisposable
3737

3838
ReadOnlyDictionary<string, Uri> GetAvailableReadEndpointsByLocation();
3939

40-
bool CanSupportMultipleWriteLocations(ResourceType resourceType, OperationType operationType);
40+
bool CanSupportMultipleWriteLocations(DocumentServiceRequest request);
4141
}
4242
}

0 commit comments

Comments
 (0)