Skip to content

Commit 690760f

Browse files
committed
Updates for the latest changes to the cross-cluster-failover PR
1 parent 6a0ef5e commit 690760f

File tree

3 files changed

+23
-19
lines changed

3 files changed

+23
-19
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,8 @@ RedisBenchmark.jedisSimpleSet avgt 0.119 ms/op
208208
</p>
209209
</details>
210210

211-
#### Fallback Tests:
212-
The test framework creates a pid file with MultiClusterIndex under jedisPid folder in the current folder (user directory). If you need to fallback to another database endpoint from provided `redis.connection` comma separated list of endpoints, then move the pid file to that index (Indexes are ordered from 1 to however many endpoints you provide)
211+
#### FaILback Tests:
212+
The test framework creates a pid file with MultiClusterIndex under jedisPid folder in the current folder (user directory). If you need to failback to another database endpoint from provided `redis.connection` comma separated list of endpoints, then move the pid file to that index (Indexes are ordered from 1 to however many endpoints you provide)
213213
````bash
214214
mv jedisPid/1.pid jedisPid/2.pid
215215
````
@@ -220,7 +220,7 @@ Creating 618 of 100000 key(s) to the benchmark: [.....] 0%
220220
Detected file delete event. File: /Users/viragtripathi/idea_workspace/redis-benchmark/jedisPid/1.pid
221221

222222
Detected file create event. File: /Users/viragtripathi/idea_workspace/redis-benchmark/jedisPid/2.pid
223-
User have requested to fallback to MultiClusterIndex 2
223+
User have requested to failback to ActiveMultiClusterIndex=2
224224
Creating 623 of 100000 key(s) to the benchmark: [.....] 0%[Thread-3] WARN redis.clients.jedis.providers.MultiClusterPooledConnectionProvider - CircuitBreaker changed the connection pool from 'cluster:1:127.0.0.1:14002' to 'cluster:2:127.0.0.1:14003'
225225
````
226226
````bash
@@ -232,7 +232,7 @@ Creating 1405 of 100000 key(s) to the benchmark: [.....] 1%
232232
Detected file delete event. File: /Users/viragtripathi/idea_workspace/redis-benchmark/jedisPid/2.pid
233233

234234
Detected file create event. File: /Users/viragtripathi/idea_workspace/redis-benchmark/jedisPid/3.pid
235-
User have requested to fallback to MultiClusterIndex 3
235+
User have requested to failback to ActiveMultiClusterIndex=3
236236
Creating 1410 of 100000 key(s) to the benchmark: [.....] 1%[Thread-3] WARN redis.clients.jedis.providers.MultiClusterPooledConnectionProvider - CircuitBreaker changed the connection pool from 'cluster:2:127.0.0.1:14003' to 'cluster:3:127.0.0.1:14004'
237237
Creating 2691 of 100000 key(s) to the benchmark: [.....] 2%
238238
````
@@ -243,7 +243,7 @@ Expected output:
243243
````log
244244
Creating 2691 of 100000 key(s) to the benchmark: [.....] 2%
245245
Detected file create event. File: /Users/viragtripathi/idea_workspace/redis-benchmark/jedisPid/1.pid
246-
User have requested to fallback to MultiClusterIndex 1
246+
User have requested to failback to ActiveMultiClusterIndex=1
247247
Creating 2692 of 100000 key(s) to the benchmark: [.....] 2%
248248
Detected file delete event. File: /Users/viragtripathi/idea_workspace/redis-benchmark/jedisPid/3.pid
249249
[Thread-3] WARN redis.clients.jedis.providers.MultiClusterPooledConnectionProvider - CircuitBreaker changed the connection pool from 'cluster:3:127.0.0.1:14004' to 'cluster:1:127.0.0.1:14002'

