Skip to content

Commit a1946d4

Browse files
authored
Enable Request Level Excluded Locations to Metadata API calls (#40905)
* Enable excluded locations to metadata API calls * Added prefix partition key table to test config * Fixed failed live tests * Fixed emulator test failures * Fixed live tests * Fixed python style errors * Update Python version for live tests * Fix bug with is_endpoint_unavailable_internal * Revert fix for is_endpoint_unavailable_internal This was not a bug * Added Metadata tests with reordering with excluded locations * Added docstring to metadata APIs * Added CHANGELOG * Updated predicate_is_collection_operation to predicate_is_resource_type * Fixed typo * Enable excluded_locations to query plan workflow * Remove docstring of excluded_location for READ API * Updated emulator tests * Clean up unnecessary mapping during QueryChangeFeed * Fixed bug * Cleanup codes * Fixed bugs with test_change_feed_split * Fixed mypy error * Upgrade Python SDK version * Cleanup excluded location conditions * Removed unnecessary test * Removed unused import
1 parent 8d6ed76 commit a1946d4

29 files changed

+1032
-874
lines changed

sdk/cosmos/azure-cosmos/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## Release History
22

33
### 4.12.0b2 (Unreleased)
4+
* Added ability to use request level `excluded_locations` on metadata calls, such as getting container properties. See [PR 40905](https://github.com/Azure/azure-sdk-for-python/pull/40905)
45

56
#### Features Added
67

sdk/cosmos/azure-cosmos/azure/cosmos/_change_feed/aio/change_feed_fetcher.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,11 @@ async def callback():
145145
except CosmosHttpResponseError as e:
146146
if exceptions._partition_range_is_gone(e) or exceptions._is_partition_split_or_merge(e):
147147
# refresh change feed state
148-
await self._change_feed_state.handle_feed_range_gone_async(
149-
self._client._routing_map_provider,
150-
self._resource_link)
148+
options = None
149+
if "excludedLocations" in self._feed_options:
150+
options = {'excludedLocations': self._feed_options["excludedLocations"]}
151+
await self._change_feed_state.handle_feed_range_gone_async(self._client._routing_map_provider,
152+
self._resource_link, options)
151153
else:
152154
raise e
153155

sdk/cosmos/azure-cosmos/azure/cosmos/_change_feed/change_feed_fetcher.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,11 @@ def callback():
140140
except CosmosHttpResponseError as e:
141141
if exceptions._partition_range_is_gone(e) or exceptions._is_partition_split_or_merge(e):
142142
# refresh change feed state
143-
self._change_feed_state.handle_feed_range_gone(self._client._routing_map_provider, self._resource_link)
143+
options = None
144+
if "excludedLocations" in self._feed_options:
145+
options = {'excludedLocations': self._feed_options["excludedLocations"]}
146+
self._change_feed_state.handle_feed_range_gone(self._client._routing_map_provider, self._resource_link,
147+
options)
144148
else:
145149
raise e
146150

sdk/cosmos/azure-cosmos/azure/cosmos/_change_feed/change_feed_state.py

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,16 @@ def populate_feed_options(self, feed_options: Dict[str, Any]) -> None:
6464
def populate_request_headers(
6565
self,
6666
routing_provider: SmartRoutingMapProvider,
67-
request_headers: Dict[str, Any]) -> None:
67+
request_headers: Dict[str, Any],
68+
feed_options: Optional[Dict[str, Any]] = None) -> None:
6869
pass
6970

7071
@abstractmethod
7172
async def populate_request_headers_async(
7273
self,
7374
async_routing_provider: AsyncSmartRoutingMapProvider,
74-
request_headers: Dict[str, Any]) -> None:
75+
request_headers: Dict[str, Any],
76+
feed_options: Optional[Dict[str, Any]] = None) -> None:
7577
pass
7678

7779
@abstractmethod
@@ -149,7 +151,8 @@ def from_json(
149151
def populate_request_headers(
150152
self,
151153
routing_provider: SmartRoutingMapProvider,
152-
request_headers: Dict[str, Any]) -> None:
154+
request_headers: Dict[str, Any],
155+
feed_options: Optional[Dict[str, Any]] = None) -> None:
153156
request_headers[http_constants.HttpHeaders.AIM] = http_constants.HttpHeaders.IncrementalFeedHeaderValue
154157

155158
self._change_feed_start_from.populate_request_headers(request_headers)
@@ -159,7 +162,8 @@ def populate_request_headers(
159162
async def populate_request_headers_async(
160163
self,
161164
async_routing_provider: AsyncSmartRoutingMapProvider,
162-
request_headers: Dict[str, Any]) -> None: # pylint: disable=unused-argument
165+
request_headers: Dict[str, Any],
166+
feed_options: Optional[Dict[str, Any]] = None) -> None: # pylint: disable=unused-argument
163167

