Skip to content

[Cosmos] Feed Range API#4149

Merged
simorenoh merged 14 commits into
release/azure_data_cosmos-previewsfrom
port-feed-range
Apr 14, 2026
Merged

[Cosmos] Feed Range API#4149
simorenoh merged 14 commits into
release/azure_data_cosmos-previewsfrom
port-feed-range

Conversation

@simorenoh
Copy link
Copy Markdown
Member

This PR adds the FeedRange type and feed range APIs to azure_data_cosmos, enabling consumers to work with physical partition ranges. It uses the driver's EPK (Effective Partition Key) computation from PR #4087 for correct MultiHash (hierarchical partition key) support, including prefix partition keys.

Changes

sdk/cosmos/azure_data_cosmos/src/feed_range.rs (new)

New FeedRange type representing a contiguous [min, max) EPK range:

  • FeedRange::full() — the complete EPK space
  • contains() / overlaps() — containment and overlap checks
  • Display / FromStr — base64-encoded JSON serialization (cross-SDK compatible)
  • Serialize / Deserialize — structured JSON for embedding in documents
  • Runtime validation of inclusivity flags and min ≤ max ordering
  • 20 unit tests covering serialization, parsing, containment, overlap, and rejection paths

sdk/cosmos/azure_data_cosmos/src/clients/container_client.rs

Two new public methods on ContainerClient:

Method Return type Description
read_feed_ranges(options) Vec<FeedRange> Returns one feed range per physical partition
feed_range_from_partition_key(pk, options) Vec<FeedRange> Maps a partition key to its covering feed ranges

feed_range_from_partition_key handles three cases:

Input PK Definition Behavior
Full key (N of N components) Any DriverEpk::compute() → point lookup → 1 feed range
Prefix key (< N components) MultiHash DriverEpk::compute_range() → overlapping lookup → 1+ feed ranges
Prefix key (< N components) Hash (single) Error — prefix not supported

Both methods support ReadFeedRangesOptions::with_force_refresh() to bypass the routing map cache after partition splits.

sdk/cosmos/azure_data_cosmos/src/handler/container_connection.rs

Added three accessor methods:

  • partition_key_definition() — returns the PK definition from the eagerly-resolved ContainerReference
  • resolve_routing_map(force_refresh) — resolves the SDK-side routing map with optional cache bypass

sdk/cosmos/azure_data_cosmos/src/hash.rs

  • Added PartialOrd, Ord, Hash derives to EffectivePartitionKey (needed by FeedRange)
  • Added From<String> and From<&str> impls for EffectivePartitionKey
  • Made MIN_INCLUSIVE_EFFECTIVE_PARTITION_KEY / MAX_EXCLUSIVE_EFFECTIVE_PARTITION_KEY pub(crate) for reuse in feed_range.rs

sdk/cosmos/azure_data_cosmos_driver/src/models/ (visibility changes)

Made the following driver types public so the SDK can use them for EPK computation and routing:

  • effective_partition_key module → pub
  • partition_key_range module → pub
  • EffectivePartitionKey struct → pub
  • PartitionKeyRange struct → pub
  • PartitionKey::values()pub

sdk/cosmos/azure_data_cosmos/src/options/mod.rs

Added ReadFeedRangesOptions with with_force_refresh(bool) for cache bypass control.

sdk/cosmos/azure_data_cosmos/tests/emulator_tests/cosmos_feed_ranges.rs (new)

5 emulator integration tests:

Test What it validates
read_feed_ranges_returns_physical_partitions Returns ≥ 2 ranges with 11000 RU/s, non-overlapping, serializable
feed_range_from_partition_key_maps_correctly Full key → single range matching a physical partition, deterministic
feed_range_from_full_hpk_returns_single_range Full 3-component HPK → single range within full EPK space
feed_range_from_prefix_hpk_returns_ranges Prefix HPK (1-of-3, 2-of-3) → 1+ non-overlapping ranges
feed_range_from_partition_key_single_hash_full_key Regression: full key on single-hash container succeeds

Architecture Note

The feed range methods use a hybrid approach:

  • EPK computation → driver's EffectivePartitionKey::compute() / compute_range() (correct MultiHash support from PR #4087)
  • Routing map lookup → SDK-side PartitionKeyRangeCache (via ContainerConnection::resolve_routing_map())

This is because CosmosDriver does not yet expose a resolve_routing_map() method — the driver's PartitionKeyRangeCache exists but isn't wired into the driver struct. Once that infrastructure is added (tracked separately), the feed range methods will switch to the driver's routing map, eliminating the dual-cache situation.

