@@ -9,30 +9,42 @@ namespace Microsoft.Azure.Cosmos
99
1010 internal sealed class HttpTimeoutPolicyForPartitionFailover : HttpTimeoutPolicy
1111 {
12- public static readonly HttpTimeoutPolicy Instance = new HttpTimeoutPolicyForPartitionFailover ( false ) ;
13- public static readonly HttpTimeoutPolicy InstanceShouldThrow503OnTimeout = new HttpTimeoutPolicyForPartitionFailover ( true ) ;
12+ public bool isQuery ;
13+ public static readonly HttpTimeoutPolicy InstanceShouldThrow503OnTimeoutForQuery = new HttpTimeoutPolicyForPartitionFailover ( true ) ;
14+ public static readonly HttpTimeoutPolicy InstanceShouldThrow503OnTimeoutForReads = new HttpTimeoutPolicyForPartitionFailover ( false ) ;
15+
1416 public bool shouldThrow503OnTimeout ;
1517 private static readonly string Name = nameof ( HttpTimeoutPolicyDefault ) ;
1618
17- private HttpTimeoutPolicyForPartitionFailover ( bool shouldThrow503OnTimeout )
19+ private HttpTimeoutPolicyForPartitionFailover ( bool isQuery )
1820 {
19- this . shouldThrow503OnTimeout = shouldThrow503OnTimeout ;
21+ this . isQuery = isQuery ;
2022 }
2123
22- private readonly IReadOnlyList < ( TimeSpan requestTimeout , TimeSpan delayForNextRequest ) > TimeoutsAndDelays = new List < ( TimeSpan requestTimeout , TimeSpan delayForNextRequest ) > ( )
24+ // Timeouts and delays are based on the following rationale:
25+ // For reads: 3 agressive attempts with timeouts of .5s, .5s, and 1s respectively.
26+ // For queries: 3 attempts with timeouts of 5s, 5s, and 10s respectively.
27+ private readonly IReadOnlyList < ( TimeSpan requestTimeout , TimeSpan delayForNextRequest ) > TimeoutsAndDelaysForReads = new List < ( TimeSpan requestTimeout , TimeSpan delayForNextRequest ) > ( )
2328 {
2429 ( TimeSpan . FromSeconds ( .5 ) , TimeSpan . Zero ) ,
2530 ( TimeSpan . FromSeconds ( .5 ) , TimeSpan . Zero ) ,
2631 ( TimeSpan . FromSeconds ( 1 ) , TimeSpan . Zero ) ,
2732 } ;
2833
34+ private readonly IReadOnlyList < ( TimeSpan requestTimeout , TimeSpan delayForNextRequest ) > TimeoutsAndDelaysForQueries = new List < ( TimeSpan requestTimeout , TimeSpan delayForNextRequest ) > ( )
35+ {
36+ ( TimeSpan . FromSeconds ( 5 ) , TimeSpan . Zero ) ,
37+ ( TimeSpan . FromSeconds ( 5 ) , TimeSpan . Zero ) ,
38+ ( TimeSpan . FromSeconds ( 10 ) , TimeSpan . Zero ) ,
39+ } ;
40+
2941 public override string TimeoutPolicyName => HttpTimeoutPolicyForPartitionFailover . Name ;
3042
31- public override int TotalRetryCount => this . TimeoutsAndDelays . Count ;
43+ public override int TotalRetryCount => this . isQuery ? this . TimeoutsAndDelaysForQueries . Count : this . TimeoutsAndDelaysForReads . Count ;
3244
3345 public override IEnumerator < ( TimeSpan requestTimeout , TimeSpan delayForNextRequest ) > GetTimeoutEnumerator ( )
3446 {
35- return this . TimeoutsAndDelays . GetEnumerator ( ) ;
47+ return this . isQuery ? this . TimeoutsAndDelaysForQueries . GetEnumerator ( ) : this . TimeoutsAndDelaysForReads . GetEnumerator ( ) ;
3648 }
3749
3850 // Assume that it is not safe to retry unless it is a get method.
0 commit comments