Unverified Commit 4278ed8d authored by iKun's avatar iKun Committed by GitHub
Browse files

redis-cli --bigkeys ,--hotkeys and --memkeys to replica in cluster mode (#12735)



Make redis-cli --bigkeys and --memkeys usable on a replicas in cluster
mode, by sending the READONLY command. This is only if -c is also given.

We don't detect if a node is a master or a replica so we send READONLY
in both cases. The READONLY has no effect on masters.

    Release notes:
    Make redis-cli --bigkeys and --memkeys usable on cluster replicas

---------
Co-authored-by: default avatarViktor Söderqvist <viktor.soderqvist@est.tech>
Co-authored-by: default avatarOran Agra <oran@redislabs.com>
parent a1f91ffa
...@@ -9087,6 +9087,21 @@ static void longStatLoopModeStop(int s) { ...@@ -9087,6 +9087,21 @@ static void longStatLoopModeStop(int s) {
force_cancel_loop = 1; force_cancel_loop = 1;
} }
/* In cluster mode we may need to send the READONLY command.
Ignore the error in case the server isn't using cluster mode. */
static void sendReadOnly(void) {
redisReply *read_reply;
read_reply = redisCommand(context, "READONLY");
if (read_reply == NULL){
fprintf(stderr, "\nI/O error\n");
exit(1);
} else if (read_reply->type == REDIS_REPLY_ERROR && strcmp(read_reply->str, "ERR This instance has cluster support disabled") != 0) {
fprintf(stderr, "Error: %s\n", read_reply->str);
exit(1);
}
freeReplyObject(read_reply);
}
static void findBigKeys(int memkeys, unsigned memkeys_samples) { static void findBigKeys(int memkeys, unsigned memkeys_samples) {
unsigned long long sampled = 0, total_keys, totlen=0, *sizes=NULL, it=0, scan_loops = 0; unsigned long long sampled = 0, total_keys, totlen=0, *sizes=NULL, it=0, scan_loops = 0;
redisReply *reply, *keys; redisReply *reply, *keys;
...@@ -9113,6 +9128,9 @@ static void findBigKeys(int memkeys, unsigned memkeys_samples) { ...@@ -9113,6 +9128,9 @@ static void findBigKeys(int memkeys, unsigned memkeys_samples) {
printf("# average sizes per key type. You can use -i 0.1 to sleep 0.1 sec\n"); printf("# average sizes per key type. You can use -i 0.1 to sleep 0.1 sec\n");
printf("# per 100 SCAN commands (not usually needed).\n\n"); printf("# per 100 SCAN commands (not usually needed).\n\n");
/* Use readonly in cluster */
sendReadOnly();
/* SCAN loop */ /* SCAN loop */
do { do {
/* Calculate approximate percentage completion */ /* Calculate approximate percentage completion */
...@@ -9278,6 +9296,9 @@ static void findHotKeys(void) { ...@@ -9278,6 +9296,9 @@ static void findHotKeys(void) {
printf("# average sizes per key type. You can use -i 0.1 to sleep 0.1 sec\n"); printf("# average sizes per key type. You can use -i 0.1 to sleep 0.1 sec\n");
printf("# per 100 SCAN commands (not usually needed).\n\n"); printf("# per 100 SCAN commands (not usually needed).\n\n");
/* Use readonly in cluster */
sendReadOnly();
/* SCAN loop */ /* SCAN loop */
do { do {
/* Calculate approximate percentage completion */ /* Calculate approximate percentage completion */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment