Skip to content

Commit

Permalink
Code changes to clean up the PPAF retry logic fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
kundadebdatta committed Sep 7, 2023
1 parent ef78559 commit fdffdd8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 17 deletions.
18 changes: 2 additions & 16 deletions Microsoft.Azure.Cosmos/src/ClientRetryPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,7 @@ private async Task<ShouldRetryResult> ShouldRetryInternalAsync(
}

// Received 503 due to client connect timeout or Gateway
if (statusCode == HttpStatusCode.ServiceUnavailable
&& ClientRetryPolicy.IsRetriableServiceUnavailable(subStatusCode))
if (statusCode == HttpStatusCode.ServiceUnavailable)
{
DefaultTrace.TraceWarning("ClientRetryPolicy: ServiceUnavailable. Refresh cache and retry. Failed Location: {0}; ResourceAddress: {1}",
this.documentServiceRequest?.RequestContext?.LocationEndpointToRoute?.ToString() ?? string.Empty,
Expand All @@ -265,12 +264,6 @@ private async Task<ShouldRetryResult> ShouldRetryInternalAsync(
return null;
}

private static bool IsRetriableServiceUnavailable(SubStatusCodes? subStatusCode)
{
return subStatusCode == SubStatusCodes.Unknown ||
(subStatusCode.HasValue && subStatusCode.Value.IsSDKGeneratedSubStatus());
}

private async Task<ShouldRetryResult> ShouldRetryOnEndpointFailureAsync(
bool isReadRequest,
bool markBothReadAndWriteAsUnavailable,
Expand Down Expand Up @@ -390,7 +383,7 @@ private ShouldRetryResult ShouldRetryOnSessionNotAvailable()

/// <summary>
/// For a ServiceUnavailable (503.0) we could be having a timeout from Direct/TCP locally or a request to Gateway request with a similar response due to an endpoint not yet available.
/// We try and retry the request only if there are other regions available.
/// We try and retry the request only if there are other regions available. The retry logic is applicable for single master write accounts as well.
/// </summary>
private ShouldRetryResult ShouldRetryOnServiceUnavailable()
{
Expand All @@ -400,13 +393,6 @@ private ShouldRetryResult ShouldRetryOnServiceUnavailable()
return ShouldRetryResult.NoRetry();
}

if (!this.canUseMultipleWriteLocations
&& !this.isReadRequest)
{
// Write requests on single master cannot be retried, no other regions available
return ShouldRetryResult.NoRetry();
}

int availablePreferredLocations = this.globalEndpointManager.PreferredLocationCount;

if (availablePreferredLocations <= 1)
Expand Down
2 changes: 1 addition & 1 deletion Microsoft.Azure.Cosmos/src/Routing/LocationCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ public Uri ResolveServiceEndpoint(DocumentServiceRequest request)
}
else
{
ReadOnlyCollection<Uri> endpoints = request.OperationType.IsWriteOperation() ? this.WriteEndpoints : this.ReadEndpoints;
ReadOnlyCollection<Uri> endpoints = this.ReadEndpoints;
locationEndpointToRoute = endpoints[locationIndex % endpoints.Count];
}

Expand Down

0 comments on commit fdffdd8

Please sign in to comment.