Skip to content

Commit 45b7926

Browse files
author
Ram Prasad Voleti
committed
Replace Dict with Rax for Cluster Nodes
Replace Dict with Rax for Cluster Nodes and construct primaries list on the go, instead of maintaining shards/masters list. Signed-off-by: Ram Prasad Voleti <[email protected]>
1 parent 622a1bf commit 45b7926

File tree

8 files changed

+211
-266
lines changed

8 files changed

+211
-266
lines changed

src/cluster.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -849,10 +849,10 @@ void clusterCommand(client *c) {
849849
} else if (!strcasecmp(c->argv[1]->ptr, "slots") && c->argc == 2) {
850850
/* CLUSTER SLOTS */
851851
clusterCommandSlots(c);
852-
} else if (!strcasecmp(c->argv[1]->ptr,"shards") && c->argc == 2) {
852+
} else if (!strcasecmp(c->argv[1]->ptr, "shards") && c->argc == 2) {
853853
/* CLUSTER SHARDS */
854854
clusterCommandShards(c);
855-
} else if (!strcasecmp(c->argv[1]->ptr,"info") && c->argc == 2) {
855+
} else if (!strcasecmp(c->argv[1]->ptr, "info") && c->argc == 2) {
856856
/* CLUSTER INFO */
857857

858858
sds info = genClusterInfoString();

src/cluster_legacy.c

Lines changed: 178 additions & 238 deletions
Large diffs are not rendered by default.

src/cluster_legacy.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,10 +320,8 @@ struct clusterState {
320320
uint64_t currentEpoch;
321321
int state; /* CLUSTER_OK, CLUSTER_FAIL, ... */
322322
int size; /* Num of primary nodes with at least one slot */
323-
dict *nodes; /* Hash table of name -> clusterNode structures */
323+
rax *nodes; /* Table mapping of name -> clusterNode structures */
324324
dict *nodes_black_list; /* Nodes we don't re-add for a few seconds. */
325-
clusterNode **masters; /* pointers to master nodes */
326-
int nummasters; /* Number of master nodes */
327325
clusterNode *migrating_slots_to[CLUSTER_SLOTS];
328326
clusterNode *importing_slots_from[CLUSTER_SLOTS];
329327
clusterNode *slots[CLUSTER_SLOTS];

src/commands.def

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -896,7 +896,9 @@ struct COMMAND_ARG CLUSTER_SETSLOT_Args[] = {
896896

897897
#ifndef SKIP_CMD_TIPS_TABLE
898898
/* CLUSTER SHARDS tips */
899-
#define CLUSTER_SHARDS_Tips NULL
899+
const char *CLUSTER_SHARDS_Tips[] = {
900+
"nondeterministic_output",
901+
};
900902
#endif
901903

902904
#ifndef SKIP_CMD_KEY_SPECS_TABLE
@@ -1027,7 +1029,7 @@ struct COMMAND_STRUCT CLUSTER_Subcommands[] = {
10271029
{MAKE_CMD("saveconfig","Forces a node to save the cluster configuration to disk.","O(1)","3.0.0",CMD_DOC_NONE,NULL,NULL,"cluster",COMMAND_GROUP_CLUSTER,CLUSTER_SAVECONFIG_History,0,CLUSTER_SAVECONFIG_Tips,0,clusterCommand,2,CMD_NO_ASYNC_LOADING|CMD_ADMIN|CMD_STALE,0,CLUSTER_SAVECONFIG_Keyspecs,0,NULL,0)},
10281030
{MAKE_CMD("set-config-epoch","Sets the configuration epoch for a new node.","O(1)","3.0.0",CMD_DOC_NONE,NULL,NULL,"cluster",COMMAND_GROUP_CLUSTER,CLUSTER_SET_CONFIG_EPOCH_History,0,CLUSTER_SET_CONFIG_EPOCH_Tips,0,clusterCommand,3,CMD_NO_ASYNC_LOADING|CMD_ADMIN|CMD_STALE,0,CLUSTER_SET_CONFIG_EPOCH_Keyspecs,0,NULL,1),.args=CLUSTER_SET_CONFIG_EPOCH_Args},
10291031
{MAKE_CMD("setslot","Binds a hash slot to a node.","O(1)","3.0.0",CMD_DOC_NONE,NULL,NULL,"cluster",COMMAND_GROUP_CLUSTER,CLUSTER_SETSLOT_History,1,CLUSTER_SETSLOT_Tips,0,clusterCommand,-4,CMD_NO_ASYNC_LOADING|CMD_ADMIN|CMD_STALE|CMD_MAY_REPLICATE,0,CLUSTER_SETSLOT_Keyspecs,0,NULL,3),.args=CLUSTER_SETSLOT_Args},
1030-
{MAKE_CMD("shards","Returns the mapping of cluster slots to shards.","O(N) where N is the total number of cluster nodes","7.0.0",CMD_DOC_NONE,NULL,NULL,"cluster",COMMAND_GROUP_CLUSTER,CLUSTER_SHARDS_History,0,CLUSTER_SHARDS_Tips,0,clusterCommand,2,CMD_LOADING|CMD_STALE,0,CLUSTER_SHARDS_Keyspecs,0,NULL,0)},
1032+
{MAKE_CMD("shards","Returns the mapping of cluster slots to shards.","O(N) where N is the total number of cluster nodes","7.0.0",CMD_DOC_NONE,NULL,NULL,"cluster",COMMAND_GROUP_CLUSTER,CLUSTER_SHARDS_History,0,CLUSTER_SHARDS_Tips,1,clusterCommand,2,CMD_LOADING|CMD_STALE,0,CLUSTER_SHARDS_Keyspecs,0,NULL,0)},
10311033
{MAKE_CMD("slaves","Lists the replica nodes of a primary node.","O(N) where N is the number of replicas.","3.0.0",CMD_DOC_DEPRECATED,"`CLUSTER REPLICAS`","5.0.0","cluster",COMMAND_GROUP_CLUSTER,CLUSTER_SLAVES_History,0,CLUSTER_SLAVES_Tips,1,clusterCommand,3,CMD_ADMIN|CMD_STALE,0,CLUSTER_SLAVES_Keyspecs,0,NULL,1),.args=CLUSTER_SLAVES_Args},
10321034
{MAKE_CMD("slot-stats","Return an array of slot usage statistics for slots assigned to the current node.","O(N) where N is the total number of slots based on arguments. O(N*log(N)) with ORDERBY subcommand.","8.0.0",CMD_DOC_NONE,NULL,NULL,"cluster",COMMAND_GROUP_CLUSTER,CLUSTER_SLOT_STATS_History,0,CLUSTER_SLOT_STATS_Tips,2,clusterSlotStatsCommand,-4,CMD_STALE|CMD_LOADING,0,CLUSTER_SLOT_STATS_Keyspecs,0,NULL,1),.args=CLUSTER_SLOT_STATS_Args},
10331035
{MAKE_CMD("slots","Returns the mapping of cluster slots to nodes.","O(N) where N is the total number of Cluster nodes","3.0.0",CMD_DOC_NONE,NULL,NULL,"cluster",COMMAND_GROUP_CLUSTER,CLUSTER_SLOTS_History,2,CLUSTER_SLOTS_Tips,1,clusterCommand,2,CMD_LOADING|CMD_STALE,0,CLUSTER_SLOTS_Keyspecs,0,NULL,0)},

src/commands/cluster-shards.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
"LOADING",
1212
"STALE"
1313
],
14+
"command_tips": [
15+
"NONDETERMINISTIC_OUTPUT"
16+
],
1417
"reply_schema": {
1518
"description": "A nested list of a map of hash ranges and shard nodes describing individual shards.",
1619
"type": "array",

src/rax.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
*/
9696

9797
#define RAX_NODE_MAX_SIZE ((1 << 29) - 1)
98+
#define RAX_OK 1
9899
typedef struct raxNode {
99100
uint32_t iskey : 1; /* Does this node contain a key? */
100101
uint32_t isnull : 1; /* Associated value is NULL (don't store it). */

tests/cluster/tests/28-cluster-shards.tcl

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -285,24 +285,3 @@ test "CLUSTER MYSHARDID reports same shard id after cluster restart" {
285285
assert_equal [dict get $node_ids $i] [R $i cluster myshardid]
286286
}
287287
}
288-
289-
test "Deterministic order of CLUSTER SHARDS response" {
290-
set node_ids {}
291-
for {set j 0} {$j < 8} {incr j} {
292-
set shards_cfg [R $j CLUSTER SHARDS]
293-
set i 0
294-
foreach shard_cfg $shards_cfg {
295-
set nodes [dict get $shard_cfg nodes]
296-
foreach node $nodes {
297-
if {$j == 0} {
298-
# Save the node ids from the first node response
299-
dict set node_ids $i [dict get $node id]
300-
} else {
301-
# Verify the order of the node ids is the same as the first node response
302-
assert_equal [dict get $node id] [dict get $node_ids $i]
303-
}
304-
incr i
305-
}
306-
}
307-
}
308-
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
start_cluster 4 4 {tags {external:skip cluster}} {
2+
test "Deterministic order of CLUSTER SHARDS response" {
3+
set node_ids {}
4+
for {set j 0} {$j < 8} {incr j} {
5+
set shards_cfg [R $j CLUSTER SHARDS]
6+
set i 0
7+
foreach shard_cfg $shards_cfg {
8+
set nodes [dict get $shard_cfg nodes]
9+
foreach node $nodes {
10+
if {$j == 0} {
11+
# Save the node ids from the first node response
12+
dict set node_ids $i [dict get $node id]
13+
} else {
14+
# Verify the order of the node ids is the same as the first node response
15+
assert_equal [dict get $node id] [dict get $node_ids $i]
16+
}
17+
incr i
18+
}
19+
}
20+
}
21+
}
22+
}

0 commit comments

Comments
 (0)