mirror of
https://codeberg.org/redict/redict.git
synced 2025-01-23 00:28:26 -05:00
Cluster: better handling of slots changes in PONG packets.
The new code makes sure that the node slots bitmap is always consistent with the cluster->slots array.
This commit is contained in:
parent
5f8fd27ace
commit
0d77440b26
@ -48,6 +48,7 @@ int clusterNodeAddSlave(clusterNode *master, clusterNode *slave);
|
|||||||
int clusterAddSlot(clusterNode *n, int slot);
|
int clusterAddSlot(clusterNode *n, int slot);
|
||||||
int clusterDelSlot(int slot);
|
int clusterDelSlot(int slot);
|
||||||
int clusterNodeSetSlotBit(clusterNode *n, int slot);
|
int clusterNodeSetSlotBit(clusterNode *n, int slot);
|
||||||
|
int bitmapTestBit(unsigned char *bitmap, int pos);
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
* Initialization
|
* Initialization
|
||||||
@ -854,14 +855,13 @@ int clusterProcessPacket(clusterLink *link) {
|
|||||||
|
|
||||||
/* Update our info about served slots. */
|
/* Update our info about served slots. */
|
||||||
if (sender && sender->flags & REDIS_NODE_MASTER) {
|
if (sender && sender->flags & REDIS_NODE_MASTER) {
|
||||||
int newslots, j;
|
int changes, j;
|
||||||
|
|
||||||
newslots =
|
changes =
|
||||||
memcmp(sender->slots,hdr->myslots,sizeof(hdr->myslots)) != 0;
|
memcmp(sender->slots,hdr->myslots,sizeof(hdr->myslots)) != 0;
|
||||||
memcpy(sender->slots,hdr->myslots,sizeof(hdr->myslots));
|
if (changes) {
|
||||||
if (newslots) {
|
|
||||||
for (j = 0; j < REDIS_CLUSTER_SLOTS; j++) {
|
for (j = 0; j < REDIS_CLUSTER_SLOTS; j++) {
|
||||||
if (clusterNodeGetSlotBit(sender,j)) {
|
if (bitmapTestBit(hdr->myslots,j)) {
|
||||||
/* If this slot was not served, or served by a node
|
/* If this slot was not served, or served by a node
|
||||||
* in FAIL state, update the table with the new node
|
* in FAIL state, update the table with the new node
|
||||||
* caliming to serve the slot. */
|
* caliming to serve the slot. */
|
||||||
@ -877,16 +877,11 @@ int clusterProcessPacket(clusterLink *link) {
|
|||||||
/* If this slot was served by this node, but it is
|
/* If this slot was served by this node, but it is
|
||||||
* no longer claiming it, del it from the table. */
|
* no longer claiming it, del it from the table. */
|
||||||
if (server.cluster->slots[j] == sender) {
|
if (server.cluster->slots[j] == sender) {
|
||||||
/* Set the bit again before calling
|
|
||||||
* clusterDelSlot() or the assert will fail. */
|
|
||||||
clusterNodeSetSlotBit(sender,j);
|
|
||||||
clusterDelSlot(j);
|
clusterDelSlot(j);
|
||||||
update_state = update_config = 1;
|
update_state = update_config = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sender->numslots =
|
|
||||||
popcount(sender->slots,sizeof(sender->slots));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user