27
27
import com .google .api .gax .retrying .TimedRetryAlgorithmWithContext ;
28
28
import java .util .Iterator ;
29
29
import java .util .concurrent .CancellationException ;
30
+ import java .util .logging .Level ;
31
+ import java .util .logging .Logger ;
30
32
import java .util .regex .Pattern ;
33
+ import org .threeten .bp .Duration ;
31
34
32
35
public class BigQueryRetryAlgorithm <ResponseT > extends RetryAlgorithm <ResponseT > {
33
36
private final BigQueryRetryConfig bigQueryRetryConfig ;
@@ -36,6 +39,8 @@ public class BigQueryRetryAlgorithm<ResponseT> extends RetryAlgorithm<ResponseT>
36
39
private final ResultRetryAlgorithmWithContext <ResponseT > resultAlgorithmWithContext ;
37
40
private final TimedRetryAlgorithmWithContext timedAlgorithmWithContext ;
38
41
42
+ private static final Logger LOG = Logger .getLogger (BigQueryRetryAlgorithm .class .getName ());
43
+
39
44
public BigQueryRetryAlgorithm (
40
45
ResultRetryAlgorithm <ResponseT > resultAlgorithm ,
41
46
TimedRetryAlgorithm timedAlgorithm ,
@@ -55,11 +60,32 @@ public boolean shouldRetry(
55
60
ResponseT previousResponse ,
56
61
TimedAttemptSettings nextAttemptSettings )
57
62
throws CancellationException {
63
+ // Log retry info
64
+ int attemptCount = nextAttemptSettings == null ? 0 : nextAttemptSettings .getAttemptCount ();
65
+ Duration retryDelay =
66
+ nextAttemptSettings == null ? Duration .ZERO : nextAttemptSettings .getRetryDelay ();
67
+ String errorMessage = previousThrowable != null ? previousThrowable .getMessage () : "" ;
68
+
58
69
// Implementing shouldRetryBasedOnBigQueryRetryConfig so that we can retry exceptions based on
59
70
// the exception messages
60
- return (shouldRetryBasedOnResult (context , previousThrowable , previousResponse )
61
- || shouldRetryBasedOnBigQueryRetryConfig (previousThrowable , bigQueryRetryConfig ))
62
- && shouldRetryBasedOnTiming (context , nextAttemptSettings );
71
+ boolean shouldRetry =
72
+ (shouldRetryBasedOnResult (context , previousThrowable , previousResponse )
73
+ || shouldRetryBasedOnBigQueryRetryConfig (previousThrowable , bigQueryRetryConfig ))
74
+ && shouldRetryBasedOnTiming (context , nextAttemptSettings );
75
+
76
+ if (LOG .isLoggable (Level .FINEST )) {
77
+ LOG .log (
78
+ Level .FINEST ,
79
+ "Retrying with:\n {0}\n {1}\n {2}\n {3}\n {4}" ,
80
+ new Object [] {
81
+ "BigQuery attemptCount: " + attemptCount ,
82
+ "BigQuery delay: " + retryDelay ,
83
+ "BigQuery retriableException: " + previousThrowable ,
84
+ "BigQuery shouldRetry: " + shouldRetry ,
85
+ "BigQuery previousThrowable.getMessage: " + errorMessage
86
+ });
87
+ }
88
+ return shouldRetry ;
63
89
}
64
90
65
91
private boolean shouldRetryBasedOnBigQueryRetryConfig (
0 commit comments