diff --git a/src/cluster_legacy.c b/src/cluster_legacy.c index f1c9eb1fcf..41f3bc9a6d 100644 --- a/src/cluster_legacy.c +++ b/src/cluster_legacy.c @@ -6519,6 +6519,10 @@ int clusterCommandSpecial(client *c) { addReplyErrorFormat(c, "Invalid node address specified: %s:%s", (char *)c->argv[2]->ptr, (char *)c->argv[3]->ptr); } else { + sds client = catClientInfoShortString(sdsempty(), c, server.hide_user_data_from_log); + serverLog(LL_NOTICE, "Cluster meet %s:%lld (user request from '%s').", (char *)c->argv[2]->ptr, port, + client); + sdsfree(client); addReply(c, shared.ok); } } else if (!strcasecmp(c->argv[1]->ptr, "flushslots") && c->argc == 2) { @@ -6633,6 +6637,9 @@ int clusterCommandSpecial(client *c) { addReplyError(c, "Can't forget my master!"); return 1; } + sds client = catClientInfoShortString(sdsempty(), c, server.hide_user_data_from_log); + serverLog(LL_NOTICE, "Cluster forget %s (user request from '%s').", (char *)c->argv[2]->ptr, client); + sdsfree(client); clusterBlacklistAddNode(n); clusterDelNode(n); clusterDoBeforeSleep(CLUSTER_TODO_UPDATE_STATE | CLUSTER_TODO_SAVE_CONFIG); @@ -6722,7 +6729,7 @@ int clusterCommandSpecial(client *c) { } resetManualFailover(); server.cluster->mf_end = mstime() + CLUSTER_MF_TIMEOUT; - sds client = catClientInfoString(sdsempty(), c, server.hide_user_data_from_log); + sds client = catClientInfoShortString(sdsempty(), c, server.hide_user_data_from_log); if (takeover) { /* A takeover does not perform any initial check. It just @@ -6801,6 +6808,9 @@ int clusterCommandSpecial(client *c) { "master nodes containing keys"); return 1; } + sds client = catClientInfoShortString(sdsempty(), c, server.hide_user_data_from_log); + serverLog(LL_NOTICE, "Cluster reset (user request from '%s').", client); + sdsfree(client); clusterReset(hard); addReply(c, shared.ok); } else if (!strcasecmp(c->argv[1]->ptr, "links") && c->argc == 2) { diff --git a/src/networking.c b/src/networking.c index 96dd05d505..32ed798f99 100644 --- a/src/networking.c +++ b/src/networking.c @@ -3372,6 +3372,29 @@ sds catClientInfoString(sds s, client *client, int hide_user_data) { return ret; } +/* Concatenate a string representing the state of a client in a human + * readable format, into the sds string 's'. + * + * This is a simplified and shortened version of catClientInfoString, + * it only added some basic fields for tracking clients. */ +sds catClientInfoShortString(sds s, client *client, int hide_user_data) { + if (!server.crashed) waitForClientIO(client); + char conninfo[CONN_INFO_LEN]; + + sds ret = sdscatfmt( + s, + FMTARGS( + "id=%U", (unsigned long long)client->id, + " addr=%s", getClientPeerId(client), + " laddr=%s", getClientSockname(client), + " %s", connGetInfo(client->conn, conninfo, sizeof(conninfo)), + " name=%s", hide_user_data ? "*redacted*" : (client->name ? (char *)client->name->ptr : ""), + " user=%s", hide_user_data ? "*redacted*" : (client->user ? client->user->name : "(superuser)"), + " lib-name=%s", client->lib_name ? (char *)client->lib_name->ptr : "", + " lib-ver=%s", client->lib_ver ? (char *)client->lib_ver->ptr : "")); + return ret; +} + sds getAllClientsInfoString(int type, int hide_user_data) { listNode *ln; listIter li; diff --git a/src/replication.c b/src/replication.c index 48e98ab8e7..06894a2102 100644 --- a/src/replication.c +++ b/src/replication.c @@ -1051,7 +1051,7 @@ void syncCommand(client *c) { } else { replicationUnsetPrimary(); } - sds client = catClientInfoString(sdsempty(), c, server.hide_user_data_from_log); + sds client = catClientInfoShortString(sdsempty(), c, server.hide_user_data_from_log); serverLog(LL_NOTICE, "PRIMARY MODE enabled (failover request from '%s')", client); sdsfree(client); } else { @@ -3978,7 +3978,7 @@ void replicaofCommand(client *c) { if (!strcasecmp(c->argv[1]->ptr, "no") && !strcasecmp(c->argv[2]->ptr, "one")) { if (server.primary_host) { replicationUnsetPrimary(); - sds client = catClientInfoString(sdsempty(), c, server.hide_user_data_from_log); + sds client = catClientInfoShortString(sdsempty(), c, server.hide_user_data_from_log); serverLog(LL_NOTICE, "PRIMARY MODE enabled (user request from '%s')", client); sdsfree(client); } @@ -4007,7 +4007,7 @@ void replicaofCommand(client *c) { /* There was no previous primary or the user specified a different one, * we can continue. */ replicationSetPrimary(c->argv[1]->ptr, port, 0); - sds client = catClientInfoString(sdsempty(), c, server.hide_user_data_from_log); + sds client = catClientInfoShortString(sdsempty(), c, server.hide_user_data_from_log); serverLog(LL_NOTICE, "REPLICAOF %s:%d enabled (user request from '%s')", server.primary_host, server.primary_port, client); sdsfree(client); diff --git a/src/server.c b/src/server.c index e8c13dd763..8756997fb5 100644 --- a/src/server.c +++ b/src/server.c @@ -4317,7 +4317,7 @@ int prepareForShutdown(client *c, int flags) { server.shutdown_flags = flags; if (c != NULL) { - sds client = catClientInfoString(sdsempty(), c, server.hide_user_data_from_log); + sds client = catClientInfoShortString(sdsempty(), c, server.hide_user_data_from_log); serverLog(LL_NOTICE, "User requested shutdown... (user request from '%s')", client); sdsfree(client); } else { diff --git a/src/server.h b/src/server.h index 5cf56e9c86..711ca7a936 100644 --- a/src/server.h +++ b/src/server.h @@ -2846,6 +2846,7 @@ char *getClientPeerId(client *client); char *getClientSockName(client *client); int isClientConnIpV6(client *c); sds catClientInfoString(sds s, client *client, int hide_user_data); +sds catClientInfoShortString(sds s, client *client, int hide_user_data); sds getAllClientsInfoString(int type, int hide_user_data); int clientSetName(client *c, robj *name, const char **err); void rewriteClientCommandVector(client *c, int argc, ...);