164168
request_headers[http_constants.HttpHeaders.AIM] = http_constants.HttpHeaders.IncrementalFeedHeaderValue
165169

@@ -277,14 +281,16 @@ def set_mode_request_headers(
277281
def populate_request_headers(
278282
self,
279283
routing_provider: SmartRoutingMapProvider,
280-
request_headers: Dict[str, Any]) -> None:
284+
request_headers: Dict[str, Any],
285+
feed_options = None) -> None:
281286
self.set_start_from_request_headers(request_headers)
282287

283288
# based on the feed range to find the overlapping partition key range id
284289
over_lapping_ranges = \
285290
routing_provider.get_overlapping_ranges(
286291
self._container_link,
287-
[self._continuation.current_token.feed_range])
292+
[self._continuation.current_token.feed_range],
293+
feed_options)
288294

289295
self.set_pk_range_id_request_headers(over_lapping_ranges, request_headers)
290296

@@ -294,14 +300,16 @@ def populate_request_headers(
294300
async def populate_request_headers_async(
295301
self,
296302
async_routing_provider: AsyncSmartRoutingMapProvider,
297-
request_headers: Dict[str, Any]) -> None:
303+
request_headers: Dict[str, Any],
304+
feed_options: Optional[Dict[str, Any]] = None) -> None:
298305
self.set_start_from_request_headers(request_headers)
299306

300307
# based on the feed range to find the overlapping partition key range id
301308
over_lapping_ranges = \
302309
await async_routing_provider.get_overlapping_ranges(
303310
self._container_link,
304-
[self._continuation.current_token.feed_range])
311+
[self._continuation.current_token.feed_range],
312+
feed_options)
305313

306314
self.set_pk_range_id_request_headers(over_lapping_ranges, request_headers)
307315

@@ -313,14 +321,16 @@ def populate_feed_options(self, feed_options: Dict[str, Any]) -> None:
313321
def handle_feed_range_gone(
314322
self,
315323
routing_provider: SmartRoutingMapProvider,
316-
resource_link: str) -> None:
317-
self._continuation.handle_feed_range_gone(routing_provider, resource_link)
324+
resource_link: str,
325+
feed_options: Optional[Dict[str, Any]] = None) -> None:
326+
self._continuation.handle_feed_range_gone(routing_provider, resource_link, feed_options)
318327

319328
async def handle_feed_range_gone_async(
320329
self,
321330
routing_provider: AsyncSmartRoutingMapProvider,
322-
resource_link: str) -> None:
323-
await self._continuation.handle_feed_range_gone_async(routing_provider, resource_link)
331+
resource_link: str,
332+
feed_options: Optional[Dict[str, Any]] = None) -> None:
333+
await self._continuation.handle_feed_range_gone_async(routing_provider, resource_link, feed_options)
324334

325335
def apply_server_response_continuation(self, continuation: str, has_modified_response: bool) -> None:
326336
self._continuation.apply_server_response_continuation(continuation, has_modified_response)

sdk/cosmos/azure-cosmos/azure/cosmos/_change_feed/feed_range_composite_continuation_token.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,10 @@ def from_json(cls, data) -> 'FeedRangeCompositeContinuation':
101101
def handle_feed_range_gone(
102102
self,
103103
routing_provider: SmartRoutingMapProvider,
104-
collection_link: str) -> None:
105-
overlapping_ranges = routing_provider.get_overlapping_ranges(collection_link, [self._current_token.feed_range])
104+
collection_link: str,
105+
feed_options: Optional[Dict[str, Any]] = None) -> None:
106+
overlapping_ranges = routing_provider.get_overlapping_ranges(collection_link,
107+
[self._current_token.feed_range], feed_options)
106108

107109
if len(overlapping_ranges) == 1:
108110
# merge,reusing the existing the feedRange and continuationToken
@@ -122,11 +124,13 @@ def handle_feed_range_gone(
122124
async def handle_feed_range_gone_async(
123125
self,
124126
routing_provider: AsyncSmartRoutingMapProvider,
125-
collection_link: str) -> None:
127+
collection_link: str,
128+
feed_options: Optional[Dict[str, Any]] = None) -> None:
126129
overlapping_ranges = \
127130
await routing_provider.get_overlapping_ranges(
128131
collection_link,
129-
[self._current_token.feed_range])
132+
[self._current_token.feed_range],
133+
feed_options)
130134

131135
if len(overlapping_ranges) == 1:
132136
# merge,reusing the existing the feedRange and continuationToken

0 commit comments

Comments
 (0)