diff --git a/src/redis.c b/src/redis.c index e5e6405e495485cba65d5d1f6a07cdaf8f5618c8..4575e271bdb030168fdb9406a5c6e937c0efb6d0 100644 --- a/src/redis.c +++ b/src/redis.c @@ -1350,6 +1350,9 @@ void initServer() { server.stat_peak_memory = 0; server.stat_fork_time = 0; server.stat_rejected_conn = 0; + server.stat_sync_full = 0; + server.stat_sync_partial_ok = 0; + server.stat_sync_partial_err = 0; memset(server.ops_sec_samples,0,sizeof(server.ops_sec_samples)); server.ops_sec_idx = 0; server.ops_sec_last_sample_time = mstime(); @@ -2069,6 +2072,9 @@ sds genRedisInfoString(char *section) { "total_commands_processed:%lld\r\n" "instantaneous_ops_per_sec:%lld\r\n" "rejected_connections:%lld\r\n" + "sync_full:%lld\r\n" + "sync_partial_ok:%lld\r\n" + "sync_partial_err:%lld\r\n" "expired_keys:%lld\r\n" "evicted_keys:%lld\r\n" "keyspace_hits:%lld\r\n" @@ -2080,6 +2086,9 @@ sds genRedisInfoString(char *section) { server.stat_numcommands, getOperationsPerSecond(), server.stat_rejected_conn, + server.stat_sync_full, + server.stat_sync_partial_ok, + server.stat_sync_partial_err, server.stat_expiredkeys, server.stat_evictedkeys, server.stat_keyspace_hits, diff --git a/src/redis.h b/src/redis.h index 100896b50901d840d441631eabb740ee0a144c57..9a5e05a89b493673f5270de6ec36f891abc1119b 100644 --- a/src/redis.h +++ b/src/redis.h @@ -561,6 +561,9 @@ struct redisServer { size_t stat_peak_memory; /* Max used memory record */ long long stat_fork_time; /* Time needed to perform latest fork() */ long long stat_rejected_conn; /* Clients rejected because of maxclients */ + long long stat_sync_full; /* Number of full resyncs with slaves. */ + long long stat_sync_partial_ok; /* Number of accepted PSYNC requests. */ + long long stat_sync_partial_err;/* Number of unaccepted PSYNC requests. */ list *slowlog; /* SLOWLOG list of commands */ long long slowlog_entry_id; /* SLOWLOG current entry ID */ long long slowlog_log_slower_than; /* SLOWLOG time limit (to get logged) */ diff --git a/src/replication.c b/src/replication.c index c17e5aa79edb60393087c10be165aec1cb17537d..36ee9b9126c939d75f543d812f72f4ef01ab7000 100644 --- a/src/replication.c +++ b/src/replication.c @@ -490,8 +490,23 @@ void syncCommand(redisClient *c) { * * So the slave knows the new runid and offset to try a PSYNC later * if the connection with the master is lost. */ - if (!strcasecmp(c->argv[0]->ptr,"psync") && - masterTryPartialResynchronization(c) == REDIS_OK) return; + if (!strcasecmp(c->argv[0]->ptr,"psync")) { + if (masterTryPartialResynchronization(c) == REDIS_OK) { + server.stat_sync_partial_ok++; + return; /* No full resync needed, return. */ + } else { + char *master_runid = c->argv[1]->ptr; + + /* Increment stats for failed PSYNCs, but only if the + * runid is not "?", as this is used by slaves to force a full + * resync on purpose when they are not albe to partially + * resync. */ + if (master_runid[0] != '?') server.stat_sync_partial_err++; + } + } + + /* Full resynchronization. */ + server.stat_sync_full++; /* Here we need to check if there is a background saving operation * in progress, or if it is required to start one */