Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ internal sealed class MetadataRequestThrottleRetryPolicy : IDocumentClientRetryP
/// </summary>
private int unavailableEndpointRetryCount;

/// <summary>
/// The request being sent to the service.
/// </summary>
private DocumentServiceRequest request;

/// <summary>
/// The constructor to initialize an instance of <see cref="MetadataRequestThrottleRetryPolicy"/>.
/// </summary>
Expand Down Expand Up @@ -93,6 +98,12 @@ public Task<ShouldRetryResult> ShouldRetryAsync(
{
if (exception is CosmosException cosmosException)
{
DefaultTrace.TraceInformation("MetadataRequestThrottleRetryPolicy: Evaluating retry for CosmosException with StatusCode: {0}, SubStatusCode: {1}, ResourceType {2}, CollectionName {3}, ResourceID {4}.",
cosmosException.StatusCode,
cosmosException.SubStatusCode,
this.request.ResourceType,
this.request.CollectionName,
this.request.ResourceId);
return this.ShouldRetryInternalAsync(
cosmosException.StatusCode,
(SubStatusCodes)cosmosException.SubStatusCode,
Expand All @@ -102,11 +113,27 @@ public Task<ShouldRetryResult> ShouldRetryAsync(

if (exception is DocumentClientException clientException)
{
DefaultTrace.TraceInformation("MetadataRequestThrottleRetryPolicy: Evaluating retry for DocumentClientException with StatusCode: {0}, SubStatusCode: {1}, ResourceType {2}, CollectionName {3}, ResourceID {4}",
clientException.StatusCode,
clientException.GetSubStatus(),
this.request.ResourceType,
this.request.CollectionName,
this.request.ResourceId);
return this.ShouldRetryInternalAsync(
clientException.StatusCode,
clientException.GetSubStatus(),
exception, cancellationToken);
}
else
{
DefaultTrace.TraceInformation("MetadataRequestThrottleRetryPolicy: Evaluating retry for Exception of type: {0}, Message: {1}, ResourceType {2}, CollectionName {3}, ResourceID {4}",
exception.GetType().Name,
exception.Message,
this.request.ResourceType,
this.request.CollectionName,
this.request.ResourceId);

}

return this.throttlingRetryPolicy.ShouldRetryAsync(exception, cancellationToken);
}
Expand Down Expand Up @@ -186,14 +213,20 @@ private Task<ShouldRetryResult> ShouldRetryInternalAsync(
public void OnBeforeSendRequest(DocumentServiceRequest request)
{
// Clear the previous location-based routing directive.
this.request = request;
request.RequestContext.ClearRouteToLocation();
request.RequestContext.RouteToLocation(
this.retryContext.RetryLocationIndex,
this.retryContext.RetryRequestOnPreferredLocations);

Uri metadataLocationEndpoint = this.globalEndpointManager.ResolveServiceEndpoint(request);

DefaultTrace.TraceInformation("MetadataRequestThrottleRetryPolicy: Routing the metadata request to: {0} for operation type: {1} and resource type: {2}.", metadataLocationEndpoint, request.OperationType, request.ResourceType);
DefaultTrace.TraceInformation("MetadataRequestThrottleRetryPolicy: Routing the metadata request to: {0} for operation type: {1} and resource type: {2} for collection: {3} with collection rid {4}.",
metadataLocationEndpoint,
request.OperationType,
request.ResourceType,
request.CollectionName,
request.ResourceId);
request.RequestContext.RouteToLocation(metadataLocationEndpoint);
}

Expand Down
10 changes: 10 additions & 0 deletions Microsoft.Azure.Cosmos/src/Routing/PartitionKeyRangeCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,16 @@ private async Task<CollectionRoutingMap> GetRoutingMapForCollectionAsync(
lastStatusCode = response.StatusCode;
changeFeedNextIfNoneMatch = response.Headers[HttpConstants.HttpHeaders.ETag];

DefaultTrace.TraceInformation("PartitionKeyRangeCache GetRoutingMapForCollectionAsync collectionRid: {0}, StatusCode: {1}, SubstatusCode {2}, request Etag {3}, response ETag: {4}, RegionsContacted {5}",
collectionRid,
lastStatusCode,
response.GetSubStatusCodes(),
headers.GetHeaderValue<string>(HttpConstants.HttpHeaders.IfNoneMatch),
changeFeedNextIfNoneMatch,
response.RequestStats?.RegionsContacted != null
? string.Join(", ", response.RequestStats.RegionsContacted)
: string.Empty);

FeedResource<PartitionKeyRange> feedResource = response.GetResource<FeedResource<PartitionKeyRange>>();
if (feedResource != null)
{
Expand Down