Copilot AI review requested due to automatic review settings April 11, 2026 00:08
@simorenoh simorenoh requested a review from a team as a code owner April 11, 2026 00:08
@simorenoh simorenoh linked an issue Apr 11, 2026 that may be closed by this pull request
@github-actions github-actions Bot added the Cosmos The azure_cosmos crate label Apr 11, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new FeedRange abstraction and accompanying ContainerClient APIs to let azure_data_cosmos consumers reason about physical partition (EPK) ranges, leveraging the driver’s EPK computation for correct MultiHash / hierarchical partition key support.

Changes:

  • Introduces FeedRange with cross-SDK compatible serialization plus containment/overlap helpers.
  • Adds ContainerClient::{read_feed_ranges, feed_range_from_partition_key} with optional routing map cache bypass.
  • Exposes select driver model types/APIs (EPK + PK range + PK values) needed by the SDK implementation and adds emulator + unit test coverage.

Reviewed changes

Copilot reviewed 15 out of 16 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
sdk/cosmos/azure_data_cosmos/tests/emulator_tests/mod.rs Registers the new feed range emulator test module.
sdk/cosmos/azure_data_cosmos/tests/emulator_tests/cosmos_feed_ranges.rs Adds emulator integration tests for reading feed ranges and PK→range mapping (including HPK prefix cases).
sdk/cosmos/azure_data_cosmos/src/options/mod.rs Adds ReadFeedRangesOptions with force_refresh support.
sdk/cosmos/azure_data_cosmos/src/lib.rs Wires in the new feed_range module and re-exports FeedRange.
sdk/cosmos/azure_data_cosmos/src/hash.rs Extends internal EffectivePartitionKey capabilities (ordering/hash + conversions) and shares EPK boundary constants.
sdk/cosmos/azure_data_cosmos/src/handler/container_connection.rs Adds accessors for PK definition and routing map resolution (with optional refresh).
sdk/cosmos/azure_data_cosmos/src/feed_range.rs New FeedRange type with serialization/parsing and range relationship helpers + unit tests.
sdk/cosmos/azure_data_cosmos/src/clients/container_client.rs Adds read_feed_ranges + feed_range_from_partition_key APIs using routing map + driver EPK computation.
sdk/cosmos/azure_data_cosmos/CHANGELOG.md Documents the new FeedRange API surface.
sdk/cosmos/azure_data_cosmos/Cargo.toml Adds the base64 dependency for FeedRange string serialization.
sdk/cosmos/azure_data_cosmos_driver/src/models/partition_key.rs Makes PartitionKey::values() public for SDK-side EPK computation.
sdk/cosmos/azure_data_cosmos_driver/src/models/partition_key_range.rs Makes PartitionKeyRange public.
sdk/cosmos/azure_data_cosmos_driver/src/models/mod.rs Exposes effective_partition_key and partition_key_range modules publicly.
sdk/cosmos/azure_data_cosmos_driver/src/models/effective_partition_key.rs Makes driver EffectivePartitionKey public.
sdk/cosmos/.cspell.json Updates spellchecker allowlist for new terminology.
Cargo.lock Locks the added base64 dependency.

Comment thread sdk/cosmos/azure_data_cosmos/src/feed_range.rs Outdated
Comment thread sdk/cosmos/azure_data_cosmos/src/feed_range.rs Outdated
@simorenoh
Copy link
Copy Markdown
Member Author

/azp run rust - cosmos - weekly

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@simorenoh
Copy link
Copy Markdown
Member Author

/azp run rust - cosmos - weekly

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

Comment thread sdk/cosmos/azure_data_cosmos/src/clients/container_client.rs Outdated
@github-project-automation github-project-automation Bot moved this from Todo to Changes Requested in CosmosDB Go/Rust Crew Apr 13, 2026
Comment thread sdk/cosmos/azure_data_cosmos/src/clients/container_client.rs
@simorenoh simorenoh requested a review from analogrelay April 13, 2026 20:03
@simorenoh
Copy link
Copy Markdown
Member Author

/azp run rust - cosmos - weekly

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 13, 2026

API Change Check

APIView identified API level changes in this PR and created the following API reviews

azure_data_cosmos_driver
azure_data_cosmos

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 - Thanks

@simorenoh simorenoh enabled auto-merge (squash) April 14, 2026 19:39
@simorenoh simorenoh disabled auto-merge April 14, 2026 19:59
@simorenoh
Copy link
Copy Markdown
Member Author

/check-enforcer override

@simorenoh simorenoh enabled auto-merge (squash) April 14, 2026 20:57
@simorenoh simorenoh disabled auto-merge April 14, 2026 20:57
@simorenoh simorenoh merged commit 9eaab0e into release/azure_data_cosmos-previews Apr 14, 2026
13 checks passed
@simorenoh simorenoh deleted the port-feed-range branch April 14, 2026 21:48
@github-project-automation github-project-automation Bot moved this from Changes Requested to Done in CosmosDB Go/Rust Crew Apr 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Cosmos The azure_cosmos crate

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[Cosmos] Feed range APIs

4 participants