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
7dbc0a63
Commit
7dbc0a63
authored
Nov 14, 2013
by
antirez
Browse files
Sentinel: remember last time slave changed master.
parent
612dbb2a
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/sentinel.c
View file @
7dbc0a63
...
@@ -164,6 +164,7 @@ typedef struct sentinelRedisInstance {
...
@@ -164,6 +164,7 @@ typedef struct sentinelRedisInstance {
* we do silly things. */
* we do silly things. */
int role_reported;
int role_reported;
mstime_t role_reported_time;
mstime_t role_reported_time;
mstime_t slave_conf_change_time; /* Last time slave master addr changed. */
/* Master specific. */
/* Master specific. */
dict *sentinels; /* Other sentinels monitoring the same master. */
dict *sentinels; /* Other sentinels monitoring the same master. */
...
@@ -924,6 +925,7 @@ sentinelRedisInstance *createSentinelRedisInstance(char *name, int flags, char *
...
@@ -924,6 +925,7 @@ sentinelRedisInstance *createSentinelRedisInstance(char *name, int flags, char *
/* Role */
/* Role */
ri->role_reported = ri->flags & (SRI_MASTER|SRI_SLAVE);
ri->role_reported = ri->flags & (SRI_MASTER|SRI_SLAVE);
ri->role_reported_time = mstime();
ri->role_reported_time = mstime();
ri->slave_conf_change_time = mstime();
/* Add into the right table. */
/* Add into the right table. */
dictAdd(table, ri->name, ri);
dictAdd(table, ri->name, ri);
...
@@ -1517,13 +1519,24 @@ void sentinelRefreshInstanceInfo(sentinelRedisInstance *ri, const char *info) {
...
@@ -1517,13 +1519,24 @@ void sentinelRefreshInstanceInfo(sentinelRedisInstance *ri, const char *info) {
if (role == SRI_SLAVE) {
if (role == SRI_SLAVE) {
/* master_host:<host> */
/* master_host:<host> */
if (sdslen(l) >= 12 && !memcmp(l,"master_host:",12)) {
if (sdslen(l) >= 12 && !memcmp(l,"master_host:",12)) {
sdsfree
(
ri
->
slave_master_host
);
if (ri->slave_master_host == NULL ||
ri
->
slave_master_host
=
sdsnew
(
l
+
12
);
strcasecmp(l+12,ri->slave_master_host))
{
sdsfree(ri->slave_master_host);
ri->slave_master_host = sdsnew(l+12);
ri->slave_conf_change_time = mstime();
}
}
}
/* master_port:<port> */
/* master_port:<port> */
if
(
sdslen
(
l
)
>=
12
&&
!
memcmp
(
l
,
"master_port:"
,
12
))
if (sdslen(l) >= 12 && !memcmp(l,"master_port:",12)) {
ri
->
slave_master_port
=
atoi
(
l
+
12
);
int slave_master_port = atoi(l+12);
if (ri->slave_master_port != slave_master_port) {
ri->slave_master_port = slave_master_port;
ri->slave_conf_change_time = mstime();
}
}
/* master_link_status:<status> */
/* master_link_status:<status> */
if (sdslen(l) >= 19 && !memcmp(l,"master_link_status:",19)) {
if (sdslen(l) >= 19 && !memcmp(l,"master_link_status:",19)) {
...
@@ -1550,6 +1563,7 @@ void sentinelRefreshInstanceInfo(sentinelRedisInstance *ri, const char *info) {
...
@@ -1550,6 +1563,7 @@ void sentinelRefreshInstanceInfo(sentinelRedisInstance *ri, const char *info) {
if (ri->role_reported != SRI_SLAVE) {
if (ri->role_reported != SRI_SLAVE) {
ri->role_reported_time = mstime();
ri->role_reported_time = mstime();
ri->role_reported = SRI_SLAVE;
ri->role_reported = SRI_SLAVE;
ri->slave_conf_change_time = mstime();
}
}
}
}
...
...
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