Skip to content

Routing: Fixes LengthAware comparer wiring across env var and cold-start CollectionRoutingMap paths#5866

Merged
ananth7592 merged 3 commits into
mainfrom
users/amudumba/hotfix-lengthaware-envvar-knob
Jun 5, 2026
Merged

Routing: Fixes LengthAware comparer wiring across env var and cold-start CollectionRoutingMap paths#5866
ananth7592 merged 3 commits into
mainfrom
users/amudumba/hotfix-lengthaware-envvar-knob

Conversation

@ananth7592
Copy link
Copy Markdown
Member

Summary

Wires \AZURE_COSMOS_USE_LENGTH_AWARE_RANGE_COMPARATOR\ env var to all LengthAware usage sites so customers can disable it as a mitigation for the HPK silent empty query issue (#5859).

Problem

Two disconnected controls existed for the LengthAware range comparer:

  1. \CosmosClientOptions.UseLengthAwareRangeComparer\ — hardcoded true for GA/Preview, controlled TryCombine (the bug path), NOT wired to env var
  2. \ConfigurationManager.IsLengthAwareRangeComparatorEnabled()\ — read env var but only defaulted true in PREVIEW, no effect in GA

Changes

ConfigurationManager.IsLengthAwareRangeComparatorEnabled()

  • Default: true in all non-INTERNAL builds (was PREVIEW-only). INTERNAL stays false.
  • \AZURE_COSMOS_USE_LENGTH_AWARE_RANGE_COMPARATOR\ env var now effective in GA SDK.

CosmosClientOptions.UseLengthAwareRangeComparer

  • Replaced hardcoded #if !INTERNAL\ literal with \ConfigurationManager.IsLengthAwareRangeComparatorEnabled()\
  • Wires \PartitionKeyRangeCache.TryCombine\ to the env var

All LengthAware sites unified under single env var

Code path Before After
\PartitionKeyRangeCache.TryCombine\ not wired wired
\QueryRangeUtils\ PREVIEW only GA + PREVIEW
\PartitionRoutingHelper\ PREVIEW only GA + PREVIEW

Customer Mitigation

Set \AZURE_COSMOS_USE_LENGTH_AWARE_RANGE_COMPARATOR=false\ to disable LengthAware routing.

Related: #5859, #5850

- ConfigurationManager.IsLengthAwareRangeComparatorEnabled() now defaults
  true in all non-INTERNAL builds (was only true in PREVIEW). This makes
  AZURE_COSMOS_USE_LENGTH_AWARE_RANGE_COMPARATOR=false work in GA SDK.
- CosmosClientOptions.UseLengthAwareRangeComparer now reads from
  ConfigurationManager instead of a hardcoded #if !INTERNAL literal.
  This wires PartitionKeyRangeCache.TryCombine to the env var so all
  three LengthAware usage sites (TryCombine, QueryRangeUtils,
  PartitionRoutingHelper) can be disabled via a single env var.

Customer mitigation: set AZURE_COSMOS_USE_LENGTH_AWARE_RANGE_COMPARATOR=false
to disable LengthAware routing and avoid silent empty query results on HPK
containers after a partition split.

Fixes: #5859

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@ananth7592 ananth7592 changed the title Routing: Fixes LengthAware comparer not controllable via env var in GA SDK [WIP]Routing: Fixes LengthAware comparer not controllable via env var in GA SDK May 14, 2026
@ananth7592 ananth7592 force-pushed the users/amudumba/hotfix-lengthaware-envvar-knob branch from fee1997 to 03314d4 Compare June 5, 2026 16:26
Covers the AZURE_COSMOS_USE_LENGTH_AWARE_RANGE_COMPARATOR env var end-to-end:
ConfigurationManager -> CosmosClientOptions -> CosmosClient -> DocumentClient.

3 parametric tests (10 invocations):
 - ConfigurationManager.IsLengthAwareRangeComparatorEnabled() for unset / false / true
 - CosmosClientOptions default for unset / false / true
 - Real CosmosClient construction for unset / false / true and explicit-option-wins

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@ananth7592 ananth7592 force-pushed the users/amudumba/hotfix-lengthaware-envvar-knob branch from 03314d4 to 06e6653 Compare June 5, 2026 16:32
…ingMap

PR #5551 wired CosmosClientOptions.UseLengthAwareRangeComparer
to the TryCombine refresh callsite in PartitionKeyRangeCache but
left a hardcoded false at the cold-start TryCreateCompleteRoutingMap
callsite. That meant the first CollectionRoutingMap for every
container in every CosmosClient was always built with the regular
Range<string>.MinComparer/MaxComparer regardless of the env var or
explicit option, since CollectionRoutingMap bakes the comparer
choice once at construction. This change propagates the configured
value to both callsites and pins the cold-start contract with a
parametric reflection-based regression test.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@ananth7592 ananth7592 changed the title [WIP]Routing: Fixes LengthAware comparer not controllable via env var in GA SDK [WIP]Routing: Fixes LengthAware comparer wiring across env var and cold-start CollectionRoutingMap paths Jun 5, 2026
@ananth7592 ananth7592 changed the title [WIP]Routing: Fixes LengthAware comparer wiring across env var and cold-start CollectionRoutingMap paths Routing: Fixes LengthAware comparer wiring across env var and cold-start CollectionRoutingMap paths Jun 5, 2026
Copy link
Copy Markdown
Member

@kundadebdatta kundadebdatta left a comment

Choose a reason for hiding this comment

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

LGTM

@ananth7592 ananth7592 enabled auto-merge (squash) June 5, 2026 21:36
Copy link
Copy Markdown
Member

@FabianMeiswinkel FabianMeiswinkel left a comment

Choose a reason for hiding this comment

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

LGTM

@ananth7592 ananth7592 merged commit e45ca19 into main Jun 5, 2026
35 checks passed
@ananth7592 ananth7592 deleted the users/amudumba/hotfix-lengthaware-envvar-knob branch June 5, 2026 21:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants