Skip to content
Draft
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
f10aef0
Add hub region caching per partition
aavasthy Mar 3, 2026
201f9c7
Merge branch 'master' into users/aavasthy/hubregioncaching
aavasthy Mar 3, 2026
a557e94
Fix failing test.
aavasthy Mar 3, 2026
6dc169c
Merge with master
aavasthy Mar 3, 2026
ea409d2
Add hub region caching per partition
aavasthy Mar 10, 2026
19f9c15
Merge branch 'master' into users/aavasthy/hubregioncaching
aavasthy Mar 10, 2026
02f6f73
Merge branch 'master' into users/aavasthy/hubregioncaching
aavasthy Mar 10, 2026
2108e6e
Merge branch 'master' into users/aavasthy/hubregioncaching
kirankumarkolli Mar 11, 2026
7e63138
Update logic for hub region caching
aavasthy Mar 18, 2026
e50ffd8
Remove unused line in GlobalPartitionEndpointManager
aavasthy Mar 18, 2026
f0fd1a3
Update logic for hub region caching
aavasthy Mar 24, 2026
a09ba1f
merge with master
aavasthy Mar 24, 2026
6159a85
Merge branch 'master' into users/aavasthy/hubregioncaching
aavasthy Mar 24, 2026
8e13fd4
code cleanup
aavasthy Mar 25, 2026
e1944b0
Merge branch 'master' into users/aavasthy/hubregioncaching
aavasthy Mar 30, 2026
14b123c
[Internal] HubRegionRouting: Fixes Logic for Per Partition Hub Region…
kundadebdatta Apr 6, 2026
4303e5c
Add more tests for 403/3 scenarios
aavasthy Apr 7, 2026
77c3724
Fix tests
aavasthy Apr 7, 2026
a389677
Add a feature flag for hub region header feature
aavasthy Apr 8, 2026
79355c6
Merge branch 'master' into users/aavasthy/hubregioncaching
aavasthy Apr 8, 2026
1c357ad
merge with master
aavasthy Apr 8, 2026
2590d19
Fix test
aavasthy Apr 8, 2026
1d4fbe5
Resolve conflicts
aavasthy Apr 8, 2026
48292bb
Merge branch 'master' into users/aavasthy/hubregioncaching
kundadebdatta Apr 8, 2026
89edb23
Fix test and address review comments.
aavasthy Apr 9, 2026
fe6e724
merge with master
aavasthy Apr 9, 2026
e73958c
Fix tests
aavasthy Apr 9, 2026
65ebd06
Fix tests
aavasthy Apr 9, 2026
f2641d5
Merge branch 'master' into users/aavasthy/hubregioncaching
aavasthy Apr 9, 2026
2b47c9a
Remove white spacing
aavasthy Apr 10, 2026
44c613b
Code changes to add request property for hub processing. Added and up…
kundadebdatta Apr 10, 2026
b87717e
Merge branch 'master' into users/aavasthy/hubregioncaching
aavasthy Apr 10, 2026
644e456
Code changes to structure better and few minor cleanups.
kundadebdatta Apr 10, 2026
2c55d45
More clean ups.
kundadebdatta Apr 10, 2026
cfd5701
Code changes to fix tests.
kundadebdatta Apr 11, 2026
48e6937
Code changes to fix failing tests.
kundadebdatta Apr 11, 2026
df20bbe
Code changes to fix c# pre-processor ordering in gpem no-op.
kundadebdatta Apr 11, 2026
742eb3e
Code changes to fix failing test.
kundadebdatta Apr 11, 2026
b7f96ee
Merge branch 'master' into users/aavasthy/hubregioncaching
kundadebdatta Apr 11, 2026
958dbd2
Code changes to simplify the pk range based routing for hub region pr…
kundadebdatta Apr 15, 2026
326ff1f
Merge branch 'master' into users/aavasthy/hubregioncaching
kundadebdatta Apr 15, 2026
010c2d2
Code changes to optimize the hub region discovery lookup.
kundadebdatta Apr 15, 2026
227193b
Minor code cleanup
kundadebdatta Apr 15, 2026
3a3b680
Removing unnecessary changes.
kundadebdatta Apr 15, 2026
8a22bbc
Code changes to fix white space diffs.
kundadebdatta Apr 15, 2026
bce3222
Code changes to fix the retry logic with hub region override.
kundadebdatta Apr 15, 2026
ae0a771
Code changes to fix the contract test failures.
kundadebdatta Apr 15, 2026
10f3124
Merge branch 'master' into users/aavasthy/hubregioncaching
kundadebdatta Apr 15, 2026
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
238 changes: 164 additions & 74 deletions Microsoft.Azure.Cosmos/src/ClientRetryPolicy.cs

Large diffs are not rendered by default.

15 changes: 8 additions & 7 deletions Microsoft.Azure.Cosmos/src/GatewayStoreModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,10 @@ await GatewayStoreModel.ApplySessionTokenAsync(
request.RequestContext.RegionName = regionName;
}

