Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>io.split.client</groupId>
<artifactId>java-client-parent</artifactId>
<version>4.1.7-rc2</version>
<version>4.1.7-rc3</version>
</parent>
<artifactId>java-client</artifactId>
<packaging>jar</packaging>
Expand Down
31 changes: 31 additions & 0 deletions client/src/main/java/io/split/client/SplitClientConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public class SplitClientConfig {
private final String _authServiceURL;
private final String _streamingServiceURL;
private final int _onDemandFetchRetryDelayMs;
private final int _onDemandFetchMaxRetries;
private final int _failedAttemptsBeforeLogging;
private final boolean _cdnDebugLogging;

// Proxy configs
Expand Down Expand Up @@ -93,6 +95,8 @@ private SplitClientConfig(String endpoint,
String authServiceURL,
String streamingServiceURL,
int onDemandFetchRetryDelayMs,
int onDemandFetchMaxRetries,
int failedAttemptsBeforeLogging,
boolean cdnDebugLogging) {
_endpoint = endpoint;
_eventsEndpoint = eventsEndpoint;
Expand Down Expand Up @@ -125,6 +129,8 @@ private SplitClientConfig(String endpoint,
_authServiceURL = authServiceURL;
_streamingServiceURL = streamingServiceURL;
_onDemandFetchRetryDelayMs = onDemandFetchRetryDelayMs;
_onDemandFetchMaxRetries = onDemandFetchMaxRetries;
_failedAttemptsBeforeLogging = failedAttemptsBeforeLogging;
_cdnDebugLogging = cdnDebugLogging;

Properties props = new Properties();
Expand Down Expand Up @@ -256,6 +262,10 @@ public String streamingServiceURL() {

public int streamingRetryDelay() {return _onDemandFetchRetryDelayMs;}

public int streamingFetchMaxRetries() {return _onDemandFetchMaxRetries;}

public int failedAttemptsBeforeLogging() {return _failedAttemptsBeforeLogging;}

public boolean cdnDebugLogging() { return _cdnDebugLogging; }


Expand Down Expand Up @@ -295,6 +305,8 @@ public static final class Builder {
private String _authServiceURL = "https://auth.split.io/api/auth";
private String _streamingServiceURL = "https://streaming.split.io/sse";
private int _onDemandFetchRetryDelayMs = 50;
private int _onDemandFetchMaxRetries = 10;
private int _failedAttemptsBeforeLogging = -1;
private boolean _cdnDebugLogging = true;

public Builder() {
Expand Down Expand Up @@ -697,6 +709,16 @@ public Builder streamingRetryDelay(int onDemandFetchRetryDelayMs) {
return this;
}

public Builder streamingFetchMaxRetries(int maxRetries) {
_onDemandFetchMaxRetries = maxRetries;
return this;
}

public Builder failedAttemptsBeforeLoggingCDNInfo(int failedAttemptsBeforeLogging) {
_failedAttemptsBeforeLogging = failedAttemptsBeforeLogging;
return this;
}

/**
* Enable logging response headers for requests made to our CDN.
* @param cdnDebugLogging
Expand Down Expand Up @@ -780,6 +802,13 @@ public SplitClientConfig build() {
if(_onDemandFetchRetryDelayMs <= 0) {
throw new IllegalStateException("streamingRetryDelay must be > 0");
}
if(_onDemandFetchMaxRetries <= 0) {
throw new IllegalStateException("_onDemandFetchMaxRetries must be > 0");
}

if (_failedAttemptsBeforeLogging < 0) {
_failedAttemptsBeforeLogging = _onDemandFetchMaxRetries / 2;
}

return new SplitClientConfig(
_endpoint,
Expand Down Expand Up @@ -813,6 +842,8 @@ public SplitClientConfig build() {
_authServiceURL,
_streamingServiceURL,
_onDemandFetchRetryDelayMs,
_onDemandFetchMaxRetries,
_failedAttemptsBeforeLogging,
_cdnDebugLogging);
}
}
Expand Down
2 changes: 2 additions & 0 deletions client/src/main/java/io/split/client/SplitFactoryImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ public SplitFactoryImpl(String apiToken, SplitClientConfig config) throws URISyn
buildSSEdHttpClient(config),
_segmentCache,
config.streamingRetryDelay(),
config.streamingFetchMaxRetries(),
config.failedAttemptsBeforeLogging(),
config.cdnDebugLogging());
_syncManager.start();

Expand Down
27 changes: 24 additions & 3 deletions client/src/main/java/io/split/engine/common/SyncManagerImp.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,32 @@ public static SyncManagerImp build(boolean streamingEnabledConfig,
CloseableHttpClient sseHttpClient,
SegmentCache segmentCache,
int streamingRetryDelay,
int maxOnDemandFetchRetries,
int failedAttemptsBeforeLogging,
boolean cdnDebugLogging) {
LinkedBlockingQueue<PushManager.Status> pushMessages = new LinkedBlockingQueue<>();
Synchronizer synchronizer = new SynchronizerImp(splitSynchronizationTask, splitFetcher, segmentSynchronizationTaskImp, splitCache, segmentCache, streamingRetryDelay, cdnDebugLogging);
PushManager pushManager = PushManagerImp.build(synchronizer, streamingServiceUrl, authUrl, httpClient, pushMessages, sseHttpClient);
return new SyncManagerImp(streamingEnabledConfig, synchronizer, pushManager, pushMessages, authRetryBackOffBase);
Synchronizer synchronizer = new SynchronizerImp(splitSynchronizationTask,
splitFetcher,
segmentSynchronizationTaskImp,
splitCache,
segmentCache,
streamingRetryDelay,
maxOnDemandFetchRetries,
failedAttemptsBeforeLogging,
cdnDebugLogging);

PushManager pushManager = PushManagerImp.build(synchronizer,
streamingServiceUrl,
authUrl,
httpClient,
pushMessages,
sseHttpClient);

return new SyncManagerImp(streamingEnabledConfig,
synchronizer,
pushManager,
pushMessages,
authRetryBackOffBase);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@

public class SynchronizerImp implements Synchronizer {

private static final int MAX_ATTEMPTS = 10;

private static final Logger _log = LoggerFactory.getLogger(Synchronizer.class);
private final SplitSynchronizationTask _splitSynchronizationTask;
private final SplitFetcher _splitFetcher;
Expand All @@ -31,7 +29,10 @@ public class SynchronizerImp implements Synchronizer {
private final SplitCache _splitCache;
private final SegmentCache _segmentCache;
private final int _onDemandFetchRetryDelayMs;
private final int _onDemandFetchMaxRetries;
private final int _failedAttemptsBeforeLogging;
private final boolean _cdnResponseHeadersLogging;

private final Gson gson = new GsonBuilder().create();

public SynchronizerImp(SplitSynchronizationTask splitSynchronizationTask,
Expand All @@ -40,6 +41,8 @@ public SynchronizerImp(SplitSynchronizationTask splitSynchronizationTask,
SplitCache splitCache,
SegmentCache segmentCache,
int onDemandFetchRetryDelayMs,
int onDemandFetchMaxRetries,
int failedAttemptsBeforeLogging,
boolean cdnResponseHeadersLogging) {
_splitSynchronizationTask = checkNotNull(splitSynchronizationTask);
_splitFetcher = checkNotNull(splitFetcher);
Expand All @@ -48,6 +51,8 @@ public SynchronizerImp(SplitSynchronizationTask splitSynchronizationTask,
_segmentCache = checkNotNull(segmentCache);
_onDemandFetchRetryDelayMs = checkNotNull(onDemandFetchRetryDelayMs);
_cdnResponseHeadersLogging = cdnResponseHeadersLogging;
_onDemandFetchMaxRetries = onDemandFetchMaxRetries;
_failedAttemptsBeforeLogging = failedAttemptsBeforeLogging;

ThreadFactory splitsThreadFactory = new ThreadFactoryBuilder()
.setDaemon(true)
Expand Down Expand Up @@ -92,15 +97,15 @@ public void refreshSplits(long targetChangeNumber) {
.responseHeadersCallback(_cdnResponseHeadersLogging ? captor::handle : null)
.build();

int remainingAttempts = MAX_ATTEMPTS;
int remainingAttempts = _onDemandFetchMaxRetries;
while(true) {
remainingAttempts--;
_splitFetcher.forceRefresh(opts);
if (targetChangeNumber <= _splitCache.getChangeNumber()) {
_log.debug(String.format("Refresh completed in %s attempts.", MAX_ATTEMPTS - remainingAttempts));
_log.debug(String.format("Refresh completed in %s attempts.", _onDemandFetchMaxRetries - remainingAttempts));
break;
} else if (remainingAttempts <= 0) {
_log.info(String.format("No changes fetched after %s attempts.", MAX_ATTEMPTS));
_log.info(String.format("No changes fetched after %s attempts.", _onDemandFetchMaxRetries));
break;
}
try {
Expand All @@ -111,7 +116,8 @@ public void refreshSplits(long targetChangeNumber) {
}
}

if (_cdnResponseHeadersLogging && remainingAttempts <= (MAX_ATTEMPTS / 2)) {
if (_cdnResponseHeadersLogging &&
(_onDemandFetchMaxRetries - remainingAttempts) > _failedAttemptsBeforeLogging) {
_log.info(String.format("CDN Debug headers: %s", gson.toJson(captor.get())));
}
}
Expand All @@ -127,7 +133,7 @@ public void localKillSplit(String splitName, String defaultTreatment, long newCh
@Override
public void refreshSegment(String segmentName, long changeNumber) {
int retries = 1;
while(changeNumber > _segmentCache.getChangeNumber(segmentName) && retries <= MAX_ATTEMPTS) {
while(changeNumber > _segmentCache.getChangeNumber(segmentName) && retries <= _onDemandFetchMaxRetries) {
SegmentFetcher fetcher = _segmentSynchronizationTaskImp.getFetcher(segmentName);
try{
fetcher.fetch(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void beforeMethod() {
_splitCache = Mockito.mock(SplitCache.class);
_segmentCache = Mockito.mock(SegmentCache.class);

_synchronizer = new SynchronizerImp(_refreshableSplitFetcherTask, _splitFetcher, _segmentFetcher, _splitCache, _segmentCache, 50, false);
_synchronizer = new SynchronizerImp(_refreshableSplitFetcherTask, _splitFetcher, _segmentFetcher, _splitCache, _segmentCache, 50, 10, 5, false);
}

@Test
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>io.split.client</groupId>
<artifactId>java-client-parent</artifactId>
<version>4.1.7-rc2</version>
<version>4.1.7-rc3</version>
<dependencyManagement>
<dependencies>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion testing/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>io.split.client</groupId>
<artifactId>java-client-parent</artifactId>
<version>4.1.7-rc2</version>
<version>4.1.7-rc3</version>
</parent>

<artifactId>java-client-testing</artifactId>
Expand Down