Skip to content
Open
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
11 changes: 11 additions & 0 deletions Microsoft.Azure.Cosmos/src/Handler/RequestInvokerHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,9 @@ private async Task ValidateAndSetConsistencyLevelAsync(RequestMessage requestMes

/// <summary>
/// Validate and set the ReadConsistencyStrategy header.
/// When the strategy is LastCommittedWriteRegion and the operation is a read,
/// also set the hub region processing header so the backend routes the request
/// to the hub (write) region.
/// </summary>
private Task ValidateAndSetReadConsistencyStrategyAsync(RequestMessage requestMessage)
{
Expand All @@ -529,6 +532,14 @@ private Task ValidateAndSetReadConsistencyStrategyAsync(RequestMessage requestMe
requestMessage.Headers.Set(
HttpConstants.HttpHeaders.ReadConsistencyStrategy,
readConsistencyStrategy.Value.ToString());

if (readConsistencyStrategy.Value == Cosmos.ReadConsistencyStrategy.LastCommittedWriteRegion
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Recommendation — Design: Consider interaction with CrossRegionHedgingAvailabilityStrategy

When CrossRegionHedgingAvailabilityStrategy and LastCommittedWriteRegion are both active, the hedging strategy clones the request (including the ShouldProcessOnlyInHubRegion header) and sends copies to multiple regions in parallel. Non-hub regions will return 403/3, which IsFinalResult() does NOT treat as final — so each hedged copy retries internally, generating cascading 403/3 traffic.

Concrete scenario: 3-region account with hedging enabled + LastCommittedWriteRegion read → 3 parallel requests → 2 get 403/3 and retry → generates ~5+ backend requests for one logical read, with wasted RUs and added latency.

Why it matters: The combination is semantically contradictory — hedging spreads across regions, but hub-only routing rejects all non-hub regions. This isn't a correctness bug (it eventually converges), but it's wasteful and could confuse diagnostics.

Suggestion: Either:

  1. Add a check in ShouldHedge to skip hedging when ShouldProcessOnlyInHubRegion is set, or
  2. Document this as an unsupported combination, or
  3. At minimum, add a code comment noting this interaction for future maintainers.

⚠️ AI-generated review — may be incorrect. Agree? → resolve the conversation. Disagree? → reply with your reasoning.

&& OperationTypeExtensions.IsReadOperation(requestMessage.OperationType))
{
requestMessage.Headers.Set(
HttpConstants.HttpHeaders.ShouldProcessOnlyInHubRegion,
bool.TrueString);
}
}

return Task.CompletedTask;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ enum ReadConsistencyStrategy
/// Quorum read with GCLSN barrier - returns the latest version across all regions.
/// Only valid for accounts configured with Strong consistency.
/// </summary>
GlobalStrong = 4
GlobalStrong = 4,

/// <summary>
Comment thread
aavasthy marked this conversation as resolved.
/// Returns the latest committed version from the hub (write) region, ensuring reads
/// reflect the most recent writes regardless of which region the client is connected to.
/// </summary>
LastCommittedWriteRegion = 5
Comment thread
aavasthy marked this conversation as resolved.
}
}
Loading
Loading