9
9
import io .split .engine .segments .SegmentFetcher ;
10
10
import io .split .engine .segments .SegmentSynchronizationTask ;
11
11
import io .split .engine .sse .dtos .SplitKillNotification ;
12
+ import io .split .storages .RuleBasedSegmentCacheProducer ;
12
13
import io .split .storages .SegmentCacheProducer ;
13
14
import io .split .storages .SplitCacheProducer ;
14
15
import io .split .telemetry .synchronizer .TelemetrySyncTask ;
@@ -34,6 +35,7 @@ public class SynchronizerImp implements Synchronizer {
34
35
private final SplitFetcher _splitFetcher ;
35
36
private final SegmentSynchronizationTask _segmentSynchronizationTaskImp ;
36
37
private final SplitCacheProducer _splitCacheProducer ;
38
+ private final RuleBasedSegmentCacheProducer _ruleBasedSegmentCacheProducer ;
37
39
private final SegmentCacheProducer segmentCacheProducer ;
38
40
private final ImpressionsManager _impressionManager ;
39
41
private final EventsTask _eventsTask ;
@@ -48,6 +50,7 @@ public SynchronizerImp(SplitTasks splitTasks,
48
50
SplitFetcher splitFetcher ,
49
51
SplitCacheProducer splitCacheProducer ,
50
52
SegmentCacheProducer segmentCacheProducer ,
53
+ RuleBasedSegmentCacheProducer ruleBasedSegmentCacheProducer ,
51
54
int onDemandFetchRetryDelayMs ,
52
55
int onDemandFetchMaxRetries ,
53
56
int failedAttemptsBeforeLogging ,
@@ -56,6 +59,7 @@ public SynchronizerImp(SplitTasks splitTasks,
56
59
_splitFetcher = checkNotNull (splitFetcher );
57
60
_segmentSynchronizationTaskImp = checkNotNull (splitTasks .getSegmentSynchronizationTask ());
58
61
_splitCacheProducer = checkNotNull (splitCacheProducer );
62
+ _ruleBasedSegmentCacheProducer = checkNotNull (ruleBasedSegmentCacheProducer );
59
63
this .segmentCacheProducer = checkNotNull (segmentCacheProducer );
60
64
_onDemandFetchRetryDelayMs = checkNotNull (onDemandFetchRetryDelayMs );
61
65
_onDemandFetchMaxRetries = onDemandFetchMaxRetries ;
@@ -103,7 +107,7 @@ private static class SyncResult {
103
107
private final FetchResult _fetchResult ;
104
108
}
105
109
106
- private SyncResult attemptSplitsSync (long targetChangeNumber ,
110
+ private SyncResult attemptSplitsSync (long targetChangeNumber , long ruleBasedSegmentChangeNumber ,
107
111
FetchOptions opts ,
108
112
Function <Void , Long > nextWaitMs ,
109
113
int maxRetries ) {
@@ -114,7 +118,8 @@ private SyncResult attemptSplitsSync(long targetChangeNumber,
114
118
if (fetchResult != null && !fetchResult .retry () && !fetchResult .isSuccess ()) {
115
119
return new SyncResult (false , remainingAttempts , fetchResult );
116
120
}
117
- if (targetChangeNumber <= _splitCacheProducer .getChangeNumber ()) {
121
+ if (targetChangeNumber <= _splitCacheProducer .getChangeNumber ()
122
+ && ruleBasedSegmentChangeNumber <= _ruleBasedSegmentCacheProducer .getChangeNumber ()) {
118
123
return new SyncResult (true , remainingAttempts , fetchResult );
119
124
} else if (remainingAttempts <= 0 ) {
120
125
return new SyncResult (false , remainingAttempts , fetchResult );
@@ -130,9 +135,17 @@ private SyncResult attemptSplitsSync(long targetChangeNumber,
130
135
}
131
136
132
137
@ Override
133
- public void refreshSplits (Long targetChangeNumber ) {
138
+ public void refreshSplits (Long targetChangeNumber , Long ruleBasedSegmentChangeNumber ) {
134
139
135
- if (targetChangeNumber <= _splitCacheProducer .getChangeNumber ()) {
140
+ if (targetChangeNumber == null || targetChangeNumber == 0 ) {
141
+ targetChangeNumber = _splitCacheProducer .getChangeNumber ();
142
+ }
143
+ if (ruleBasedSegmentChangeNumber == null || ruleBasedSegmentChangeNumber == 0 ) {
144
+ ruleBasedSegmentChangeNumber = _ruleBasedSegmentCacheProducer .getChangeNumber ();
145
+ }
146
+
147
+ if (targetChangeNumber <= _splitCacheProducer .getChangeNumber ()
148
+ && ruleBasedSegmentChangeNumber <= _ruleBasedSegmentCacheProducer .getChangeNumber ()) {
136
149
return ;
137
150
}
138
151
@@ -142,7 +155,7 @@ public void refreshSplits(Long targetChangeNumber) {
142
155
.flagSetsFilter (_sets )
143
156
.build ();
144
157
145
- SyncResult regularResult = attemptSplitsSync (targetChangeNumber , opts ,
158
+ SyncResult regularResult = attemptSplitsSync (targetChangeNumber , ruleBasedSegmentChangeNumber , opts ,
146
159
(discard ) -> (long ) _onDemandFetchRetryDelayMs , _onDemandFetchMaxRetries );
147
160
148
161
int attempts = _onDemandFetchMaxRetries - regularResult .remainingAttempts ();
@@ -157,7 +170,7 @@ public void refreshSplits(Long targetChangeNumber) {
157
170
_log .info (String .format ("No changes fetched after %s attempts. Will retry bypassing CDN." , attempts ));
158
171
FetchOptions withCdnBypass = new FetchOptions .Builder (opts ).targetChangeNumber (targetChangeNumber ).build ();
159
172
Backoff backoff = new Backoff (ON_DEMAND_FETCH_BACKOFF_BASE_MS , ON_DEMAND_FETCH_BACKOFF_MAX_WAIT_MS );
160
- SyncResult withCDNBypassed = attemptSplitsSync (targetChangeNumber , withCdnBypass ,
173
+ SyncResult withCDNBypassed = attemptSplitsSync (targetChangeNumber , ruleBasedSegmentChangeNumber , withCdnBypass ,
161
174
(discard ) -> backoff .interval (), ON_DEMAND_FETCH_BACKOFF_MAX_RETRIES );
162
175
163
176
int withoutCDNAttempts = ON_DEMAND_FETCH_BACKOFF_MAX_RETRIES - withCDNBypassed ._remainingAttempts ;
@@ -175,7 +188,7 @@ public void localKillSplit(SplitKillNotification splitKillNotification) {
175
188
if (splitKillNotification .getChangeNumber () > _splitCacheProducer .getChangeNumber ()) {
176
189
_splitCacheProducer .kill (splitKillNotification .getSplitName (), splitKillNotification .getDefaultTreatment (),
177
190
splitKillNotification .getChangeNumber ());
178
- refreshSplits (splitKillNotification .getChangeNumber ());
191
+ refreshSplits (splitKillNotification .getChangeNumber (), 0L );
179
192
}
180
193
}
181
194
0 commit comments