Skip to content

Commit 275e5d7

Browse files
authored
fix: fixing exclude region inclusion (#43602)
* fix: fixing exclude region issues * updated CHANGELOG.md * fix: fixing bug in the implementation * fix: refactoring * fix: fixing tests * fix: fixing pylint * fix: fixing pylint * fix: fixing pylint * fix: fixing pylint * fix: fixing logic * fix: cleaning up code
1 parent 734a674 commit 275e5d7

10 files changed

+496
-65
lines changed

sdk/cosmos/azure-cosmos/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
#### Breaking Changes
88

99
#### Bugs Fixed
10+
* Fixed bug where customer provided excluded region was not always being honored during certain transient failures. See [PR 43602](https://github.com/Azure/azure-sdk-for-python/pull/43602)
1011

1112
#### Other Changes
13+
* Enhanced logging to ensure when a region is marked unavailable we have the proper context. See [PR 43602](https://github.com/Azure/azure-sdk-for-python/pull/43602)
1214

1315
### 4.14.0 (2025-10-13)
1416
This version and all future versions will require Python 3.9+.

sdk/cosmos/azure-cosmos/azure/cosmos/_endpoint_discovery_retry_policy.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,16 @@ def ShouldRetry(self, exception): # pylint: disable=unused-argument
7171
self.failover_retry_count += 1
7272

7373
if self.request.location_endpoint_to_route:
74+
context = self.__class__.__name__
7475
if _OperationType.IsReadOnlyOperation(self.request.operation_type):
7576
# Mark current read endpoint as unavailable
7677
self.global_endpoint_manager.mark_endpoint_unavailable_for_read(
7778
self.request.location_endpoint_to_route,
78-
True)
79+
True, context)
7980
else:
8081
self.global_endpoint_manager.mark_endpoint_unavailable_for_write(
8182
self.request.location_endpoint_to_route,
82-
True)
83+
True, context)
8384

8485
# set the refresh_needed flag to ensure that endpoint list is
8586
# refreshed with new writable and readable locations

sdk/cosmos/azure-cosmos/azure/cosmos/_global_endpoint_manager.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ def _resolve_service_endpoint(
7474
) -> str:
7575
return self.location_cache.resolve_service_endpoint(request)
7676

77-
def mark_endpoint_unavailable_for_read(self, endpoint, refresh_cache):
78-
self.location_cache.mark_endpoint_unavailable_for_read(endpoint, refresh_cache)
77+
def mark_endpoint_unavailable_for_read(self, endpoint, refresh_cache, context: str):
78+
self.location_cache.mark_endpoint_unavailable_for_read(endpoint, refresh_cache, context)
7979

80-
def mark_endpoint_unavailable_for_write(self, endpoint, refresh_cache):
81-
self.location_cache.mark_endpoint_unavailable_for_write(endpoint, refresh_cache)
80+
def mark_endpoint_unavailable_for_write(self, endpoint, refresh_cache, context: str):
81+
self.location_cache.mark_endpoint_unavailable_for_write(endpoint, refresh_cache, context)
8282

8383
def get_ordered_write_locations(self):
8484
return self.location_cache.get_ordered_write_locations()
@@ -96,14 +96,15 @@ def force_refresh_on_startup(self, database_account):
9696
def update_location_cache(self):
9797
self.location_cache.update_location_cache()
9898

99-
def _mark_endpoint_unavailable(self, endpoint: str):
99+
def _mark_endpoint_unavailable(self, endpoint: str, context: str):
100100
"""Marks an endpoint as unavailable for the appropriate operations.
101101
:param str endpoint: The endpoint to mark as unavailable.
102+
:param str context: The context for marking the endpoint as unavailable.
102103
"""
103104
write_endpoints = self.location_cache.get_all_write_endpoints()
104-
self.mark_endpoint_unavailable_for_read(endpoint, False)
105+
self.mark_endpoint_unavailable_for_read(endpoint, False, context)
105106
if endpoint in write_endpoints:
106-
self.mark_endpoint_unavailable_for_write(endpoint, False)
107+
self.mark_endpoint_unavailable_for_write(endpoint, False, context)
107108

108109
def refresh_endpoint_list(self, database_account, **kwargs):
109110
if current_time_millis() - self.last_refresh_time > self.refresh_time_interval_in_ms:
@@ -159,7 +160,7 @@ def _GetDatabaseAccount(self, **kwargs) -> Tuple[DatabaseAccount, str]:
159160
self.location_cache.mark_endpoint_available(locational_endpoint)
160161
return database_account, locational_endpoint
161162
except (exceptions.CosmosHttpResponseError, AzureError):
162-
self._mark_endpoint_unavailable(locational_endpoint)
163+
self._mark_endpoint_unavailable(locational_endpoint, "_GetDatabaseAccount")
163164
raise
164165

165166
def _endpoints_health_check(self, **kwargs):
@@ -194,7 +195,7 @@ def _endpoints_health_check(self, **kwargs):
194195
success_count += 1
195196
self.location_cache.mark_endpoint_available(endpoint)
196197
except (exceptions.CosmosHttpResponseError, AzureError):
197-
self._mark_endpoint_unavailable(endpoint)
198+
self._mark_endpoint_unavailable(endpoint, "_endpoints_health_check")
198199

199200
finally:
200201
# after the health check for that endpoint setting the timeouts back to their original values

0 commit comments

Comments
 (0)