Improve perf of reading cluster bitfield
Former-commit-id: 9371c005aa7ffc2060b1b787e4268bc25336ca15
This commit is contained in:
parent
c34fee9ed4
commit
baffeff5c7
@ -4180,16 +4180,32 @@ void clusterReplyMultiBulkSlots(client *c) {
|
|||||||
dictIterator *di = dictGetSafeIterator(g_pserver->cluster->nodes);
|
dictIterator *di = dictGetSafeIterator(g_pserver->cluster->nodes);
|
||||||
while((de = dictNext(di)) != NULL) {
|
while((de = dictNext(di)) != NULL) {
|
||||||
clusterNode *node = (clusterNode*)dictGetVal(de);
|
clusterNode *node = (clusterNode*)dictGetVal(de);
|
||||||
int j = 0, start = -1;
|
int start = -1;
|
||||||
|
|
||||||
/* 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 (j = 0; j < CLUSTER_SLOTS; j++) {
|
static_assert((CLUSTER_SLOTS % (sizeof(uint32_t)*8)) == 0, "code below assumes the bitfield is a multiple of sizeof(unsinged)");
|
||||||
int bit, i;
|
|
||||||
|
|
||||||
if ((bit = clusterNodeGetSlotBit(node,j)) != 0) {
|
for (unsigned iw = 0; iw < (CLUSTER_SLOTS/sizeof(uint32_t)/8); ++iw)
|
||||||
|
{
|
||||||
|
uint32_t wordCur = reinterpret_cast<uint32_t*>(node->slots)[iw];
|
||||||
|
if (iw != ((CLUSTER_SLOTS/sizeof(uint32_t)/8)-1))
|
||||||
|
{
|
||||||
|
if (start == -1 && wordCur == 0)
|
||||||
|
continue;
|
||||||
|
if (start != -1 && (wordCur+1)==0)
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned ibitStartLoop = iw*sizeof(uint32_t)*8;
|
||||||
|
|
||||||
|
for (unsigned j = ibitStartLoop; j < (iw+1)*sizeof(uint32_t)*8; j++) {
|
||||||
|
int i;
|
||||||
|
int bit = (int)(wordCur & 1);
|
||||||
|
wordCur >>= 1;
|
||||||
|
if (bit != 0) {
|
||||||
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)) {
|
||||||
@ -4231,6 +4247,9 @@ void clusterReplyMultiBulkSlots(client *c) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
serverAssert(start == -1);
|
||||||
|
}
|
||||||
|
|
||||||
dictReleaseIterator(di);
|
dictReleaseIterator(di);
|
||||||
setDeferredArrayLen(c, slot_replylen, num_masters);
|
setDeferredArrayLen(c, slot_replylen, num_masters);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user