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
9d5e2ed3
Commit
9d5e2ed3
authored
May 12, 2015
by
antirez
Browse files
Sentinel: same-Sentinel link sharing across masters
parent
e0a5246f
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/sentinel.c
View file @
9d5e2ed3
...
@@ -361,6 +361,7 @@ void sentinelFlushConfig(void);
...
@@ -361,6 +361,7 @@ void sentinelFlushConfig(void);
void
sentinelGenerateInitialMonitorEvents
(
void
);
void
sentinelGenerateInitialMonitorEvents
(
void
);
int
sentinelSendPing
(
sentinelRedisInstance
*
ri
);
int
sentinelSendPing
(
sentinelRedisInstance
*
ri
);
int
sentinelForceHelloUpdateForMaster
(
sentinelRedisInstance
*
master
);
int
sentinelForceHelloUpdateForMaster
(
sentinelRedisInstance
*
master
);
sentinelRedisInstance
*
getSentinelRedisInstanceByAddrAndRunID
(
dict
*
instances
,
char
*
ip
,
int
port
,
char
*
runid
);
/* ========================= Dictionary types =============================== */
/* ========================= Dictionary types =============================== */
...
@@ -977,15 +978,39 @@ instanceLink *releaseInstanceLink(instanceLink *link, sentinelRedisInstance *ri)
...
@@ -977,15 +978,39 @@ instanceLink *releaseInstanceLink(instanceLink *link, sentinelRedisInstance *ri)
* This way multiple Sentinel objects that refer all to the same physical
* This way multiple Sentinel objects that refer all to the same physical
* Sentinel instance but in the context of different masters will use
* Sentinel instance but in the context of different masters will use
* a single connection, will send a single PING per second for failure
* a single connection, will send a single PING per second for failure
* detection and so forth. */
* detection and so forth.
void
tryConnectionSharing
(
sentinelRedisInstance
*
ri
)
{
*
* Return REDIS_OK if a matching Sentinel was found in the context of a
* different master and sharing was performed. Otherwise REDIS_ERR
* is returned. */
int
sentinelTryConnectionSharing
(
sentinelRedisInstance
*
ri
)
{
redisAssert
(
ri
->
flags
&
SRI_SENTINEL
);
redisAssert
(
ri
->
flags
&
SRI_SENTINEL
);
dictIterator
*
di
;
dictEntry
*
de
;
if
(
ri
->
runid
==
NULL
)
return
REDIS_ERR
;
/* No way to identify it. */
if
(
ri
->
link
->
refcount
>
1
)
return
REDIS_ERR
;
/* Already shared. */
/* TODO:
di
=
dictGetIterator
(
sentinel
.
masters
);
* 1) Check if there is a match.
while
((
de
=
dictNext
(
di
))
!=
NULL
)
{
* 2) Free our current link.
sentinelRedisInstance
*
master
=
dictGetVal
(
de
),
*
match
;
* 3) Reference the other link and increment its reference count. */
/* We want to share with the same physical Senitnel referenced
REDIS_NOTUSED
(
ri
);
* in other masters, so skip our master. */
if
(
master
==
ri
->
master
)
continue
;
match
=
getSentinelRedisInstanceByAddrAndRunID
(
master
->
sentinels
,
NULL
,
0
,
ri
->
runid
);
if
(
match
==
ri
)
continue
;
/* Should never happen but... safer. */
/* We identified a matching Sentinel, great! Let's free our link
* and use the one of the matching Sentinel. */
releaseInstanceLink
(
ri
->
link
,
NULL
);
ri
->
link
=
match
->
link
;
match
->
link
->
refcount
++
;
printf
(
"SHARED!
\n
"
);
return
REDIS_OK
;
}
dictReleaseIterator
(
di
);
return
REDIS_ERR
;
}
}
/* This function is called when an hiredis connection reported an error.
/* This function is called when an hiredis connection reported an error.
...
@@ -1572,7 +1597,7 @@ char *sentinelHandleConfiguration(char **argv, int argc) {
...
@@ -1572,7 +1597,7 @@ char *sentinelHandleConfiguration(char **argv, int argc) {
}
}
if
(
argc
==
5
)
{
if
(
argc
==
5
)
{
si
->
runid
=
sdsnew
(
argv
[
4
]);
si
->
runid
=
sdsnew
(
argv
[
4
]);
t
ryConnectionSharing
(
si
);
sentinelT
ryConnectionSharing
(
si
);
}
}
}
else
if
(
!
strcasecmp
(
argv
[
0
],
"announce-ip"
)
&&
argc
==
2
)
{
}
else
if
(
!
strcasecmp
(
argv
[
0
],
"announce-ip"
)
&&
argc
==
2
)
{
/* announce-ip <ip-address> */
/* announce-ip <ip-address> */
...
@@ -2249,7 +2274,7 @@ void sentinelProcessHelloMessage(char *hello, int hello_len) {
...
@@ -2249,7 +2274,7 @@ void sentinelProcessHelloMessage(char *hello, int hello_len) {
* for Sentinels we don't have a later chance to fill it,
* for Sentinels we don't have a later chance to fill it,
* so do it now. */
* so do it now. */
si
->
runid
=
sdsnew
(
token
[
2
]);
si
->
runid
=
sdsnew
(
token
[
2
]);
t
ryConnectionSharing
(
si
);
sentinelT
ryConnectionSharing
(
si
);
sentinelFlushConfig
();
sentinelFlushConfig
();
}
}
}
}
...
...
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