21
21
22
22
public class SynchronizerImp implements Synchronizer {
23
23
24
- private static final int MAX_ATTEMPTS = 10 ;
25
-
26
24
private static final Logger _log = LoggerFactory .getLogger (Synchronizer .class );
27
25
private final SplitSynchronizationTask _splitSynchronizationTask ;
28
26
private final SplitFetcher _splitFetcher ;
@@ -31,7 +29,10 @@ public class SynchronizerImp implements Synchronizer {
31
29
private final SplitCache _splitCache ;
32
30
private final SegmentCache _segmentCache ;
33
31
private final int _onDemandFetchRetryDelayMs ;
32
+ private final int _onDemandFetchMaxRetries ;
33
+ private final int _failedAttemptsBeforeLogging ;
34
34
private final boolean _cdnResponseHeadersLogging ;
35
+
35
36
private final Gson gson = new GsonBuilder ().create ();
36
37
37
38
public SynchronizerImp (SplitSynchronizationTask splitSynchronizationTask ,
@@ -40,6 +41,8 @@ public SynchronizerImp(SplitSynchronizationTask splitSynchronizationTask,
40
41
SplitCache splitCache ,
41
42
SegmentCache segmentCache ,
42
43
int onDemandFetchRetryDelayMs ,
44
+ int onDemandFetchMaxRetries ,
45
+ int failedAttemptsBeforeLogging ,
43
46
boolean cdnResponseHeadersLogging ) {
44
47
_splitSynchronizationTask = checkNotNull (splitSynchronizationTask );
45
48
_splitFetcher = checkNotNull (splitFetcher );
@@ -48,6 +51,8 @@ public SynchronizerImp(SplitSynchronizationTask splitSynchronizationTask,
48
51
_segmentCache = checkNotNull (segmentCache );
49
52
_onDemandFetchRetryDelayMs = checkNotNull (onDemandFetchRetryDelayMs );
50
53
_cdnResponseHeadersLogging = cdnResponseHeadersLogging ;
54
+ _onDemandFetchMaxRetries = onDemandFetchMaxRetries ;
55
+ _failedAttemptsBeforeLogging = failedAttemptsBeforeLogging ;
51
56
52
57
ThreadFactory splitsThreadFactory = new ThreadFactoryBuilder ()
53
58
.setDaemon (true )
@@ -92,15 +97,15 @@ public void refreshSplits(long targetChangeNumber) {
92
97
.responseHeadersCallback (_cdnResponseHeadersLogging ? captor ::handle : null )
93
98
.build ();
94
99
95
- int remainingAttempts = MAX_ATTEMPTS ;
100
+ int remainingAttempts = _onDemandFetchMaxRetries ;
96
101
while (true ) {
97
102
remainingAttempts --;
98
103
_splitFetcher .forceRefresh (opts );
99
104
if (targetChangeNumber <= _splitCache .getChangeNumber ()) {
100
- _log .debug (String .format ("Refresh completed in %s attempts." , MAX_ATTEMPTS - remainingAttempts ));
105
+ _log .debug (String .format ("Refresh completed in %s attempts." , _onDemandFetchMaxRetries - remainingAttempts ));
101
106
break ;
102
107
} else if (remainingAttempts <= 0 ) {
103
- _log .info (String .format ("No changes fetched after %s attempts." , MAX_ATTEMPTS ));
108
+ _log .info (String .format ("No changes fetched after %s attempts." , _onDemandFetchMaxRetries ));
104
109
break ;
105
110
}
106
111
try {
@@ -111,7 +116,8 @@ public void refreshSplits(long targetChangeNumber) {
111
116
}
112
117
}
113
118
114
- if (_cdnResponseHeadersLogging && remainingAttempts <= (MAX_ATTEMPTS / 2 )) {
119
+ if (_cdnResponseHeadersLogging &&
120
+ (_onDemandFetchMaxRetries - remainingAttempts ) > _failedAttemptsBeforeLogging ) {
115
121
_log .info (String .format ("CDN Debug headers: %s" , gson .toJson (captor .get ())));
116
122
}
117
123
}
@@ -127,7 +133,7 @@ public void localKillSplit(String splitName, String defaultTreatment, long newCh
127
133
@ Override
128
134
public void refreshSegment (String segmentName , long changeNumber ) {
129
135
int retries = 1 ;
130
- while (changeNumber > _segmentCache .getChangeNumber (segmentName ) && retries <= MAX_ATTEMPTS ) {
136
+ while (changeNumber > _segmentCache .getChangeNumber (segmentName ) && retries <= _onDemandFetchMaxRetries ) {
131
137
SegmentFetcher fetcher = _segmentSynchronizationTaskImp .getFetcher (segmentName );
132
138
try {
133
139
fetcher .fetch (true );
0 commit comments