Skip to content

Commit

Permalink
Limit CLUSTER_CANT_FAILOVER_DATA_AGE log to 10 times period (valkey-i…
Browse files Browse the repository at this point in the history
…o#1189)

If a replica is step into data_age too old stage, it can not
trigger the failover and currently it can not be automatically
recovered and we will print a log every
CLUSTER_CANT_FAILOVER_RELOG_PERIOD,
which is every second. If the primary has not recovered or there is
no manual failover, this log will flood the log file.

In this case, limit its frequency to 10 times period, which is
10 seconds in our code. Also in this data_age too old stage,
the repeated logs also can stand for the progress of the failover.

See also valkey-io#780 for more details about it.

Signed-off-by: Binbin <[email protected]>
Co-authored-by: Ping Xie <[email protected]>
  • Loading branch information
enjoy-binbin and PingXie authored Oct 24, 2024
1 parent c419524 commit a21fe71
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/cluster_legacy.c
Original file line number Diff line number Diff line change
Expand Up @@ -4433,11 +4433,18 @@ int clusterGetReplicaRank(void) {
void clusterLogCantFailover(int reason) {
char *msg;
static time_t lastlog_time = 0;
time_t now = time(NULL);

/* Don't log if we have the same reason for some time. */
if (reason == server.cluster->cant_failover_reason &&
time(NULL) - lastlog_time < CLUSTER_CANT_FAILOVER_RELOG_PERIOD)
/* General logging suppression if the same reason has occurred recently. */
if (reason == server.cluster->cant_failover_reason && now - lastlog_time < CLUSTER_CANT_FAILOVER_RELOG_PERIOD) {
return;
}

/* Special case: If the failure reason is due to data age, log 10 times less frequently. */
if (reason == server.cluster->cant_failover_reason && reason == CLUSTER_CANT_FAILOVER_DATA_AGE &&
now - lastlog_time < 10 * CLUSTER_CANT_FAILOVER_RELOG_PERIOD) {
return;
}

server.cluster->cant_failover_reason = reason;

Expand Down

0 comments on commit a21fe71

Please sign in to comment.