Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/cluster_legacy.c
Original file line number Diff line number Diff line change
Expand Up @@ -6906,9 +6906,11 @@ void addNodeDetailsToShardReply(client *c, clusterNode *node) {
setDeferredMapLen(c, node_replylen, reply_count);
}

/* Add to the output buffer of the given client, an array of slot (start, end)
* pair owned by the shard, also the primary and set of replica(s) along with
* information about each node. */
/* Add to the output buffer of the given client,
* an array of slot (start, end) pair owned by the shard,
* an array of the primary and set of replica(s) along with information about each node,
* an array of shard info, like shard-id and so on
*/
void clusterCommandShards(client *c) {
addReplyArrayLen(c, dictSize(server.cluster->shards));
/* This call will add slot_info_pairs to all nodes */
Expand All @@ -6917,7 +6919,7 @@ void clusterCommandShards(client *c) {
for (dictEntry *de = dictNext(di); de != NULL; de = dictNext(di)) {
list *nodes = dictGetVal(de);
serverAssert(listLength(nodes) > 0);
addReplyMapLen(c, 2);
addReplyMapLen(c, 3);
addReplyBulkCString(c, "slots");

/* Find a node which has the slot information served by this shard. */
Expand Down Expand Up @@ -6950,6 +6952,10 @@ void clusterCommandShards(client *c) {
addNodeDetailsToShardReply(c, n);
clusterFreeNodesSlotsInfo(n);
}
addReplyBulkCString(c, "shard");
addReplyMapLen(c, 1);
addReplyBulkCString(c, "id");
addReplyBulkCBuffer(c, dictGetKey(de), CLUSTER_NAMELEN);
}
dictReleaseIterator(di);
}
Expand Down
30 changes: 30 additions & 0 deletions tests/cluster/tests/28-cluster-shards.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -285,3 +285,33 @@ test "CLUSTER MYSHARDID reports same shard id after cluster restart" {
assert_equal [dict get $node_ids $i] [R $i cluster myshardid]
}
}

test "CLUSTER SHARDS id response validation" {
# For each node in the cluster
for {set i 0} {$i < $::cluster_master_nodes + $::cluster_replica_nodes} {incr i} {
# Get the CLUSTER SHARDS output from this node
set shards [R $i CLUSTER SHARDS]
set seen_shard_ids {}

# For each shard in the output
foreach shard $shards {
set shard_dict [dict create {*}$shard]

# 1. Verify 'shard' key exists
assert {[dict exists $shard_dict shard]}
set shard_info [dict get $shard_dict shard]
set shard_info_dict [dict create {*}$shard_info]

# 2. Verify 'id' key exists in the nested shard info
assert {[dict exists $shard_info_dict id]}
set shard_id [dict get $shard_info_dict id]

# 3. Verify shard_id is a 40-char string
assert {[string length $shard_id] == 40}

# 4. Verify that for a given node's output, all shard IDs are unique
assert {[dict exists $seen_shard_ids $shard_id] == 0}
dict set seen_shard_ids $shard_id 1
}
}
}