Unverified Commit ce4ebe6b authored by DarrenJiang13's avatar DarrenJiang13 Committed by GitHub
Browse files

Two minor fixes for cluster.c (#11441)

clusterNodeClearSlotBit()/clusterNodeSetSlotBit(), only set bit when slot does not exist and clear bit when slot does exist.
parent abc345ad
...@@ -4297,7 +4297,7 @@ static int clusterNodeCronHandleReconnect(clusterNode *node, mstime_t handshake_ ...@@ -4297,7 +4297,7 @@ static int clusterNodeCronHandleReconnect(clusterNode *node, mstime_t handshake_
link->conn = connCreate(connTypeOfCluster()); link->conn = connCreate(connTypeOfCluster());
connSetPrivateData(link->conn, link); connSetPrivateData(link->conn, link);
if (connConnect(link->conn, node->ip, node->cport, server.bind_source_addr, if (connConnect(link->conn, node->ip, node->cport, server.bind_source_addr,
clusterLinkConnectHandler) == -1) { clusterLinkConnectHandler) == C_ERR) {
/* We got a synchronous error from connect before /* We got a synchronous error from connect before
* clusterSendPing() had a chance to be called. * clusterSendPing() had a chance to be called.
* If node->ping_sent is zero, failure detection can't work, * If node->ping_sent is zero, failure detection can't work,
...@@ -4627,8 +4627,8 @@ int clusterMastersHaveSlaves(void) { ...@@ -4627,8 +4627,8 @@ int clusterMastersHaveSlaves(void) {
/* Set the slot bit and return the old value. */ /* Set the slot bit and return the old value. */
int clusterNodeSetSlotBit(clusterNode *n, int slot) { int clusterNodeSetSlotBit(clusterNode *n, int slot) {
int old = bitmapTestBit(n->slots,slot); int old = bitmapTestBit(n->slots,slot);
bitmapSetBit(n->slots,slot);
if (!old) { if (!old) {
bitmapSetBit(n->slots,slot);
n->numslots++; n->numslots++;
/* When a master gets its first slot, even if it has no slaves, /* When a master gets its first slot, even if it has no slaves,
* it gets flagged with MIGRATE_TO, that is, the master is a valid * it gets flagged with MIGRATE_TO, that is, the master is a valid
...@@ -4652,8 +4652,10 @@ int clusterNodeSetSlotBit(clusterNode *n, int slot) { ...@@ -4652,8 +4652,10 @@ int clusterNodeSetSlotBit(clusterNode *n, int slot) {
/* Clear the slot bit and return the old value. */ /* Clear the slot bit and return the old value. */
int clusterNodeClearSlotBit(clusterNode *n, int slot) { int clusterNodeClearSlotBit(clusterNode *n, int slot) {
int old = bitmapTestBit(n->slots,slot); int old = bitmapTestBit(n->slots,slot);
bitmapClearBit(n->slots,slot); if (old) {
if (old) n->numslots--; bitmapClearBit(n->slots,slot);
n->numslots--;
}
return old; return old;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment