-
Notifications
You must be signed in to change notification settings - Fork 494
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* creating executor * Adding public API * Updating contract * Adding ToResponseMessage * Wiring to executor * Mockable executor * Itemrequestoptions to batchitemrequestoptions * cleanup * Tests * Wiring to executor * Unit tests on executor * Emulator tests on container * executor retry handler * Retry tests * Handler tests * under preview * else * Upsert support * Using ResourceThrottleRetryPolicy * Generating new context on retry * Correctly obtaining retrypolicy * Fixing unrelated test * Removing unneeded constants * Fixing conflict tests * Replace and Delete support * Adding Read support * private instead of internal * Fix for Read and DeleteItemAsync * Typed API support * Rename property * Rename * Refactor on ClientContext * Refactoring through policies and batcher * ItemId is required * Undo unnecessary changes * Rename * Undoing comment * Description * Renaming variable * Fixing test * Rename
- Loading branch information
1 parent
b2f8f82
commit 272aa1e
Showing
26 changed files
with
1,318 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
Microsoft.Azure.Cosmos/src/BulkPartitionKeyRangeGoneRetryPolicy.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
//------------------------------------------------------------ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
//------------------------------------------------------------ | ||
|
||
namespace Microsoft.Azure.Cosmos | ||
{ | ||
using System; | ||
using System.Net; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.Azure.Documents; | ||
|
||
/// <summary> | ||
/// Used only in the context of Bulk Stream operations. | ||
/// </summary> | ||
/// <see cref="BatchAsyncBatcher"/> | ||
/// <see cref="ItemBatchOperationContext"/> | ||
internal sealed class BulkPartitionKeyRangeGoneRetryPolicy : IDocumentClientRetryPolicy | ||
{ | ||
private const int MaxRetries = 1; | ||
|
||
private readonly IDocumentClientRetryPolicy nextRetryPolicy; | ||
|
||
private int retriesAttempted; | ||
|
||
public BulkPartitionKeyRangeGoneRetryPolicy(IDocumentClientRetryPolicy nextRetryPolicy) | ||
{ | ||
this.nextRetryPolicy = nextRetryPolicy; | ||
} | ||
|
||
public Task<ShouldRetryResult> ShouldRetryAsync( | ||
Exception exception, | ||
CancellationToken cancellationToken) | ||
{ | ||
DocumentClientException clientException = exception as DocumentClientException; | ||
|
||
ShouldRetryResult shouldRetryResult = this.ShouldRetryInternal( | ||
clientException?.StatusCode, | ||
clientException?.GetSubStatus(), | ||
clientException?.ResourceAddress); | ||
|
||
if (shouldRetryResult != null) | ||
{ | ||
return Task.FromResult(shouldRetryResult); | ||
} | ||
|
||
if (this.nextRetryPolicy == null) | ||
{ | ||
return Task.FromResult(ShouldRetryResult.NoRetry()); | ||
} | ||
|
||
return this.nextRetryPolicy.ShouldRetryAsync(exception, cancellationToken); | ||
} | ||
|
||
public Task<ShouldRetryResult> ShouldRetryAsync( | ||
ResponseMessage cosmosResponseMessage, | ||
CancellationToken cancellationToken) | ||
{ | ||
ShouldRetryResult shouldRetryResult = this.ShouldRetryInternal(cosmosResponseMessage?.StatusCode, | ||
cosmosResponseMessage?.Headers.SubStatusCode, | ||
cosmosResponseMessage?.GetResourceAddress()); | ||
if (shouldRetryResult != null) | ||
{ | ||
return Task.FromResult(shouldRetryResult); | ||
} | ||
|
||
if (this.nextRetryPolicy == null) | ||
{ | ||
return Task.FromResult(ShouldRetryResult.NoRetry()); | ||
} | ||
|
||
return this.nextRetryPolicy.ShouldRetryAsync(cosmosResponseMessage, cancellationToken); | ||
} | ||
|
||
public void OnBeforeSendRequest(DocumentServiceRequest request) | ||
{ | ||
this.nextRetryPolicy.OnBeforeSendRequest(request); | ||
} | ||
|
||
private ShouldRetryResult ShouldRetryInternal( | ||
HttpStatusCode? statusCode, | ||
SubStatusCodes? subStatusCode, | ||
string resourceIdOrFullName) | ||
{ | ||
if (statusCode == HttpStatusCode.Gone | ||
&& subStatusCode == SubStatusCodes.PartitionKeyRangeGone | ||
&& this.retriesAttempted < MaxRetries) | ||
{ | ||
this.retriesAttempted++; | ||
return ShouldRetryResult.RetryAfter(TimeSpan.Zero); | ||
} | ||
|
||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.