Skip to content

Commit ad0583e

Browse files
[Internal] Release: Adds Cherry-Pick Metadata PR Fix to release branch (#5125)
# Pull Request Template ## Description ### Context Currently, there is a bug in the SDK where upon a cold start of the SDK and rare edge cases involving online/offline-ing regions, where only query requests are made, the SDK will not retry certain status code responses from metadata requests causing the entire request to fail. The correct behavior would be for the SDK to do cross region retries on these metadata requests. This pulls request includes several updates to enhance error handling and retry logic in the Cosmos DB SDK. The changes mainly focus on extending support for additional server error types and improving retry policies for various scenarios. ### Improvements to retry logic: * [`ClientRetryPolicy.cs`](diffhunk://#diff-2b056512ca285b1d95e025e31f60345059fa92d958becc38f90a6fb54ce1bbb4R331-R341): Enhanced retry logic to handle `InternalServerError` , `DatabaseAccountNotFound`, and `LeaseNotFound` status codes. * [`MetadataRequestThrottleRetryPolicy.cs`](diffhunk://#diff-a5ed5985909c3dcb6e4ce186cdd662d590dac5297ea14e68560c7d1eca307be4L26-R28): Refactored retry policy to handle additional status codes and renamed methods and constants to reflect the broader scope of endpoint unavailability. ### FaultInjection enhancements to error handling testing: * [`FaultInjectionRuleBuilder.cs`](diffhunk://#diff-d827164a4a6a0d8737e6598f8132c915ef48a1fc01daaa6422706f770dada5d5L152-R156): Added support for additional server error types such as `DatabaseAccountNotFound`, `ServiceUnavailable`, `InternalServerError`, and `LeaseNotFound` in the for metadata requests. * [`FaultInjectionServerErrorType.cs`](diffhunk://#diff-0c89faa9a48c428a7a98662d995474e34295618ac60e677ad9762fd048f33601L75-R82): Updated the `FaultInjectionServerErrorType` enum to include `LeaseNotFound` and corrected the status code for `DatabaseAccountNotFound`. * [`FaultInjectionServerErrorResultInternal.cs`](diffhunk://#diff-1ae8256c6d505a8f3b0a350978a0cc9a08f6234f7328f28f1db14302ee691d72L473-R473): Added handling for `LeaseNotFound` and updated the status code for `DatabaseAccountNotFound` in the `GetInjectedServerError` method. * ### Testing updates: * [`CosmosItemIntegrationTests.cs`](diffhunk://#diff-16d429adf686a32936696d2014afab3fc8faf91f10c880850fb8b30f8b96bb33R153-R214): Added a new test method `MetadataEndpointUnavailableCrossRegionalRetryTest` to validate the retry logic for various server error types. * [`ClientRetryPolicyTests.cs`](diffhunk://#diff-d3fdfdc5d4f4d8af2c2cc463d928285680e7695861422ef2e3330d1a956807e1L167-R176): Extended existing tests to cover additional status codes and substatus codes. ## 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 #4710 --------- # Pull Request Template ## Description Please include a summary of the change and which issue is fixed. Include samples if adding new API, and include relevant motivation and context. List any dependencies that are required for this change. ## Type of change Please delete options that are not relevant. - [] Bug fix (non-breaking change which fixes an issue) - [] New feature (non-breaking change which adds functionality) - [] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [] This change requires a documentation update ## Closing issues To automatically close an issue: closes #IssueNumber --------- Co-authored-by: Kiran Kumar Kolli <kirankk@microsoft.com>
1 parent 2745311 commit ad0583e

14 files changed

Lines changed: 3805 additions & 70 deletions

Directory.Build.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
22
<PropertyGroup>
3-
<ClientOfficialVersion>3.48.0</ClientOfficialVersion>
3+
<ClientOfficialVersion>3.48.1</ClientOfficialVersion>
44
<ClientPreviewVersion>3.49.0</ClientPreviewVersion>
5-
<ClientPreviewSuffixVersion>preview.0</ClientPreviewSuffixVersion>
5+
<ClientPreviewSuffixVersion>preview.1</ClientPreviewSuffixVersion>
66
<DirectVersion>3.37.10</DirectVersion>
77
<FaultInjectionVersion>1.0.0</FaultInjectionVersion>
88
<FaultInjectionSuffixVersion>beta.0</FaultInjectionSuffixVersion>

Microsoft.Azure.Cosmos/FaultInjection/src/FaultInjectionRuleBuilder.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,11 @@ private void ValidateGatewayConnection()
149149
{
150150
if (serverErrorResult?.GetServerErrorType() != FaultInjectionServerErrorType.TooManyRequests
151151
&& serverErrorResult?.GetServerErrorType() != FaultInjectionServerErrorType.ResponseDelay
152-
&& serverErrorResult?.GetServerErrorType() != FaultInjectionServerErrorType.SendDelay)
152+
&& serverErrorResult?.GetServerErrorType() != FaultInjectionServerErrorType.SendDelay
153+
&& serverErrorResult?.GetServerErrorType() != FaultInjectionServerErrorType.DatabaseAccountNotFound
154+
&& serverErrorResult?.GetServerErrorType() != FaultInjectionServerErrorType.ServiceUnavailable
155+
&& serverErrorResult?.GetServerErrorType() != FaultInjectionServerErrorType.InternalServerError
156+
&& serverErrorResult?.GetServerErrorType() != FaultInjectionServerErrorType.LeaseNotFound)
153157
{
154158
throw new ArgumentException($"{serverErrorResult?.GetServerErrorType()} is not supported for metadata requests.");
155159
}

Microsoft.Azure.Cosmos/FaultInjection/src/FaultInjectionServerErrorType.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,13 @@ public enum FaultInjectionServerErrorType
7272
ServiceUnavailable,
7373

7474
/// <summary>
75-
/// 404:1008 Database account not found from gateway
75+
/// 403:1008 Database account not found from gateway
7676
/// </summary>
7777
DatabaseAccountNotFound,
78+
79+
/// <summary>
80+
/// 410:1022 Lease not Found
81+
/// </summary>
82+
LeaseNotFound,
7883
}
7984
}

