def ShouldRetry(self, _exception): """Returns true if should retry based on the passed-in exception. :param (errors.CosmosHttpResponseError instance) exception: :rtype: boolean """ self.session_token_retry_count += 1 # clear previous location-based routing directive self.request.clear_route_to_location() if not self.endpoint_discovery_enable: # if endpoint discovery is disabled, the request cannot be retried anywhere else return False if self.can_use_multiple_write_locations: if _OperationType.IsReadOnlyOperation(self.request.operation_type): endpoints = self.global_endpoint_manager.get_ordered_read_endpoints( ) else: endpoints = self.global_endpoint_manager.get_ordered_write_endpoints( ) if self.session_token_retry_count > len(endpoints): # When use multiple write locations is true and the request has been tried # on all locations, then don't retry the request return False # set location-based routing directive based on request retry context self.request.route_to_location_with_preferred_location_flag( self.session_token_retry_count - 1, self.session_token_retry_count > self._max_retry_attempt_count) self.request.should_clear_session_token_on_session_read_failure = self.session_token_retry_count == len( endpoints) # clear on last attempt # Resolve the endpoint for the request and pin the resolution to the resolved endpoint # This enables marking the endpoint unavailability on endpoint failover/unreachability self.location_endpoint = self.global_endpoint_manager.resolve_service_endpoint( self.request) self.request.route_to_location(self.location_endpoint) return True if self.session_token_retry_count > self._max_retry_attempt_count: # When cannot use multiple write locations, then don't retry the request if # we have already tried this request on the write location return False # set location-based routing directive based on request retry context self.request.route_to_location_with_preferred_location_flag( self.session_token_retry_count - 1, False) self.request.should_clear_session_token_on_session_read_failure = True # Resolve the endpoint for the request and pin the resolution to the resolved endpoint # This enables marking the endpoint unavailability on endpoint failover/unreachability self.location_endpoint = self.global_endpoint_manager.resolve_service_endpoint( self.request) self.request.route_to_location(self.location_endpoint) return True
def ShouldRetry(self, exception): # pylint: disable=unused-argument """Returns true if should retry based on the passed-in exception. :param (errors.CosmosHttpResponseError instance) exception: :rtype: boolean """ if not self.connection_policy.EnableEndpointDiscovery: return False if self.failover_retry_count >= self.Max_retry_attempt_count: return False self.failover_retry_count += 1 if self.location_endpoint: if _OperationType.IsReadOnlyOperation(self.request.operation_type): # Mark current read endpoint as unavailable self.global_endpoint_manager.mark_endpoint_unavailable_for_read( self.location_endpoint) else: self.global_endpoint_manager.mark_endpoint_unavailable_for_write( self.location_endpoint) # set the refresh_needed flag to ensure that endpoint list is # refreshed with new writable and readable locations self.global_endpoint_manager.refresh_needed = True # clear previous location-based routing directive self.request.clear_route_to_location() # set location-based routing directive based on retry count # simulating single master writes by ensuring usePreferredLocations # is set to false self.request.route_to_location_with_preferred_location_flag( self.failover_retry_count, False) # Resolve the endpoint for the request and pin the resolution to the resolved endpoint # This enables marking the endpoint unavailability on endpoint failover/unreachability self.location_endpoint = self.global_endpoint_manager.resolve_service_endpoint( self.request) self.request.route_to_location(self.location_endpoint) return True