mirror of
https://github.com/fluencelabs/redis
synced 2025-03-20 09:30:55 +00:00
Cluster: REPLICATE subcommand and stub for clusterSetMaster().
This commit is contained in:
parent
bc84c399f8
commit
0c01088b51
@ -1498,6 +1498,24 @@ int verifyClusterConfigWithData(void) {
|
||||
return REDIS_OK;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* SLAVE nodes handling
|
||||
* -------------------------------------------------------------------------- */
|
||||
|
||||
/* Set the specified node 'n' as master. */
|
||||
void clusterSetMaster(clusterNode *n) {
|
||||
clusterNode *myself = server.cluster->myself;
|
||||
|
||||
redisAssert(n != myself);
|
||||
|
||||
if (myself->flags & REDIS_NODE_MASTER) {
|
||||
myself->flags &= ~REDIS_NODE_MASTER;
|
||||
myself->flags |= REDIS_NODE_SLAVE;
|
||||
}
|
||||
myself->slaveof = n;
|
||||
/* TODO: actually handle replication to point to the new slave. */
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* CLUSTER command
|
||||
* -------------------------------------------------------------------------- */
|
||||
@ -1849,6 +1867,40 @@ void clusterCommand(redisClient *c) {
|
||||
clusterUpdateState();
|
||||
clusterSaveConfigOrDie();
|
||||
addReply(c,shared.ok);
|
||||
} else if (!strcasecmp(c->argv[1]->ptr,"replicate") && c->argc == 3) {
|
||||
/* CLUSTER REPLICATE <NODE ID> */
|
||||
clusterNode *n = clusterLookupNode(c->argv[2]->ptr);
|
||||
|
||||
/* Lookup the specified node in our table. */
|
||||
if (!n) {
|
||||
addReplyErrorFormat(c,"Unknown node %s", (char*)c->argv[2]->ptr);
|
||||
return;
|
||||
}
|
||||
|
||||
/* I can't replicate myself. */
|
||||
if (n == server.cluster->myself) {
|
||||
addReplyError(c,"Can't replicate myself");
|
||||
return;
|
||||
}
|
||||
|
||||
/* Can't replicate a slave. */
|
||||
if (n->slaveof != NULL) {
|
||||
addReplyError(c,"I can only replicate a master, not a slave.");
|
||||
return;
|
||||
}
|
||||
|
||||
/* We should have no assigned slots to accept to replicate some
|
||||
* other node. */
|
||||
if (server.cluster->myself->numslots != 0 ||
|
||||
dictSize(server.db[0].dict) != 0)
|
||||
{
|
||||
addReplyError(c,"To set a master the node must be empty and without assigned slots.");
|
||||
return;
|
||||
}
|
||||
|
||||
/* Set the master. */
|
||||
clusterSetMaster(n);
|
||||
addReply(c,shared.ok);
|
||||
} else {
|
||||
addReplyError(c,"Wrong CLUSTER subcommand or number of arguments");
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user