bool isPPAFEnabled = this.IsPartitionLevelFailoverEnabled();
// This is applicable for both per partition automatic failover and per partition circuit breaker.
if ((isPPAFEnabled || this.isThinClientEnabled)
bool isPPAFEnabled = this.IsPartitionLevelFailoverEnabled();
// This is applicable for both per partition automatic failover and per partition circuit breaker.
bool isHubRegionRoutingActive = GlobalPartitionEndpointManagerCore.IsHubRegionRoutingActive(request);
if ((isPPAFEnabled || this.isThinClientEnabled || isHubRegionRoutingActive)
&& !ReplicatedResourceClient.IsMasterResource(request.ResourceType)
&& (request.ResourceType.IsPartitioned() || request.ResourceType == ResourceType.StoredProcedure))
{
Expand All @@ -114,12 +115,12 @@ await GatewayStoreModel.ApplySessionTokenAsync(
clientCollectionCache: this.clientCollectionCache,
refreshCache: false);

request.RequestContext.ResolvedPartitionKeyRange = partitionKeyRange;
request.RequestContext.ResolvedPartitionKeyRange = partitionKeyRange;

if (isPPAFEnabled)
if (isPPAFEnabled || isHubRegionRoutingActive)
{
this.globalPartitionEndpointManager.TryAddPartitionLevelLocationOverride(request);
}
this.globalPartitionEndpointManager.TryAddPartitionLevelLocationOverride(request, isHubRegionRoutingActive);
}
}

bool canUseThinClient =
Expand Down
4 changes: 2 additions & 2 deletions Microsoft.Azure.Cosmos/src/Routing/GlobalAddressResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,8 @@ public async Task<PartitionAddressInformation> ResolveAsync(
{
IAddressResolver resolver = this.GetAddressResolver(request);
PartitionAddressInformation partitionAddressInformation = await resolver.ResolveAsync(request, forceRefresh, cancellationToken);

if (!this.partitionKeyRangeLocationCache.TryAddPartitionLevelLocationOverride(request))
bool isHubRegionRoutingActive = GlobalPartitionEndpointManagerCore.IsHubRegionRoutingActive(request);
if (!this.partitionKeyRangeLocationCache.TryAddPartitionLevelLocationOverride(request, isHubRegionRoutingActive))
{
return partitionAddressInformation;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,18 @@ namespace Microsoft.Azure.Cosmos.Routing

internal abstract class GlobalPartitionEndpointManager
{
/// <summary>
/// A constant string representing if hub region override is present in the pk range to location cache for a request.
/// </summary>
public const string HubRegionOverridePresentInCache = "x-ms-hub-region-override-active";

/// <summary>
/// Updates the DocumentServiceRequest routing location to point
/// new a location based if a partition level failover occurred
/// </summary>
public abstract bool TryAddPartitionLevelLocationOverride(
DocumentServiceRequest request);
DocumentServiceRequest request,
bool checkHubRegionOverrideInCache = false);

/// <summary>
/// Marks the current location unavailable for write. Future
Expand Down Expand Up @@ -79,5 +85,14 @@ public abstract void SetBackgroundConnectionPeriodicRefreshTask(
/// Returns true if circuit breaker logic for partition key ranges is active, otherwise false.
/// </summary>
public abstract bool IsPartitionLevelCircuitBreakerEnabled();

#if !INTERNAL
/// <summary>
/// Gets a value indicating whether hub region processing is enabled for read requests
/// encountering repeated 404/1002 (ReadSessionNotAvailable) errors on single-master accounts.
/// Returns true if hub region header attachment and hub region discovery are active, otherwise false.
/// </summary>
public abstract bool IsHubRegionProcessingEnabled();
#endif
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ public override void SetBackgroundConnectionPeriodicRefreshTask(
}

public override bool TryAddPartitionLevelLocationOverride(
DocumentServiceRequest request)
DocumentServiceRequest request,
bool checkHubRegionOverrideInCache = false)
{
return false;
}
Expand Down Expand Up @@ -70,5 +71,12 @@ public override bool IsPartitionLevelCircuitBreakerEnabled()
{
return false;
}

#if !INTERNAL
public override bool IsHubRegionProcessingEnabled()
{
return false;
}
#endif
}
}
25 changes: 25 additions & 0 deletions Microsoft.Azure.Cosmos/src/Util/ConfigurationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ internal static class ConfigurationManager
/// </summary>
internal static readonly string HybridSearchQueryPlanOptimizationDisabled = "AZURE_COSMOS_HYBRID_SEARCH_QUERYPLAN_OPTIMIZATION_DISABLED";

/// <summary>
/// A read-only string containing the environment variable name for enabling hub region processing for read requests.
/// When enabled (default), the SDK attaches a hub region header to read requests that encounter repeated 404/1002
/// (ReadSessionNotAvailable) errors, allowing the hub region to process the request directly. When disabled, the
/// SDK falls back to the original retry behavior without hub region header attachment.
/// </summary>
internal static readonly string HubRegionProcessingEnabled = "AZURE_COSMOS_HUB_REGION_PROCESSING_ENABLED";

/// <summary>
/// Environment variable name to enable distributed query gateway mode.
/// </summary>
Expand Down Expand Up @@ -426,5 +434,22 @@ public static bool IsTcpDnsDotSuffixEnabled()
variable: ConfigurationManager.TcpDnsDotSuffixEnabled,
defaultValue: false);
}

/// <summary>
/// Gets the boolean value indicating if hub region processing is enabled for read requests
/// encountering repeated 404/1002 (ReadSessionNotAvailable) errors on single-master accounts.
/// When enabled, the SDK attaches a hub region header to route read requests to the hub region
/// for authoritative partition resolution. When disabled, the SDK falls back to the original
/// retry behavior (route to write region and give up after two 404/1002 attempts).
/// Default: true.
/// </summary>
/// <returns>A boolean flag indicating if hub region processing is enabled.</returns>
public static bool IsHubRegionProcessingEnabled()
{
return ConfigurationManager
.GetEnvironmentVariable(
variable: ConfigurationManager.HubRegionProcessingEnabled,
defaultValue: true);
}
}
}
Loading
Loading