Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions sdk/cosmos/azure-cosmos/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
#### Breaking Changes

#### Bugs Fixed
* 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)

#### Other Changes
* 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)

### 4.14.0 (2025-10-13)
This version and all future versions will require Python 3.9+.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,16 @@ def ShouldRetry(self, exception): # pylint: disable=unused-argument
self.failover_retry_count += 1

if self.request.location_endpoint_to_route:
context = self.__class__.__name__
if _OperationType.IsReadOnlyOperation(self.request.operation_type):
# Mark current read endpoint as unavailable
self.global_endpoint_manager.mark_endpoint_unavailable_for_read(
self.request.location_endpoint_to_route,
True)
True, context)
else:
self.global_endpoint_manager.mark_endpoint_unavailable_for_write(
self.request.location_endpoint_to_route,
True)
True, context)

# set the refresh_needed flag to ensure that endpoint list is
# refreshed with new writable and readable locations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ def _resolve_service_endpoint(
) -> str:
return self.location_cache.resolve_service_endpoint(request)

def mark_endpoint_unavailable_for_read(self, endpoint, refresh_cache):
self.location_cache.mark_endpoint_unavailable_for_read(endpoint, refresh_cache)
def mark_endpoint_unavailable_for_read(self, endpoint, refresh_cache, context: str):
self.location_cache.mark_endpoint_unavailable_for_read(endpoint, refresh_cache, context)

def mark_endpoint_unavailable_for_write(self, endpoint, refresh_cache):
self.location_cache.mark_endpoint_unavailable_for_write(endpoint, refresh_cache)
def mark_endpoint_unavailable_for_write(self, endpoint, refresh_cache, context: str):
self.location_cache.mark_endpoint_unavailable_for_write(endpoint, refresh_cache, context)

def get_ordered_write_locations(self):
return self.location_cache.get_ordered_write_locations()
Expand All @@ -96,14 +96,15 @@ def force_refresh_on_startup(self, database_account):
def update_location_cache(self):
self.location_cache.update_location_cache()

def _mark_endpoint_unavailable(self, endpoint: str):
def _mark_endpoint_unavailable(self, endpoint: str, context: str):
"""Marks an endpoint as unavailable for the appropriate operations.
:param str endpoint: The endpoint to mark as unavailable.
:param str context: The context for marking the endpoint as unavailable.
"""
write_endpoints = self.location_cache.get_all_write_endpoints()
self.mark_endpoint_unavailable_for_read(endpoint, False)
self.mark_endpoint_unavailable_for_read(endpoint, False, context)
if endpoint in write_endpoints:
self.mark_endpoint_unavailable_for_write(endpoint, False)
self.mark_endpoint_unavailable_for_write(endpoint, False, context)

def refresh_endpoint_list(self, database_account, **kwargs):
if current_time_millis() - self.last_refresh_time > self.refresh_time_interval_in_ms:
Expand Down Expand Up @@ -159,7 +160,7 @@ def _GetDatabaseAccount(self, **kwargs) -> Tuple[DatabaseAccount, str]:
self.location_cache.mark_endpoint_available(locational_endpoint)
return database_account, locational_endpoint
except (exceptions.CosmosHttpResponseError, AzureError):
self._mark_endpoint_unavailable(locational_endpoint)
self._mark_endpoint_unavailable(locational_endpoint, "_GetDatabaseAccount")
raise

def _endpoints_health_check(self, **kwargs):
Expand Down Expand Up @@ -194,7 +195,7 @@ def _endpoints_health_check(self, **kwargs):
success_count += 1
self.location_cache.mark_endpoint_available(endpoint)
except (exceptions.CosmosHttpResponseError, AzureError):
self._mark_endpoint_unavailable(endpoint)
self._mark_endpoint_unavailable(endpoint, "_endpoints_health_check")

finally:
# after the health check for that endpoint setting the timeouts back to their original values
Expand Down
Loading