From 0d77440b2698b693cc31a0ee59df88b63cc704e7 Mon Sep 17 00:00:00 2001 From: antirez Date: Thu, 28 Feb 2013 15:41:54 +0100 Subject: [PATCH] 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. --- src/cluster.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/cluster.c b/src/cluster.c index ff5cc3b9b..e6a0fb414 100644 --- a/src/cluster.c +++ b/src/cluster.c @@ -48,6 +48,7 @@ int clusterNodeAddSlave(clusterNode *master, clusterNode *slave); int clusterAddSlot(clusterNode *n, int slot); int clusterDelSlot(int slot); int clusterNodeSetSlotBit(clusterNode *n, int slot); +int bitmapTestBit(unsigned char *bitmap, int pos); /* ----------------------------------------------------------------------------- * Initialization @@ -854,14 +855,13 @@ int clusterProcessPacket(clusterLink *link) { /* Update our info about served slots. */ if (sender && sender->flags & REDIS_NODE_MASTER) { - int newslots, j; + int changes, j; - newslots = + changes = memcmp(sender->slots,hdr->myslots,sizeof(hdr->myslots)) != 0; - memcpy(sender->slots,hdr->myslots,sizeof(hdr->myslots)); - if (newslots) { + if (changes) { 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 * in FAIL state, update the table with the new node * caliming to serve the slot. */ @@ -877,16 +877,11 @@ int clusterProcessPacket(clusterLink *link) { /* If this slot was served by this node, but it is * no longer claiming it, del it from the table. */ if (server.cluster->slots[j] == sender) { - /* Set the bit again before calling - * clusterDelSlot() or the assert will fail. */ - clusterNodeSetSlotBit(sender,j); clusterDelSlot(j); update_state = update_config = 1; } } } - sender->numslots = - popcount(sender->slots,sizeof(sender->slots)); } }