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
cc605368
Commit
cc605368
authored
Nov 21, 2013
by
antirez
Browse files
Sentinel: different comments updated to new implementation.
parent
685e7999
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/sentinel.c
View file @
cc605368
...
@@ -993,8 +993,8 @@ const char *sentinelRedisInstanceTypeStr(sentinelRedisInstance *ri) {
...
@@ -993,8 +993,8 @@ const char *sentinelRedisInstanceTypeStr(sentinelRedisInstance *ri) {
else
return
"unknown"
;
else
return
"unknown"
;
}
}
/* This function removes all the instances found in the dictionary of
instances
/* This function removes all the instances found in the dictionary of
*
'd
', having either:
*
sentinels in the specified 'master
', having either:
*
*
* 1) The same ip/port as specified.
* 1) The same ip/port as specified.
* 2) The same runid.
* 2) The same runid.
...
@@ -1005,13 +1005,9 @@ const char *sentinelRedisInstanceTypeStr(sentinelRedisInstance *ri) {
...
@@ -1005,13 +1005,9 @@ const char *sentinelRedisInstanceTypeStr(sentinelRedisInstance *ri) {
*
*
* This function is useful because every time we add a new Sentinel into
* This function is useful because every time we add a new Sentinel into
* a master's Sentinels dictionary, we want to be very sure about not
* a master's Sentinels dictionary, we want to be very sure about not
* having duplicated instances for any reason. This is so important because
* having duplicated instances for any reason. This is important because
* we use those other sentinels in order to run our quorum protocol to
* other sentinels are needed to reach ODOWN quorum, and later to get
* understand if it's time to proceed with the fail over.
* voted for a given configuration epoch in order to perform the failover.
*
* Making sure no duplication is possible we greatly improve the robustness
* of the quorum (otherwise we may end counting the same instance multiple
* times for some reason).
*
*
* The function returns the number of Sentinels removed. */
* The function returns the number of Sentinels removed. */
int
removeMatchingSentinelsFromMaster
(
sentinelRedisInstance
*
master
,
char
*
ip
,
int
port
,
char
*
runid
)
{
int
removeMatchingSentinelsFromMaster
(
sentinelRedisInstance
*
master
,
char
*
ip
,
int
port
,
char
*
runid
)
{
...
@@ -1623,7 +1619,7 @@ void sentinelReconnectInstance(sentinelRedisInstance *ri) {
...
@@ -1623,7 +1619,7 @@ void sentinelReconnectInstance(sentinelRedisInstance *ri) {
* 1) It is actually a master in the current configuration.
* 1) It is actually a master in the current configuration.
* 2) It reports itself as a master.
* 2) It reports itself as a master.
* 3) It is not SDOWN or ODOWN.
* 3) It is not SDOWN or ODOWN.
* 4) We obtained last INFO no more than two times the INFO period
of
time ago. */
* 4) We obtained last INFO no more than two times the INFO period time ago. */
int
sentinelMasterLooksSane
(
sentinelRedisInstance
*
master
)
{
int
sentinelMasterLooksSane
(
sentinelRedisInstance
*
master
)
{
return
return
master
->
flags
&
SRI_MASTER
&&
master
->
flags
&
SRI_MASTER
&&
...
@@ -2560,8 +2556,8 @@ void sentinelCheckSubjectivelyDown(sentinelRedisInstance *ri) {
...
@@ -2560,8 +2556,8 @@ void sentinelCheckSubjectivelyDown(sentinelRedisInstance *ri) {
sentinelKillLink
(
ri
,
ri
->
pc
);
sentinelKillLink
(
ri
,
ri
->
pc
);
}
}
/* Update the
subjectively down
flag. We believe the instance is
in
SDOWN
/* Update the
SDOWN
flag. We believe the instance is SDOWN
if:
*
state if:
*
* 1) It is not replying.
* 1) It is not replying.
* 2) We believe it is a master, it reports to be a slave for enough time
* 2) We believe it is a master, it reports to be a slave for enough time
* to meet the down_after_period, plus enough time to get two times
* to meet the down_after_period, plus enough time to get two times
...
@@ -2587,7 +2583,12 @@ void sentinelCheckSubjectivelyDown(sentinelRedisInstance *ri) {
...
@@ -2587,7 +2583,12 @@ void sentinelCheckSubjectivelyDown(sentinelRedisInstance *ri) {
}
}
}
}
/* Is this instance down accordingly to the configured quorum? */
/* Is this instance down according to the configured quorum?
*
* Note that ODOWN is a weak quorum, it only means that enough Sentinels
* reported in a given time range that the instance was not reachable.
* However messages can be delayed so there are no strong guarantees about
* N instances agreeing at the same time about the down state. */
void
sentinelCheckObjectivelyDown
(
sentinelRedisInstance
*
master
)
{
void
sentinelCheckObjectivelyDown
(
sentinelRedisInstance
*
master
)
{
dictIterator
*
di
;
dictIterator
*
di
;
dictEntry
*
de
;
dictEntry
*
de
;
...
@@ -2657,10 +2658,10 @@ void sentinelReceiveIsMasterDownReply(redisAsyncContext *c, void *reply, void *p
...
@@ -2657,10 +2658,10 @@ void sentinelReceiveIsMasterDownReply(redisAsyncContext *c, void *reply, void *p
}
}
}
}
/* If we think
(subjectively)
the master is down, we start sending
/* If we think the master is down, we start sending
* SENTINEL IS-MASTER-DOWN-BY-ADDR requests to other sentinels
* SENTINEL IS-MASTER-DOWN-BY-ADDR requests to other sentinels
* in order to get the replies that allow to reach the quorum
and
* in order to get the replies that allow to reach the quorum
*
possibly als
o mark the master
as objectively down
. */
*
needed t
o mark the master
in ODOWN state and trigger a failover
. */
#define SENTINEL_ASK_FORCED (1<<0)
#define SENTINEL_ASK_FORCED (1<<0)
void
sentinelAskMasterStateToOtherSentinels
(
sentinelRedisInstance
*
master
,
int
flags
)
{
void
sentinelAskMasterStateToOtherSentinels
(
sentinelRedisInstance
*
master
,
int
flags
)
{
dictIterator
*
di
;
dictIterator
*
di
;
...
@@ -3222,11 +3223,7 @@ void sentinelFailoverReconfNextSlave(sentinelRedisInstance *master) {
...
@@ -3222,11 +3223,7 @@ void sentinelFailoverReconfNextSlave(sentinelRedisInstance *master) {
/* This function is called when the slave is in
/* This function is called when the slave is in
* SENTINEL_FAILOVER_STATE_UPDATE_CONFIG state. In this state we need
* SENTINEL_FAILOVER_STATE_UPDATE_CONFIG state. In this state we need
* to remove it from the master table and add the promoted slave instead.
* to remove it from the master table and add the promoted slave instead. */
*
* If there are no promoted slaves as this instance is unique, we remove
* and re-add it with the same address to trigger a complete state
* refresh. */
void
sentinelFailoverSwitchToPromotedSlave
(
sentinelRedisInstance
*
master
)
{
void
sentinelFailoverSwitchToPromotedSlave
(
sentinelRedisInstance
*
master
)
{
sentinelRedisInstance
*
ref
=
master
->
promoted_slave
?
sentinelRedisInstance
*
ref
=
master
->
promoted_slave
?
master
->
promoted_slave
:
master
;
master
->
promoted_slave
:
master
;
...
...
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