mirror of
https://codeberg.org/redict/redict.git
synced 2025-01-22 16:18:28 -05:00
Cluster: node replication role change handle improved.
The code handling a master that turns into a slave or the contrary was improved in order to avoid repeating the same operations. Also the readability and conceptual simplicity was improved.
This commit is contained in:
parent
88221f88c0
commit
4d62623015
@ -884,34 +884,33 @@ int clusterProcessPacket(clusterLink *link) {
|
||||
sizeof(hdr->slaveof)))
|
||||
{
|
||||
/* Node is a master. */
|
||||
if (sender->flags & REDIS_NODE_SLAVE &&
|
||||
sender->slaveof != NULL)
|
||||
{
|
||||
/* If the node changed role and is now a master, remove
|
||||
* it from the list of slaves of its old master. */
|
||||
if (sender->flags & REDIS_NODE_SLAVE) {
|
||||
/* Slave turned into master? Reconfigure it. */
|
||||
if (sender->slaveof)
|
||||
clusterNodeRemoveSlave(sender->slaveof,sender);
|
||||
update_state = 1;
|
||||
update_config = 1;
|
||||
}
|
||||
sender->flags &= ~REDIS_NODE_SLAVE;
|
||||
sender->flags |= REDIS_NODE_MASTER;
|
||||
sender->slaveof = NULL;
|
||||
update_state = 1;
|
||||
update_config = 1;
|
||||
}
|
||||
} else {
|
||||
/* Node is a slave. */
|
||||
clusterNode *master = clusterLookupNode(hdr->slaveof);
|
||||
|
||||
if (sender->flags & REDIS_NODE_MASTER) {
|
||||
/* If the node changed role and is now a slave, clear all
|
||||
* its slots as them are no longer served. */
|
||||
/* Master just turned into a slave? Reconfigure the node. */
|
||||
clusterDelNodeSlots(sender);
|
||||
sender->flags &= ~REDIS_NODE_MASTER;
|
||||
sender->flags |= REDIS_NODE_SLAVE;
|
||||
/* Remove the list of slaves from the node. */
|
||||
if (sender->numslaves) clusterNodeResetSlaves(sender);
|
||||
update_state = 1;
|
||||
update_config = 1;
|
||||
}
|
||||
|
||||
sender->flags &= ~REDIS_NODE_MASTER;
|
||||
sender->flags |= REDIS_NODE_SLAVE;
|
||||
if (sender->numslaves) clusterNodeResetSlaves(sender);
|
||||
if (master) {
|
||||
/* Master node changed for this slave? */
|
||||
if (sender->slaveof != master) {
|
||||
clusterNodeAddSlave(master,sender);
|
||||
sender->slaveof = master;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user