Skip to content

Commit 3e36025

Browse files
committed
Revert "Propagate hub region header to hedged requests via shared state"
This reverts commit dd41d00.
1 parent dd41d00 commit 3e36025

4 files changed

Lines changed: 6 additions & 152 deletions

File tree

Microsoft.Azure.Cosmos/src/ClientRetryPolicy.cs

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -228,21 +228,11 @@ public void OnBeforeSendRequest(DocumentServiceRequest request)
228228
}
229229
}
230230
#if !INTERNAL
231-
// If previous attempt failed with 404/1002, add the hub-region-processing-only header to all subsequent retry attempts.
232-
// Also check the shared state for hedged requests — another request in the same operation
233-
// may have already discovered that the hub header is needed.
234-
bool shouldAddHeader = this.addHubRegionProcessingOnlyHeader;
235-
if (!shouldAddHeader
236-
&& request.Properties != null
237-
&& request.Properties.TryGetValue(HubRegionProcessingState.RequestPropertyKey, out object sharedState))
238-
{
239-
shouldAddHeader = ((HubRegionProcessingState)sharedState).ShouldAddHubRegionProcessingOnlyHeader;
240-
}
241-
242-
if (shouldAddHeader)
243-
{
244-
request.Headers[HttpConstants.HttpHeaders.ShouldProcessOnlyInHubRegion] = bool.TrueString;
245-
}
231+
// If previous attempt failed with 404/1002, add the hub-region-processing-only header to all subsequent retry attempts
232+
if (this.addHubRegionProcessingOnlyHeader)
233+
{
234+
request.Headers[HttpConstants.HttpHeaders.ShouldProcessOnlyInHubRegion] = bool.TrueString;
235+
}
246236
#endif
247237
// Resolve the endpoint for the request and pin the resolution to the resolved endpoint
248238
// This enables marking the endpoint unavailability on endpoint failover/unreachability
@@ -466,15 +456,6 @@ private ShouldRetryResult ShouldRetryOnSessionNotAvailable(DocumentServiceReques
466456
if (this.sessionTokenRetryCount >= MaxSessionTokenRetryCount)
467457
{
468458
this.addHubRegionProcessingOnlyHeader = true;
469-
470-
// Signal shared state so hedged requests in the same operation
471-
// can immediately include the hub header without their own 2x 404/1002 cycle.
472-
if (this.documentServiceRequest?.Properties != null
473-
&& this.documentServiceRequest.Properties.TryGetValue(
474-
HubRegionProcessingState.RequestPropertyKey, out object sharedState))
475-
{
476-
((HubRegionProcessingState)sharedState).ShouldAddHubRegionProcessingOnlyHeader = true;
477-
}
478459
}
479460

480461
if (this.sessionTokenRetryCount > MaxSessionTokenRetryCount)

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

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -138,17 +138,7 @@ internal override async Task<ResponseMessage> ExecuteAvailabilityStrategyAsync(
138138
{
139139
return await sender(request, applicationProvidedCancellationToken);
140140
}
141-
142-
#if !INTERNAL
143-
// Inject shared hub region state so all hedged clones can coordinate.
144-
// When one clone's retry discovers hub header is needed (after 2x 404/1002),
145-
// all subsequent clones inherit the header immediately via this shared reference.
146-
if (!request.Properties.ContainsKey(HubRegionProcessingState.RequestPropertyKey))
147-
{
148-
request.Properties[HubRegionProcessingState.RequestPropertyKey] = new HubRegionProcessingState();
149-
}
150-
#endif
151-
141+
152142
ITrace trace = request.Trace;
153143

154144
using (CancellationTokenSource hedgeRequestsCancellationTokenSource =

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

Lines changed: 0 additions & 31 deletions
This file was deleted.

Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/ClientRetryPolicyTests.cs

Lines changed: 0 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -673,92 +673,6 @@ public async Task ClientRetryPolicy_HubRegionHeader_PersistsThroughRetriableErro
673673
Assert.AreEqual(bool.TrueString, headerValues[0], "Hub region header value should remain 'True'.");
674674
}
675675

676-
/// <summary>
677-
/// Validates that the shared <see cref="HubRegionProcessingState"/> propagates the hub region
678-
/// header to a second (hedged) ClientRetryPolicy that shares the same Properties dictionary.
679-
/// Scenario:
680-
/// 1. Primary request hits 2x 404/1002 → sets shared state to true.
681-
/// 2. Hedged request (using the same Properties) checks OnBeforeSendRequest on its FIRST attempt.
682-
/// 3. Asserts the hub header is present immediately without the hedge needing its own 404/1002 cycle.
683-
/// </summary>
684-
[TestMethod]
685-
public async Task ClientRetryPolicy_HubRegionHeader_PropagatedToHedgedRequest_ViaSharedState()
686-
{
687-
const bool enableEndpointDiscovery = true;
688-
689-
using GlobalEndpointManager endpointManager = this.Initialize(
690-
useMultipleWriteLocations: false,
691-
enableEndpointDiscovery: enableEndpointDiscovery,
692-
isPreferredLocationsListEmpty: false,
693-
enforceSingleMasterSingleWriteLocation: true);
694-
695-
// Create shared properties (simulates what CrossRegionHedgingAvailabilityStrategy does)
696-
Dictionary<string, object> sharedProperties = new Dictionary<string, object>
697-
{
698-
[HubRegionProcessingState.RequestPropertyKey] = new HubRegionProcessingState()
699-
};
700-
701-
// ---- PRIMARY REQUEST: goes through 2x 404/1002 discovery ----
702-
ClientRetryPolicy primaryRetryPolicy = new ClientRetryPolicy(
703-
endpointManager,
704-
this.partitionKeyRangeLocationCache,
705-
new RetryOptions(),
706-
enableEndpointDiscovery,
707-
isThinClientEnabled: false);
708-
709-
DocumentServiceRequest primaryRequest = this.CreateRequest(isReadRequest: true, isMasterResourceType: false);
710-
primaryRequest.Properties = sharedProperties;
711-
712-
// 1st 404/1002
713-
primaryRetryPolicy.OnBeforeSendRequest(primaryRequest);
714-
ShouldRetryResult shouldRetry = await primaryRetryPolicy.ShouldRetryAsync(
715-
new DocumentClientException(
716-
message: "1st 404/1002",
717-
innerException: null,
718-
statusCode: HttpStatusCode.NotFound,
719-
substatusCode: SubStatusCodes.ReadSessionNotAvailable,
720-
requestUri: primaryRequest.RequestContext.LocationEndpointToRoute,
721-
responseHeaders: new DictionaryNameValueCollection()),
722-
CancellationToken.None);
723-
Assert.IsTrue(shouldRetry.ShouldRetry);
724-
725-
// 2nd 404/1002 → triggers shared state
726-
primaryRetryPolicy.OnBeforeSendRequest(primaryRequest);
727-
shouldRetry = await primaryRetryPolicy.ShouldRetryAsync(
728-
new DocumentClientException(
729-
message: "2nd 404/1002",
730-
innerException: null,
731-
statusCode: HttpStatusCode.NotFound,
732-
substatusCode: SubStatusCodes.ReadSessionNotAvailable,
733-
requestUri: primaryRequest.RequestContext.LocationEndpointToRoute,
734-
responseHeaders: new DictionaryNameValueCollection()),
735-
CancellationToken.None);
736-
Assert.IsTrue(shouldRetry.ShouldRetry);
737-
738-
// Verify shared state was signaled
739-
HubRegionProcessingState sharedState = (HubRegionProcessingState)sharedProperties[HubRegionProcessingState.RequestPropertyKey];
740-
Assert.IsTrue(sharedState.ShouldAddHubRegionProcessingOnlyHeader,
741-
"Shared state must be set to true after primary hits 2x 404/1002.");
742-
743-
// ---- HEDGED REQUEST: new retry policy, same shared Properties ----
744-
ClientRetryPolicy hedgeRetryPolicy = new ClientRetryPolicy(
745-
endpointManager,
746-
this.partitionKeyRangeLocationCache,
747-
new RetryOptions(),
748-
enableEndpointDiscovery,
749-
isThinClientEnabled: false);
750-
751-
DocumentServiceRequest hedgeRequest = this.CreateRequest(isReadRequest: true, isMasterResourceType: false);
752-
hedgeRequest.Properties = sharedProperties;
753-
754-
// Hedge's FIRST OnBeforeSendRequest — should immediately see hub header via shared state
755-
hedgeRetryPolicy.OnBeforeSendRequest(hedgeRequest);
756-
string[] headerValues = hedgeRequest.Headers.GetValues(HubRegionHeader);
757-
Assert.IsNotNull(headerValues,
758-
"Hedged request must have hub region header on its first attempt (propagated via shared state).");
759-
Assert.AreEqual(bool.TrueString, headerValues[0]);
760-
}
761-
762676
private async Task ValidateConnectTimeoutTriggersClientRetryPolicyAsync(
763677
bool isReadRequest,
764678
bool useMultipleWriteLocations,

0 commit comments

Comments
 (0)