Merge pull request #7123 from fayadexinqing/optimizeClusterSlots
Optimize the command of cluster slots
This commit is contained in:
commit
0dd08d746e
@ -4191,11 +4191,17 @@ void clusterReplyMultiBulkSlots(client *c) {
|
|||||||
while((de = dictNext(di)) != NULL) {
|
while((de = dictNext(di)) != NULL) {
|
||||||
clusterNode *node = dictGetVal(de);
|
clusterNode *node = dictGetVal(de);
|
||||||
int j = 0, start = -1;
|
int j = 0, start = -1;
|
||||||
|
int i, nested_elements = 0;
|
||||||
|
|
||||||
/* Skip slaves (that are iterated when producing the output of their
|
/* Skip slaves (that are iterated when producing the output of their
|
||||||
* master) and masters not serving any slot. */
|
* master) and masters not serving any slot. */
|
||||||
if (!nodeIsMaster(node) || node->numslots == 0) continue;
|
if (!nodeIsMaster(node) || node->numslots == 0) continue;
|
||||||
|
|
||||||
|
for(i = 0; i < node->numslaves; i++) {
|
||||||
|
if (nodeFailed(node->slaves[i])) continue;
|
||||||
|
nested_elements++;
|
||||||
|
}
|
||||||
|
|
||||||
for (j = 0; j < CLUSTER_SLOTS; j++) {
|
for (j = 0; j < CLUSTER_SLOTS; j++) {
|
||||||
int bit, i;
|
int bit, i;
|
||||||
|
|
||||||
@ -4203,8 +4209,7 @@ void clusterReplyMultiBulkSlots(client *c) {
|
|||||||
if (start == -1) start = j;
|
if (start == -1) start = j;
|
||||||
}
|
}
|
||||||
if (start != -1 && (!bit || j == CLUSTER_SLOTS-1)) {
|
if (start != -1 && (!bit || j == CLUSTER_SLOTS-1)) {
|
||||||
int nested_elements = 3; /* slots (2) + master addr (1). */
|
addReplyArrayLen(c, nested_elements + 3); /* slots (2) + master addr (1). */
|
||||||
void *nested_replylen = addReplyDeferredLen(c);
|
|
||||||
|
|
||||||
if (bit && j == CLUSTER_SLOTS-1) j++;
|
if (bit && j == CLUSTER_SLOTS-1) j++;
|
||||||
|
|
||||||
@ -4234,9 +4239,7 @@ void clusterReplyMultiBulkSlots(client *c) {
|
|||||||
addReplyBulkCString(c, node->slaves[i]->ip);
|
addReplyBulkCString(c, node->slaves[i]->ip);
|
||||||
addReplyLongLong(c, node->slaves[i]->port);
|
addReplyLongLong(c, node->slaves[i]->port);
|
||||||
addReplyBulkCBuffer(c, node->slaves[i]->name, CLUSTER_NAMELEN);
|
addReplyBulkCBuffer(c, node->slaves[i]->name, CLUSTER_NAMELEN);
|
||||||
nested_elements++;
|
|
||||||
}
|
}
|
||||||
setDeferredArrayLen(c, nested_replylen, nested_elements);
|
|
||||||
num_masters++;
|
num_masters++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
44
tests/cluster/tests/15-cluster-slots.tcl
Normal file
44
tests/cluster/tests/15-cluster-slots.tcl
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
source "../tests/includes/init-tests.tcl"
|
||||||
|
|
||||||
|
proc cluster_allocate_mixedSlots {n} {
|
||||||
|
set slot 16383
|
||||||
|
while {$slot >= 0} {
|
||||||
|
set node [expr {$slot % $n}]
|
||||||
|
lappend slots_$node $slot
|
||||||
|
incr slot -1
|
||||||
|
}
|
||||||
|
for {set j 0} {$j < $n} {incr j} {
|
||||||
|
R $j cluster addslots {*}[set slots_${j}]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
proc create_cluster_with_mixedSlot {masters slaves} {
|
||||||
|
cluster_allocate_mixedSlots $masters
|
||||||
|
if {$slaves} {
|
||||||
|
cluster_allocate_slaves $masters $slaves
|
||||||
|
}
|
||||||
|
assert_cluster_state ok
|
||||||
|
}
|
||||||
|
|
||||||
|
test "Create a 5 nodes cluster" {
|
||||||
|
create_cluster_with_mixedSlot 5 15
|
||||||
|
}
|
||||||
|
|
||||||
|
test "Cluster is up" {
|
||||||
|
assert_cluster_state ok
|
||||||
|
}
|
||||||
|
|
||||||
|
test "Cluster is writable" {
|
||||||
|
cluster_write_test 0
|
||||||
|
}
|
||||||
|
|
||||||
|
test "Instance #5 is a slave" {
|
||||||
|
assert {[RI 5 role] eq {slave}}
|
||||||
|
}
|
||||||
|
|
||||||
|
test "client do not break when cluster slot" {
|
||||||
|
R 0 config set client-output-buffer-limit "normal 33554432 16777216 60"
|
||||||
|
if { [catch {R 0 cluster slots}] } {
|
||||||
|
fail "output overflow when cluster slots"
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user