Skip to content

Commit ce4ebe6

Browse files
Two minor fixes for cluster.c (redis#11441)
clusterNodeClearSlotBit()/clusterNodeSetSlotBit(), only set bit when slot does not exist and clear bit when slot does exist.
1 parent abc345a commit ce4ebe6

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

src/cluster.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4297,7 +4297,7 @@ static int clusterNodeCronHandleReconnect(clusterNode *node, mstime_t handshake_
42974297
link->conn = connCreate(connTypeOfCluster());
42984298
connSetPrivateData(link->conn, link);
42994299
if (connConnect(link->conn, node->ip, node->cport, server.bind_source_addr,
4300-
clusterLinkConnectHandler) == -1) {
4300+
clusterLinkConnectHandler) == C_ERR) {
43014301
/* We got a synchronous error from connect before
43024302
* clusterSendPing() had a chance to be called.
43034303
* If node->ping_sent is zero, failure detection can't work,
@@ -4627,8 +4627,8 @@ int clusterMastersHaveSlaves(void) {
46274627
/* Set the slot bit and return the old value. */
46284628
int clusterNodeSetSlotBit(clusterNode *n, int slot) {
46294629
int old = bitmapTestBit(n->slots,slot);
4630-
bitmapSetBit(n->slots,slot);
46314630
if (!old) {
4631+
bitmapSetBit(n->slots,slot);
46324632
n->numslots++;
46334633
/* When a master gets its first slot, even if it has no slaves,
46344634
* it gets flagged with MIGRATE_TO, that is, the master is a valid
@@ -4652,8 +4652,10 @@ int clusterNodeSetSlotBit(clusterNode *n, int slot) {
46524652
/* Clear the slot bit and return the old value. */
46534653
int clusterNodeClearSlotBit(clusterNode *n, int slot) {
46544654
int old = bitmapTestBit(n->slots,slot);
4655-
bitmapClearBit(n->slots,slot);
4656-
if (old) n->numslots--;
4655+
if (old) {
4656+
bitmapClearBit(n->slots,slot);
4657+
n->numslots--;
4658+
}
46574659
return old;
46584660
}
46594661

0 commit comments

Comments
 (0)