Microsoft.Azure.Cosmos/FaultInjection/src/implementation/FaultInjectionServerErrorResultInternal.cs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ public HttpResponseMessage GetInjectedServerError(DocumentServiceRequest dsr, st
461461

462462
httpResponse.Headers.Add(
463463
WFConstants.BackendHeaders.SubStatus,
464-
((int)SubStatusCodes.RUBudgetExceeded).ToString(CultureInfo.InvariantCulture));
464+
((int)SubStatusCodes.Unknown).ToString(CultureInfo.InvariantCulture));
465465
httpResponse.Headers.Add(WFConstants.BackendHeaders.LocalLSN, lsn);
466466

467467
return httpResponse;
@@ -470,7 +470,7 @@ public HttpResponseMessage GetInjectedServerError(DocumentServiceRequest dsr, st
470470

471471
httpResponse = new HttpResponseMessage
472472
{
473-
StatusCode = HttpStatusCode.NotFound,
473+
StatusCode = HttpStatusCode.Forbidden,
474474
Content = new FauntInjectionHttpContent(
475475
new MemoryStream(
476476
FaultInjectionResponseEncoding.GetBytes($"Fault Injection Server Error: DatabaseAccountNotFound, rule: {ruleId}"))),
@@ -488,6 +488,28 @@ public HttpResponseMessage GetInjectedServerError(DocumentServiceRequest dsr, st
488488

489489
return httpResponse;
490490

491+
case FaultInjectionServerErrorType.LeaseNotFound:
492+
493+
httpResponse = new HttpResponseMessage
494+
{
495+
StatusCode = HttpStatusCode.Gone,
496+
Content = new FauntInjectionHttpContent(
497+
new MemoryStream(
498+
FaultInjectionResponseEncoding.GetBytes($"Fault Injection Server Error: LeaseNotFound, rule: {ruleId}"))),
499+
};
500+
501+
foreach (string header in headers.AllKeys())
502+
{
503+
httpResponse.Headers.Add(header, headers.Get(header));
504+
}
505+
506+
httpResponse.Headers.Add(
507+
WFConstants.BackendHeaders.SubStatus,
508+
((int)SubStatusCodes.LeaseNotFound).ToString(CultureInfo.InvariantCulture));
509+
httpResponse.Headers.Add(WFConstants.BackendHeaders.LocalLSN, lsn);
510+
511+
return httpResponse;
512+
491513
default:
492514
throw new ArgumentException($"Server error type {this.serverErrorType} is not supported");
493515
}

Microsoft.Azure.Cosmos/contracts/API_3.48.1.txt

Lines changed: 1703 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)