Cosmos: resolve-by-RID, addressing validation, and RID cache (2/3)#4663
Open
simorenoh wants to merge 5 commits into
Open
Cosmos: resolve-by-RID, addressing validation, and RID cache (2/3)#4663simorenoh wants to merge 5 commits into
simorenoh wants to merge 5 commits into
Conversation
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>
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>
simorenoh
commented
Jun 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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, notmain, 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, theazure_data_cosmoscrate). Unit-tested only.What's here
Resolve-by-RID flow (
driver/cosmos_driver.rs,models/cosmos_operation.rs)CosmosOperation::read_container_by_ridbuilds its parentDatabaseReference::from_ridinternally, so a mixed name/RID request path is unrepresentable (always/dbs/{db_rid}/colls/{container_rid}).fetch_container_by_riddecodes the container RID, fails fast withCLIENT_INVALID_RESOURCE_IDwhen it can't decode or is shorter than 8 bytes, derives the parent DB RID from the first 4 decoded bytes (noread_databaseround-trip), reads the container, and prefers the service-echoed RID. Returns a RID-addressedContainerReference(no database name).resolve_container_by_ridresolves 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_addressingis the release-mode counterpart to the existing debug assert: it returns a deterministicCLIENT_MIXED_NAME_RID_ADDRESSINGerror before signing instead of letting the gateway reject a mixed reference with an opaque401. The driver calls it once per operation, so the guarantee holds for references built through any path.addressing_conflictandparent_chain_is_ridare un-gated from#[cfg(debug_assertions)]now thatvalidate_addressingconsumes them in all builds.CLIENT_INVALID_RESOURCE_ID(20118) andCLIENT_MIXED_NAME_RID_ADDRESSING(20119) status codes.RID cache + review finding R1 (
driver/cache/container_cache.rs)ContainerNameKey::from_containernow returnsOptionandputskips 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}. TheTODO(Slice 2)shim comment is removed.get_or_fetch_by_ridpath 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-gatedaddressing_conflict), andcargo test --all-features --lib(all pass) — all forazure_data_cosmos_driver. cspell clean.