Exclude aux fields from "cluster nodes" and "cluster replicas" output (#12166)

This commit excludes aux fields from the output of the `cluster nodes` and `cluster replicas` command.
We may decide to re-introduce them in some form or another in the future, but not in v7.2.
This commit is contained in:
Ping Xie 2023-05-23 08:32:37 -07:00 committed by GitHub
parent 07ea220419
commit 4c74dd986f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 17 additions and 36 deletions

View File

@ -601,7 +601,7 @@ int clusterSaveConfig(int do_fsync) {
/* Get the nodes description and concatenate our "vars" directive to
* save currentEpoch and lastVoteEpoch. */
ci = clusterGenNodesDescription(CLUSTER_NODE_HANDSHAKE, 0);
ci = clusterGenNodesDescription(NULL, CLUSTER_NODE_HANDSHAKE, 0);
ci = sdscatprintf(ci,"vars currentEpoch %llu lastVoteEpoch %llu\n",
(unsigned long long) server.cluster->currentEpoch,
(unsigned long long) server.cluster->lastVoteEpoch);
@ -5000,7 +5000,7 @@ sds representSlotInfo(sds ci, uint16_t *slot_info_pairs, int slot_info_pairs_cou
* See clusterGenNodesDescription() top comment for more information.
*
* The function returns the string representation as an SDS string. */
sds clusterGenNodeDescription(clusterNode *node, int use_pport) {
sds clusterGenNodeDescription(client *c, clusterNode *node, int use_pport) {
int j, start;
sds ci;
int port = use_pport && node->pport ? node->pport : node->port;
@ -5021,13 +5021,16 @@ sds clusterGenNodeDescription(clusterNode *node, int use_pport) {
node->cport);
}
/* Node's aux fields */
/* Don't expose aux fields to any clients yet but do allow them
* to be persisted to nodes.conf */
if (c == NULL) {
for (int i = af_start; i < af_count; i++) {
if (auxFieldHandlers[i].isPresent(node)) {
ci = sdscatprintf(ci, ",%s=", auxFieldHandlers[i].field);
ci = auxFieldHandlers[i].getter(node, ci);
}
}
}
/* Flags */
ci = sdscatlen(ci," ",1);
@ -5150,7 +5153,7 @@ void clusterFreeNodesSlotsInfo(clusterNode *n) {
* The representation obtained using this function is used for the output
* of the CLUSTER NODES function, and as format for the cluster
* configuration file (nodes.conf) for a given node. */
sds clusterGenNodesDescription(int filter, int use_pport) {
sds clusterGenNodesDescription(client *c, int filter, int use_pport) {
sds ci = sdsempty(), ni;
dictIterator *di;
dictEntry *de;
@ -5163,7 +5166,7 @@ sds clusterGenNodesDescription(int filter, int use_pport) {
clusterNode *node = dictGetVal(de);
if (node->flags & filter) continue;
ni = clusterGenNodeDescription(node, use_pport);
ni = clusterGenNodeDescription(c, node, use_pport);
ci = sdscatsds(ci,ni);
sdsfree(ni);
ci = sdscatlen(ci,"\n",1);
@ -5737,7 +5740,7 @@ NULL
* be non-TLS). */
int use_pport = (server.tls_cluster &&
c->conn && (c->conn->type != connectionTypeTls()));
sds nodes = clusterGenNodesDescription(0, use_pport);
sds nodes = clusterGenNodesDescription(c, 0, use_pport);
addReplyVerbatim(c,nodes,sdslen(nodes),"txt");
sdsfree(nodes);
} else if (!strcasecmp(c->argv[1]->ptr,"myid") && c->argc == 2) {
@ -6104,7 +6107,7 @@ NULL
c->conn && (c->conn->type != connectionTypeTls()));
addReplyArrayLen(c,n->numslaves);
for (j = 0; j < n->numslaves; j++) {
sds ni = clusterGenNodeDescription(n->slaves[j], use_pport);
sds ni = clusterGenNodeDescription(c, n->slaves[j], use_pport);
addReplyBulkCString(c,ni);
sdsfree(ni);
}

View File

@ -422,7 +422,7 @@ void slotToChannelAdd(sds channel);
void slotToChannelDel(sds channel);
void clusterUpdateMyselfHostname(void);
void clusterUpdateMyselfAnnouncedPorts(void);
sds clusterGenNodesDescription(int filter, int use_pport);
sds clusterGenNodesDescription(client *c, int filter, int use_pport);
sds genClusterInfoString(void);
void freeClusterLink(clusterLink *link);

View File

@ -1803,7 +1803,7 @@ sds genClusterDebugString(sds infostring) {
infostring = sdscatprintf(infostring, "\r\n# Cluster info\r\n");
infostring = sdscatsds(infostring, genClusterInfoString());
infostring = sdscatprintf(infostring, "\n------ CLUSTER NODES OUTPUT ------\n");
infostring = sdscatsds(infostring, clusterGenNodesDescription(0, 0));
infostring = sdscatsds(infostring, clusterGenNodesDescription(NULL, 0, 0));
return infostring;
}

View File

@ -19,8 +19,7 @@ proc get_cluster_nodes {id {status "*"}} {
set args [split $l]
set node [dict create \
id [lindex $args 0] \
addr [lindex [split [lindex $args 1] ,] 0] \
shard-id [lindex [split [lindex [split [lindex $args 1] ,] 2] = ] 1]\
addr [lindex $args 1] \
flags [split [lindex $args 2] ,] \
slaveof [lindex $args 3] \
ping_sent [lindex $args 4] \

View File

@ -227,26 +227,6 @@ test "CLUSTER MYSHARDID reports same id for both primary and replica" {
}
}
test "CLUSTER NODES reports correct shard id" {
for {set i 0} {$i < 8} {incr i} {
set nodes [get_cluster_nodes $i]
set node_id_to_shardid_mapping []
foreach n $nodes {
set node_shard_id [dict get $n shard-id]
set node_id [dict get $n id]
assert_equal [string length $node_shard_id] 40
if {[dict exists $node_id_to_shardid_mapping $node_id]} {
assert_equal [dict get $node_id_to_shardid_mapping $node_id] $node_shard_id
} else {
dict set node_id_to_shardid_mapping $node_id $node_shard_id
}
if {[lindex [dict get $n flags] 0] eq "myself"} {
assert_equal [R $i cluster myshardid] [dict get $n shard-id]
}
}
}
}
test "New replica receives primary's shard id" {
#find a primary
set id 0

View File

@ -18,7 +18,6 @@ start_cluster 2 2 {tags {external:skip cluster}} {
set id [R 0 CLUSTER MYID]
assert_equal {0} [R 0 CLUSTER count-failure-reports $id]
assert_match "*shard-id*" [R 0 CLUSTER slaves $id]
R 0 flushall
assert_equal {OK} [R 0 CLUSTER flushslots]