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
575cbc99
Commit
575cbc99
authored
Mar 13, 2013
by
antirez
Browse files
Cluster: clusterHandleSlaveFailover() stub.
parent
1902a9c5
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/cluster.c
View file @
575cbc99
...
...
@@ -227,6 +227,8 @@ void clusterInit(void) {
server
.
cluster
->
size
=
1
;
server
.
cluster
->
nodes
=
dictCreate
(
&
clusterNodesDictType
,
NULL
);
server
.
cluster
->
node_timeout
=
15
;
server
.
cluster
->
failover_auth_time
=
0
;
server
.
cluster
->
failover_auth_count
=
0
;
memset
(
server
.
cluster
->
migrating_slots_to
,
0
,
sizeof
(
server
.
cluster
->
migrating_slots_to
));
memset
(
server
.
cluster
->
importing_slots_from
,
0
,
...
...
@@ -1256,6 +1258,33 @@ void clusterPropagatePublish(robj *channel, robj *message) {
* 4) Perform the failover informing all the other nodes.
*/
void
clusterHandleSlaveFailover
(
void
)
{
time_t
data_age
=
server
.
unixtime
-
server
.
repl_down_since
;
time_t
auth_age
=
server
.
unixtime
-
server
.
cluster
->
failover_auth_time
;
int
needed_quorum
=
(
server
.
cluster
->
size
/
2
)
+
1
;
/* Check if our data is recent enough. For now we just use a fixed
* constant of ten times the node timeout since the cluster should
* react much faster to a master down. */
if
(
data_age
>
server
.
cluster
->
node_timeout
*
10
)
return
;
/* TODO: check if we are the first slave as well? Or just rely on the
* master authorization? */
/* Ask masters if we are authorized to perform the failover. If there
* is a pending auth request that's too old, reset it. */
if
(
server
.
cluster
->
failover_auth_time
==
0
||
auth_age
>
15
)
{
server
.
cluster
->
failover_auth_time
=
time
(
NULL
);
server
.
cluster
->
failover_auth_count
=
0
;
/* TODO: Broadcast the AUTH request. */
return
;
/* Wait for replies. */
}
/* Check if we reached the quorum. */
if
(
server
.
cluster
->
failover_auth_count
>
needed_quorum
)
{
/* TODO: Perform election. */
/* TODO: Broadcast update to cluster. */
}
}
/* -----------------------------------------------------------------------------
...
...
src/redis.h
View file @
575cbc99
...
...
@@ -579,6 +579,8 @@ typedef struct {
clusterNode
*
importing_slots_from
[
REDIS_CLUSTER_SLOTS
];
clusterNode
*
slots
[
REDIS_CLUSTER_SLOTS
];
zskiplist
*
slots_to_keys
;
int
failover_auth_time
;
/* Time at which we sent the AUTH request. */
int
failover_auth_count
;
/* Number of authorizations received. */
}
clusterState
;
/* Redis cluster messages header */
...
...
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