Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ public void accept(DatabaseSwitchEvent e) {
AtomicLong retryingThreadsCounter = new AtomicLong(0);
AtomicLong failedCommandsAfterFailover = new AtomicLong(0);
AtomicReference<Instant> lastFailedCommandAt = new AtomicReference<>();
Endpoint primaryEndpoint = client.getActiveDatabaseEndpoint();

// Start thread that imitates an application that uses the client
MultiThreadedFakeApp fakeApp = new MultiThreadedFakeApp(client, (UnifiedJedis c) -> {
Expand All @@ -130,13 +131,15 @@ public void accept(DatabaseSwitchEvent e) {
int maxTries = 500;
int retryingDelay = 5;
while (true) {
boolean attemptToExecuteOnFailedCluster = true;
try {
Map<String, String> executionInfo = new HashMap<String, String>() {
{
put("threadId", String.valueOf(threadId));
put("cluster", reporter.getCurrentClusterName());
}
};
attemptToExecuteOnFailedCluster = client.getActiveDatabaseEndpoint() == primaryEndpoint;
client.xadd("execution_log", StreamEntryID.NEW_ENTRY, executionInfo);
executedCommands.incrementAndGet();

Expand All @@ -148,7 +151,8 @@ public void accept(DatabaseSwitchEvent e) {
break;
} catch (JedisConnectionException e) {

if (reporter.failoverHappened) {
if (reporter.failoverHappened && !reporter.failbackHappened
&& attemptToExecuteOnFailedCluster) {
failedCommandsAfterFailover.incrementAndGet();
lastFailedCommandAt.set(Instant.now());
}
Expand Down Expand Up @@ -219,9 +223,12 @@ public void accept(DatabaseSwitchEvent e) {
log.info("Failback happened at: {}", reporter.failbackAt);
log.info("Last failed command at: {}", lastFailedCommandAt.get());
log.info("Failed commands after failover: {}", failedCommandsAfterFailover.get());
Duration fullFailoverTime = Duration.between(reporter.failoverAt, lastFailedCommandAt.get());
log.info("Full failover time: {} s", fullFailoverTime.getSeconds());

if (lastFailedCommandAt.get() == null) {
log.info("No failed commands after failover!");
} else {
Duration fullFailoverTime = Duration.between(reporter.failoverAt, lastFailedCommandAt.get());
log.info("Full failover time: {} s", fullFailoverTime.getSeconds());
}
assertEquals(0, pool1.getNumActive());
assertTrue(fakeApp.capturedExceptions().isEmpty());
assertTrue(reporter.failoverHappened);
Expand Down
Loading