diff --git a/src/cluster.c b/src/cluster.c index 69029164e..98a7a902f 100644 --- a/src/cluster.c +++ b/src/cluster.c @@ -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,11 +5021,14 @@ sds clusterGenNodeDescription(clusterNode *node, int use_pport) { node->cport); } - /* Node's aux fields */ - 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); + /* 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); + } } } @@ -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); } diff --git a/src/cluster.h b/src/cluster.h index b5ab7d5a5..eb56f581f 100644 --- a/src/cluster.h +++ b/src/cluster.h @@ -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); diff --git a/src/debug.c b/src/debug.c index b2c3de69a..94c3c2658 100644 --- a/src/debug.c +++ b/src/debug.c @@ -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; } diff --git a/tests/cluster/cluster.tcl b/tests/cluster/cluster.tcl index 7b5f0f951..9931eac84 100644 --- a/tests/cluster/cluster.tcl +++ b/tests/cluster/cluster.tcl @@ -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] \ diff --git a/tests/cluster/tests/28-cluster-shards.tcl b/tests/cluster/tests/28-cluster-shards.tcl index 726c460c3..ef4067ff0 100644 --- a/tests/cluster/tests/28-cluster-shards.tcl +++ b/tests/cluster/tests/28-cluster-shards.tcl @@ -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 diff --git a/tests/unit/cluster/misc.tcl b/tests/unit/cluster/misc.tcl index 3ff21010a..cd66697c4 100644 --- a/tests/unit/cluster/misc.tcl +++ b/tests/unit/cluster/misc.tcl @@ -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]