Skip to content

Cosmos: resolve-by-RID, addressing validation, and RID cache (2/3)#4663

Open
simorenoh wants to merge 5 commits into
simorenoh/cosmos-rid-slice1-driver-protocolfrom
simorenoh/cosmos-rid-slice2-resolution
Open

Cosmos: resolve-by-RID, addressing validation, and RID cache (2/3)#4663
simorenoh wants to merge 5 commits into
simorenoh/cosmos-rid-slice1-driver-protocolfrom
simorenoh/cosmos-rid-slice2-resolution

Conversation

@simorenoh

Copy link
Copy Markdown
Member

Slice 2 of 3 for epic #4637, stacked on Slice 1 (PR #4640). Target this PR's base at simorenoh/cosmos-rid-slice1-driver-protocol, not main, so the diff is reviewable in isolation.

This is the driver-internal layer where RID-addressed references are actually produced, validated, and cached. Still azure_data_cosmos_driver-only — no SDK public API surface (that lands in Slice 3, the azure_data_cosmos crate). Unit-tested only.

What's here

Resolve-by-RID flow (driver/cosmos_driver.rs, models/cosmos_operation.rs)

  • CosmosOperation::read_container_by_rid builds its parent DatabaseReference::from_rid internally, so a mixed name/RID request path is unrepresentable (always /dbs/{db_rid}/colls/{container_rid}).
  • fetch_container_by_rid decodes the container RID, fails fast with CLIENT_INVALID_RESOURCE_ID when it can't decode or is shorter than 8 bytes, derives the parent DB RID from the first 4 decoded bytes (no read_database round-trip), reads the container, and prefers the service-echoed RID. Returns a RID-addressed ContainerReference (no database name).
  • resolve_container_by_rid resolves via the container cache's by-RID index, fetching and populating on a miss.

Addressing validation (models/cosmos_resource_reference.rs, error/cosmos_status.rs)

  • validate_addressing is the release-mode counterpart to the existing debug assert: it returns a deterministic CLIENT_MIXED_NAME_RID_ADDRESSING error before signing instead of letting the gateway reject a mixed reference with an opaque 401. The driver calls it once per operation, so the guarantee holds for references built through any path.
  • addressing_conflict and parent_chain_is_rid are un-gated from #[cfg(debug_assertions)] now that validate_addressing consumes them in all builds.
  • Adds the CLIENT_INVALID_RESOURCE_ID (20118) and CLIENT_MIXED_NAME_RID_ADDRESSING (20119) status codes.

RID cache + review finding R1 (driver/cache/container_cache.rs)

  • Fixes R1: ContainerNameKey::from_container now returns Option and put skips the by-name index for RID-addressed containers, so two RID-resolved containers that share a name across different databases can no longer alias to {endpoint, "", name}. The TODO(Slice 2) shim comment is removed.
  • Adds a by-RID get_or_fetch_by_rid path that populates only the by-RID index.

Slice 3 (SDK public API) builds on this.

Validation

cargo fmt, cargo build --all-features, cargo clippy --all-features --all-targets (zero warnings) and --release (dead_code check for the un-gated addressing_conflict), and cargo test --all-features --lib (all pass) — all for azure_data_cosmos_driver. cspell clean.

Slice 2 of the driver-internal RID-addressing work (stacked on Slice 1).

Adds the resolve-by-RID flow (fetch_container_by_rid and resolve_container_by_rid), the read_container_by_rid operation, and the CLIENT_INVALID_RESOURCE_ID and CLIENT_MIXED_NAME_RID_ADDRESSING status codes.

Adds validate_addressing as the release-mode counterpart to the debug assert and un-gates addressing_conflict and parent_chain_is_rid so it is consumed in all builds.

Fixes review finding R1 in the container cache: ContainerNameKey::from_container now returns Option and the by-name index is skipped for RID-addressed containers, so two RID-resolved containers sharing a name across databases can no longer alias. Adds a by-RID get_or_fetch path.

Still driver-internal with no public API surface; unit-tested.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
simorenoh and others added 3 commits June 25, 2026 17:58
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Move validate_addressing to the top of plan_operation so every executable operation (including multi-page queries that bypass execute_operation) passes through a single addressing-consistency choke point.

Add searchable diagnostic names for the new ClientInvalidResourceId and ClientMixedNameRidAddressing client statuses, and clarify the container cache docs to note RID-addressed references live only in the by-RID index.

Add cspell word unrepresentable used in the read_container_by_rid doc.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Inserting fetch_container_by_rid directly above CosmosDriver::new consumed the new() summary line in the diff, leaving it with only the internal-use note. Restore the Creates a new driver instance summary so the doc is intact.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Comment thread sdk/cosmos/azure_data_cosmos_driver/src/driver/cosmos_driver.rs Outdated
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: Todo

Development

Successfully merging this pull request may close these issues.

1 participant