Skip to content

Commit 9043ace

Browse files
committed
improve logs, fix crap in random till generation
1 parent ccc5c40 commit 9043ace

File tree

6 files changed

+23
-7
lines changed

6 files changed

+23
-7
lines changed

client/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>io.split.client</groupId>
77
<artifactId>java-client-parent</artifactId>
8-
<version>4.1.7-rc4</version>
8+
<version>4.1.7-rc5</version>
99
</parent>
1010
<artifactId>java-client</artifactId>
1111
<packaging>jar</packaging>

client/src/main/java/io/split/client/HttpSplitChangeFetcher.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ private HttpSplitChangeFetcher(CloseableHttpClient client, URI uri, Metrics metr
6060
}
6161

6262
long makeRandomTill() {
63-
return (-1)*(int)Math.floor(Math.random()*(Math.pow(2, 63)));
63+
64+
return (-1)*(long)Math.floor(Math.random()*(Math.pow(2, 63)));
6465
}
6566

6667
@Override

client/src/main/java/io/split/engine/common/SynchronizerImp.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ private SyncResult attemptSync(long targetChangeNumber,
114114
if (targetChangeNumber <= _splitCache.getChangeNumber()) {
115115
return new SyncResult(true, remainingAttempts);
116116
} else if (remainingAttempts <= 0) {
117-
_log.info(String.format("No changes fetched after %s attempts.", maxRetries));
118117
return new SyncResult(false, remainingAttempts);
119118
}
120119
try {
@@ -150,19 +149,28 @@ public void refreshSplits(long targetChangeNumber) {
150149
SyncResult regularResult = attemptSync(targetChangeNumber, opts,
151150
(discard) -> (long) _onDemandFetchRetryDelayMs, _onDemandFetchMaxRetries);
152151

152+
int attempts = _onDemandFetchMaxRetries - regularResult.remainingAttempts();
153153
if (regularResult.success()) {
154-
_log.debug(String.format("Refresh completed in %s attempts.", _onDemandFetchMaxRetries - regularResult.remainingAttempts()));
154+
_log.debug(String.format("Refresh completed in %s attempts.", attempts));
155155
if (_cdnResponseHeadersLogging) {
156156
logCdnHeaders(_onDemandFetchMaxRetries , regularResult.remainingAttempts(), captor.get());
157157
}
158158
return;
159159
}
160160

161+
_log.info(String.format("No changes fetched after %s attempts. Will retry bypassing CDN.", attempts));
161162
FetchOptions withCdnBypass = new FetchOptions.Builder(opts).cdnBypass(true).build();
162163
Backoff backoff = new Backoff(ON_DEMAND_FETCH_BACKOFF_BASE_MS, ON_DEMAND_FETCH_BACKOFF_MAX_WAIT_MS);
163164
SyncResult withCDNBypassed = attemptSync(targetChangeNumber, withCdnBypass,
164165
(discard) -> backoff.interval(), ON_DEMAND_FETCH_BACKOFF_MAX_RETRIES);
165166

167+
int withoutCDNAttempts = ON_DEMAND_FETCH_BACKOFF_MAX_RETRIES - withCDNBypassed._remainingAttempts;
168+
if (withCDNBypassed.success()) {
169+
_log.debug(String.format("Refresh completed bypassing the CDN in %s attempts.", attempts));
170+
} else {
171+
_log.debug(String.format("No changes fetched after %s attempts, even with CDN bypassed.", attempts));
172+
}
173+
166174
if (_cdnResponseHeadersLogging) {
167175
logCdnHeaders(_onDemandFetchMaxRetries + ON_DEMAND_FETCH_BACKOFF_MAX_RETRIES,
168176
withCDNBypassed.remainingAttempts(), captor.get());

client/src/test/java/io/split/client/HttpSplitChangeFetcherTest.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@
2424
import java.lang.reflect.InvocationTargetException;
2525
import java.net.URI;
2626
import java.net.URISyntaxException;
27+
import java.util.HashSet;
2728
import java.util.List;
2829
import java.util.Map;
30+
import java.util.Set;
2931

3032
import static org.mockito.Mockito.when;
3133

@@ -121,10 +123,15 @@ public void testRandomNumberGeneration() throws URISyntaxException {
121123
Metrics.NoopMetrics metrics = new Metrics.NoopMetrics();
122124
HttpSplitChangeFetcher fetcher = HttpSplitChangeFetcher.create(httpClientMock, rootTarget, metrics);
123125

126+
Set<Long> seen = new HashSet<>();
124127
long min = (long)Math.pow(2, 63) * (-1);
125-
for (long x = 0; x < 100000000; x++) {
128+
final long total = 10000000;
129+
for (long x = 0; x < total; x++) {
126130
long r = fetcher.makeRandomTill();
127131
Assert.assertTrue(r < 0 && r > min);
132+
seen.add(r);
128133
}
134+
135+
Assert.assertTrue(seen.size() >= (total * 0.9999));
129136
}
130137
}

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>io.split.client</groupId>
66
<artifactId>java-client-parent</artifactId>
7-
<version>4.1.7-rc4</version>
7+
<version>4.1.7-rc5</version>
88
<dependencyManagement>
99
<dependencies>
1010
<dependency>

testing/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>io.split.client</groupId>
88
<artifactId>java-client-parent</artifactId>
9-
<version>4.1.7-rc4</version>
9+
<version>4.1.7-rc5</version>
1010
</parent>
1111

1212
<artifactId>java-client-testing</artifactId>

0 commit comments

Comments
 (0)