提交 4d626230 编写于 作者: A antirez

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.
上级 88221f88
......@@ -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. */
clusterNodeRemoveSlave(sender->slaveof,sender);
if (sender->flags & REDIS_NODE_SLAVE) {
/* Slave turned into master? Reconfigure it. */
if (sender->slaveof)
clusterNodeRemoveSlave(sender->slaveof,sender);
sender->flags &= ~REDIS_NODE_SLAVE;
sender->flags |= REDIS_NODE_MASTER;
sender->slaveof = NULL;
update_state = 1;
update_config = 1;
}
sender->flags &= ~REDIS_NODE_SLAVE;
sender->flags |= REDIS_NODE_MASTER;
sender->slaveof = NULL;
} 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;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册