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
0c01088b
Commit
0c01088b
authored
Mar 04, 2013
by
antirez
Browse files
Cluster: REPLICATE subcommand and stub for clusterSetMaster().
parent
bc84c399
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/cluster.c
View file @
0c01088b
...
...
@@ -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"
);
}
...
...
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