Two minor fixes for cluster.c (#11441)

clusterNodeClearSlotBit()/clusterNodeSetSlotBit(), only set bit when slot does not exist and clear bit when slot does exist.
This commit is contained in:
DarrenJiang13 2022-11-26 03:58:19 +08:00 committed by GitHub
parent abc345ad28
commit ce4ebe6ba8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4297,7 +4297,7 @@ static int clusterNodeCronHandleReconnect(clusterNode *node, mstime_t handshake_
link->conn = connCreate(connTypeOfCluster());
connSetPrivateData(link->conn, link);
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
* clusterSendPing() had a chance to be called.
* If node->ping_sent is zero, failure detection can't work,
@ -4627,8 +4627,8 @@ int clusterMastersHaveSlaves(void) {
/* Set the slot bit and return the old value. */
int clusterNodeSetSlotBit(clusterNode *n, int slot) {
int old = bitmapTestBit(n->slots,slot);
bitmapSetBit(n->slots,slot);
if (!old) {
bitmapSetBit(n->slots,slot);
n->numslots++;
/* 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
@ -4652,8 +4652,10 @@ int clusterNodeSetSlotBit(clusterNode *n, int slot) {
/* Clear the slot bit and return the old value. */
int clusterNodeClearSlotBit(clusterNode *n, int slot) {
int old = bitmapTestBit(n->slots,slot);
bitmapClearBit(n->slots,slot);
if (old) n->numslots--;
if (old) {
bitmapClearBit(n->slots,slot);
n->numslots--;
}
return old;
}