src/main/java/com/redis/benchmark/utils/FileEventListener.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ public void start(String dir, int pollInterval) throws Exception {
2626
@Override
2727
public void onFileCreate(File file) {
2828
System.out.println("\nDetected file create event. File: " + file);
29-
int fallBackIndex = Integer.parseInt(file.getName().substring(0, 1));
30-
System.out.println("User have requested to fallback to MultiClusterIndex " + fallBackIndex);
31-
JedisConnectionManagement.provider.setActiveMultiClusterIndex(fallBackIndex);
29+
int activeClusterFailBackIndex = Integer.parseInt(file.getName().substring(0, 1));
30+
System.out.println("User have requested to failback to ActiveMultiClusterIndex=" + activeClusterFailBackIndex);
31+
JedisConnectionManagement.provider.setActiveMultiClusterIndex(activeClusterFailBackIndex);
3232
}
3333

3434
@Override
@@ -39,9 +39,9 @@ public void onFileDelete(File file) {
3939
@Override
4040
public void onFileChange(File file) {
4141
System.out.println("\nDetected file change event. File: " + file);
42-
int fallBackIndex = Integer.parseInt(file.getName().substring(0, 1));
43-
System.out.println("User have requested to fallback to MultiClusterIndex " + fallBackIndex);
44-
JedisConnectionManagement.provider.setActiveMultiClusterIndex(fallBackIndex);
42+
int activeClusterFailBackIndex = Integer.parseInt(file.getName().substring(0, 1));
43+
System.out.println("User have requested to failback to ActiveMultiClusterIndex=" + activeClusterFailBackIndex);
44+
JedisConnectionManagement.provider.setActiveMultiClusterIndex(activeClusterFailBackIndex);
4545
}
4646
};
4747
observer.addListener(listener);

src/main/java/com/redis/benchmark/utils/JedisConnectionManagement.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,9 @@ private void createJedisConnection() {
5757
multiClusterJedisClientConfig.circuitBreakerSlidingWindowMinCalls(Integer.parseInt(BenchmarkConfiguration.get().getConnectionCircuitBreakerSlidingWindowMinCalls()));
5858
multiClusterJedisClientConfig.circuitBreakerFailureRateThreshold(Float.parseFloat(BenchmarkConfiguration.get().getConnectionCircuitBreakerFailureRateThreshold()));
5959
provider = new MultiClusterPooledConnectionProvider(multiClusterJedisClientConfig.build());
60+
provider.setClusterFailoverPostProcessor(a -> System.out.println("\nActiveMultiClusterIndex=" + a));
6061

6162
connectionManagement.unifiedJedis = new UnifiedJedis(provider);
62-
63-
activeMultiClusterIndex = Integer.parseInt(provider.getClusterCircuitBreaker().getName().split(":")[1]);
64-
pidPath = System.getProperty("user.dir") + File.separator + "jedisPid" + File.separator;
65-
pidFile = pidPath + activeMultiClusterIndex + ".pid";
66-
67-
PidFile.create(Path.of(pidFile), true, activeMultiClusterIndex);
68-
69-
FileEventListener.FILE_EVENT_LISTENER.start(pidPath, 1000);
7063
}
7164
} catch (Exception e) {
7265
System.err.println("------------------- Failed UnifiedJedis " + e.getMessage());
@@ -77,6 +70,17 @@ public static JedisCommands getCommands() {
7770
if (!connectionCreated) {
7871
connectionManagement.createJedisConnection();
7972
connectionCreated = Boolean.TRUE;
73+
74+
activeMultiClusterIndex = Integer.parseInt(provider.getClusterCircuitBreaker().getName().split(":")[1]);
75+
pidPath = System.getProperty("user.dir") + File.separator + "jedisPid" + File.separator;
76+
pidFile = pidPath + activeMultiClusterIndex + ".pid";
77+
78+
try {
79+
PidFile.create(Path.of(pidFile), true, activeMultiClusterIndex);
80+
FileEventListener.FILE_EVENT_LISTENER.start(pidPath, 1000);
81+
} catch (Exception e) {
82+
System.err.println("------------------- Failed " + e.getMessage());
83+
}
8084
}
8185
return connectionManagement.unifiedJedis;
8286
}

0 commit comments

Comments
 (0)