5
5
Cosmos database service.
6
6
"""
7
7
from azure .cosmos .documents import _OperationType
8
- from . import http_constants
9
8
10
9
11
10
class _TimeoutFailoverRetryPolicy (object ):
12
11
13
12
def __init__ (self , connection_policy , global_endpoint_manager , * args ):
14
- self ._max_retry_attempt_count = 120
15
- self ._max_service_unavailable_retry_count = 1
16
- self .retry_after_in_milliseconds = 0
13
+ self .retry_after_in_milliseconds = 500
17
14
self .args = args
18
15
19
16
self .global_endpoint_manager = global_endpoint_manager
17
+ # If an account only has 1 region, then we still want to retry once on the same region
18
+ self ._max_retry_attempt_count = len (self .global_endpoint_manager .location_cache .read_regional_endpoints ) + 1
20
19
self .retry_count = 0
21
20
self .connection_policy = connection_policy
22
21
self .request = args [0 ] if args else None
@@ -28,17 +27,13 @@ def ShouldRetry(self, _exception):
28
27
:returns: a boolean stating whether the request should be retried
29
28
:rtype: bool
30
29
"""
31
- # we don't retry on write operations for timeouts or service unavailable
30
+ # we don't retry on write operations for timeouts or any internal server errors
32
31
if self .request and (not _OperationType .IsReadOnlyOperation (self .request .operation_type )):
33
32
return False
34
33
35
34
if not self .connection_policy .EnableEndpointDiscovery :
36
35
return False
37
36
38
- # Check if the next retry about to be done is safe
39
- if _exception .status_code == http_constants .StatusCodes .SERVICE_UNAVAILABLE and \
40
- self .retry_count >= self ._max_service_unavailable_retry_count :
41
- return False
42
37
self .retry_count += 1
43
38
# Check if the next retry about to be done is safe
44
39
if self .retry_count >= self ._max_retry_attempt_count :
0 commit comments