Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
d512a09c
Commit
d512a09c
authored
Mar 15, 2013
by
antirez
Browse files
Cluster: a bit more serious node role change handling.
parent
004fbef8
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/cluster.c
View file @
d512a09c
...
...
@@ -48,6 +48,7 @@ clusterNode *clusterLookupNode(char *name);
int clusterNodeAddSlave(clusterNode *master, clusterNode *slave);
int clusterAddSlot(clusterNode *n, int slot);
int clusterDelSlot(int slot);
int clusterDelNodeSlots(clusterNode *node);
int clusterNodeSetSlotBit(clusterNode *n, int slot);
int bitmapTestBit(unsigned char *bitmap, int pos);
...
...
@@ -882,14 +883,31 @@ int clusterProcessPacket(clusterLink *link) {
if (!memcmp(hdr->slaveof,REDIS_NODE_NULL_NAME,
sizeof(hdr->slaveof)))
{
if
(
sender
->
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);
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. */
clusterDelNodeSlots(sender);
update_state = 1;
update_config = 1;
}
sender->flags &= ~REDIS_NODE_MASTER;
sender->flags |= REDIS_NODE_SLAVE;
if (sender->numslaves) clusterNodeResetSlaves(sender);
...
...
@@ -1629,6 +1647,18 @@ int clusterDelSlot(int slot) {
return REDIS_OK;
}
/* Delete all the slots associated with the specified node.
* The number of deleted slots is returned. */
int clusterDelNodeSlots(clusterNode *node) {
int deleted = 0, j;
for (j = 0; j < REDIS_CLUSTER_SLOTS; j++) {
if (clusterNodeGetSlotBit(node,j)) clusterDelSlot(j);
deleted++;
}
return deleted;
}
/* -----------------------------------------------------------------------------
* Cluster state evaluation function
* -------------------------------------------------------------------------- */
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment