Commit 5128111
[Cosmos] Fix pkranges fetch: use container name for URL, RID for cache key (#4047)
## Summary
Fixes [#4031](#4031) —
the pkranges fetch was using the collection **RID** in a name-based URL
hierarchy (`dbs/perfdb/colls/<RID>/pkranges`), which Cosmos DB rejects
with 404 because mixed name/RID addressing is not supported.
The previous fix (#4041) corrected URL encoding (`.item()` →
`.item_by_rid()`) but did not fix the fundamental mixed-addressing
issue. This PR resolves it by passing the container **name** for URL
construction while keeping the **RID** as the cache key and request
context value.
## Root Cause
PR #4005 changed `container_connection.rs::send()` to pass
`self.container_ref.rid()` to `pk_range_cache.try_lookup()`. The cache
used this RID to build the pkranges URL:
```
dbs/perfdb/colls/pLLZAIuPigw=/pkranges
^^^^^^ ^^^^^^^^^^^^^
NAME RID ← mixed addressing → 404
```
All other SDK and driver operations use name-based URLs. The pkranges
fetch was the only code path using a RID in a name-based link hierarchy.
## Impact (observed on continuous benchmarks)
- **1.8M 404 requests/hour** from failed pkranges fetches
- Errors silently swallowed by `try_lookup` → `Ok(routing_map.ok())`
- Errors not cached → retried on every request (write lock contention on
AsyncCache)
- Loss of client-side partition key routing → gateway must route all
requests
- Throughput regression from ~110M to ~4.2M requests/hour
## Changes
### `partition_key_range_cache.rs`
- Added `collection_name: &str` parameter to `try_lookup`,
`get_routing_map_for_collection`, `resolve_partition_key_range_by_id`,
and `resolve_overlapping_ranges`
- Changed `.item_by_rid(collection_rid)` → `.item(collection_name)` for
pkranges URL construction
- Cache key remains the RID (`collection_rid.to_string()`)
- `resource_id` on the request remains the RID
- Updated `tracing::warn!` to include both `collection_name` and
`collection_rid`
- Replaced 3 RID-encoding unit tests with 2 tests verifying name-based
URL construction
### `container_connection.rs`
- Extracted `collection_name` from `self.container_ref.name()` alongside
existing `collection_rid`
- Passes `collection_name` to all `pk_range_cache` method calls
- `resolved_collection_rid` on request context still uses the RID
(unchanged)
### `cosmos_fault_injection.rs`
- Added `fault_injection_pkrange_readfeed_is_exercised` integration test
- Injects a transient error on `MetadataPartitionKeyRanges` ReadFeed
with hit_limit=1
- Verifies the fault rule is hit (proving pkrange fetch code path
executes)
- Verifies subsequent item operations succeed (proving end-to-end
pkrange resolution works)
## Test Results
- ✅ 31 unit tests pass (including 2 new)
- ✅ Build succeeds
- Integration test requires emulator (will run in CI)
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>1 parent 2ad6e08 commit 5128111
6 files changed
Lines changed: 186 additions & 50 deletions
File tree
- sdk/cosmos
- azure_data_cosmos
- src
- fault_injection
- handler
- routing
- tests/emulator_tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
123 | 123 | | |
124 | 124 | | |
125 | 125 | | |
| 126 | + | |
126 | 127 | | |
127 | 128 | | |
128 | 129 | | |
| |||
Lines changed: 23 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
219 | 219 | | |
220 | 220 | | |
221 | 221 | | |
222 | | - | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
223 | 226 | | |
224 | 227 | | |
225 | 228 | | |
| |||
234 | 237 | | |
235 | 238 | | |
236 | 239 | | |
237 | | - | |
| 240 | + | |
238 | 241 | | |
239 | | - | |
| 242 | + | |
240 | 243 | | |
241 | 244 | | |
242 | 245 | | |
| |||
257 | 260 | | |
258 | 261 | | |
259 | 262 | | |
260 | | - | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
261 | 280 | | |
262 | 281 | | |
263 | 282 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
| 10 | + | |
| 11 | + | |
9 | 12 | | |
10 | 13 | | |
11 | 14 | | |
| |||
26 | 29 | | |
27 | 30 | | |
28 | 31 | | |
29 | | - | |
| 32 | + | |
30 | 33 | | |
| 34 | + | |
| 35 | + | |
31 | 36 | | |
32 | 37 | | |
33 | 38 | | |
| |||
43 | 48 | | |
44 | 49 | | |
45 | 50 | | |
| 51 | + | |
46 | 52 | | |
47 | 53 | | |
48 | 54 | | |
| |||
81 | 87 | | |
82 | 88 | | |
83 | 89 | | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
84 | 110 | | |
85 | 111 | | |
86 | 112 | | |
| |||
155 | 181 | | |
156 | 182 | | |
157 | 183 | | |
| 184 | + | |
158 | 185 | | |
159 | 186 | | |
160 | 187 | | |
| |||
Lines changed: 7 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
| 56 | + | |
56 | 57 | | |
57 | 58 | | |
58 | 59 | | |
59 | 60 | | |
60 | 61 | | |
61 | 62 | | |
62 | 63 | | |
| 64 | + | |
63 | 65 | | |
64 | 66 | | |
65 | 67 | | |
| |||
71 | 73 | | |
72 | 74 | | |
73 | 75 | | |
74 | | - | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
75 | 80 | | |
76 | 81 | | |
77 | 82 | | |
| |||
94 | 99 | | |
95 | 100 | | |
96 | 101 | | |
97 | | - | |
| 102 | + | |
98 | 103 | | |
99 | 104 | | |
100 | 105 | | |
| |||
Lines changed: 50 additions & 43 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
| 58 | + | |
58 | 59 | | |
59 | 60 | | |
60 | 61 | | |
61 | 62 | | |
62 | | - | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
63 | 66 | | |
64 | 67 | | |
65 | 68 | | |
66 | | - | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
67 | 72 | | |
68 | 73 | | |
69 | 74 | | |
| |||
83 | 88 | | |
84 | 89 | | |
85 | 90 | | |
86 | | - | |
| 91 | + | |
| 92 | + | |
87 | 93 | | |
88 | 94 | | |
89 | 95 | | |
90 | | - | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
91 | 100 | | |
92 | 101 | | |
93 | 102 | | |
94 | 103 | | |
95 | | - | |
| 104 | + | |
96 | 105 | | |
97 | 106 | | |
98 | 107 | | |
| |||
103 | 112 | | |
104 | 113 | | |
105 | 114 | | |
106 | | - | |
| 115 | + | |
107 | 116 | | |
108 | 117 | | |
109 | 118 | | |
| |||
114 | 123 | | |
115 | 124 | | |
116 | 125 | | |
| 126 | + | |
117 | 127 | | |
118 | 128 | | |
119 | 129 | | |
| |||
128 | 138 | | |
129 | 139 | | |
130 | 140 | | |
131 | | - | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
132 | 146 | | |
133 | 147 | | |
134 | 148 | | |
135 | 149 | | |
136 | 150 | | |
137 | 151 | | |
138 | | - | |
139 | | - | |
| 152 | + | |
| 153 | + | |
140 | 154 | | |
141 | 155 | | |
142 | 156 | | |
| |||
146 | 160 | | |
147 | 161 | | |
148 | 162 | | |
| 163 | + | |
149 | 164 | | |
150 | 165 | | |
151 | 166 | | |
| |||
168 | 183 | | |
169 | 184 | | |
170 | 185 | | |
| 186 | + | |
171 | 187 | | |
172 | 188 | | |
173 | 189 | | |
| |||
196 | 212 | | |
197 | 213 | | |
198 | 214 | | |
199 | | - | |
| 215 | + | |
200 | 216 | | |
201 | 217 | | |
202 | 218 | | |
| |||
681 | 697 | | |
682 | 698 | | |
683 | 699 | | |
684 | | - | |
685 | | - | |
686 | | - | |
687 | | - | |
688 | 700 | | |
689 | | - | |
690 | | - | |
691 | | - | |
692 | | - | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
693 | 704 | | |
694 | 705 | | |
695 | 706 | | |
696 | | - | |
| 707 | + | |
697 | 708 | | |
698 | 709 | | |
699 | | - | |
700 | 710 | | |
701 | | - | |
| 711 | + | |
702 | 712 | | |
703 | 713 | | |
704 | 714 | | |
705 | 715 | | |
706 | 716 | | |
707 | | - | |
708 | | - | |
709 | | - | |
710 | | - | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
711 | 721 | | |
712 | | - | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
713 | 726 | | |
714 | | - | |
| 727 | + | |
715 | 728 | | |
716 | 729 | | |
717 | | - | |
718 | | - | |
719 | | - | |
720 | | - | |
721 | | - | |
| 730 | + | |
722 | 731 | | |
723 | | - | |
724 | | - | |
| 732 | + | |
| 733 | + | |
725 | 734 | | |
726 | | - | |
727 | 735 | | |
728 | | - | |
729 | | - | |
730 | | - | |
731 | | - | |
732 | | - | |
733 | | - | |
| 736 | + | |
| 737 | + | |
734 | 738 | | |
735 | | - | |
| 739 | + | |
736 | 740 | | |
737 | 741 | | |
738 | | - | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
739 | 746 | | |
740 | 747 | | |
0 commit comments