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
5998769c
Commit
5998769c
authored
Nov 19, 2013
by
antirez
Browse files
Sentinel: CONFIG REWRITE support for Sentinel config.
parent
47df12d5
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/config.c
View file @
5998769c
...
@@ -1162,6 +1162,10 @@ int dictSdsKeyCompare(void *privdata, const void *key1, const void *key2);
...
@@ -1162,6 +1162,10 @@ int dictSdsKeyCompare(void *privdata, const void *key1, const void *key2);
void
dictSdsDestructor
(
void
*
privdata
,
void
*
val
);
void
dictSdsDestructor
(
void
*
privdata
,
void
*
val
);
void
dictListDestructor
(
void
*
privdata
,
void
*
val
);
void
dictListDestructor
(
void
*
privdata
,
void
*
val
);
/* Sentinel config rewriting is implemented inside sentinel.c by
* rewriteConfigSentinelOption(). */
void
rewriteConfigSentinelOption
(
struct
rewriteConfigState
*
state
);
dictType
optionToLineDictType
=
{
dictType
optionToLineDictType
=
{
dictSdsHash
,
/* hash function */
dictSdsHash
,
/* hash function */
NULL
,
/* key dup */
NULL
,
/* key dup */
...
@@ -1735,6 +1739,7 @@ int rewriteConfig(char *path) {
...
@@ -1735,6 +1739,7 @@ int rewriteConfig(char *path) {
rewriteConfigClientoutputbufferlimitOption
(
state
);
rewriteConfigClientoutputbufferlimitOption
(
state
);
rewriteConfigNumericalOption
(
state
,
"hz"
,
server
.
hz
,
REDIS_DEFAULT_HZ
);
rewriteConfigNumericalOption
(
state
,
"hz"
,
server
.
hz
,
REDIS_DEFAULT_HZ
);
rewriteConfigYesNoOption
(
state
,
"aof-rewrite-incremental-fsync"
,
server
.
aof_rewrite_incremental_fsync
,
REDIS_DEFAULT_AOF_REWRITE_INCREMENTAL_FSYNC
);
rewriteConfigYesNoOption
(
state
,
"aof-rewrite-incremental-fsync"
,
server
.
aof_rewrite_incremental_fsync
,
REDIS_DEFAULT_AOF_REWRITE_INCREMENTAL_FSYNC
);
if
(
server
.
sentinel_mode
)
rewriteConfigSentinelOption
(
state
);
/* Step 3: remove all the orphaned lines in the old file, that is, lines
/* Step 3: remove all the orphaned lines in the old file, that is, lines
* that were used by a config option and are no longer used, like in case
* that were used by a config option and are no longer used, like in case
...
...
src/redis.h
View file @
5998769c
...
@@ -1169,6 +1169,8 @@ sds keyspaceEventsFlagsToString(int flags);
...
@@ -1169,6 +1169,8 @@ sds keyspaceEventsFlagsToString(int flags);
void
loadServerConfig
(
char
*
filename
,
char
*
options
);
void
loadServerConfig
(
char
*
filename
,
char
*
options
);
void
appendServerSaveParams
(
time_t
seconds
,
int
changes
);
void
appendServerSaveParams
(
time_t
seconds
,
int
changes
);
void
resetServerSaveParams
();
void
resetServerSaveParams
();
struct
rewriteConfigState
;
/* Forward declaration to export API. */
void
rewriteConfigRewriteLine
(
struct
rewriteConfigState
*
state
,
char
*
option
,
sds
line
,
int
force
);
/* db.c -- Keyspace access API */
/* db.c -- Keyspace access API */
int
removeExpire
(
redisDb
*
db
,
robj
*
key
);
int
removeExpire
(
redisDb
*
db
,
robj
*
key
);
...
...
src/sentinel.c
View file @
5998769c
...
@@ -1303,10 +1303,10 @@ char *sentinelHandleConfiguration(char **argv, int argc) {
...
@@ -1303,10 +1303,10 @@ char *sentinelHandleConfiguration(char **argv, int argc) {
ri
->
config_epoch
=
strtoull
(
argv
[
2
],
NULL
,
10
);
ri
->
config_epoch
=
strtoull
(
argv
[
2
],
NULL
,
10
);
if
(
ri
->
config_epoch
>
sentinel
.
current_epoch
)
if
(
ri
->
config_epoch
>
sentinel
.
current_epoch
)
sentinel
.
current_epoch
=
ri
->
config_epoch
;
sentinel
.
current_epoch
=
ri
->
config_epoch
;
}
else
if
(
!
strcasecmp
(
argv
[
0
],
"slave"
)
&&
argc
==
3
)
{
}
else
if
(
!
strcasecmp
(
argv
[
0
],
"
known-
slave"
)
&&
argc
==
3
)
{
sentinelRedisInstance
*
slave
;
sentinelRedisInstance
*
slave
;
/* slave <name> <ip> <port> */
/*
known-
slave <name> <ip> <port> */
ri
=
sentinelGetMasterByName
(
argv
[
1
]);
ri
=
sentinelGetMasterByName
(
argv
[
1
]);
if
(
!
ri
)
return
"No such master with specified name."
;
if
(
!
ri
)
return
"No such master with specified name."
;
if
((
slave
=
createSentinelRedisInstance
(
NULL
,
SRI_SLAVE
,
argv
[
2
],
if
((
slave
=
createSentinelRedisInstance
(
NULL
,
SRI_SLAVE
,
argv
[
2
],
...
@@ -1314,10 +1314,10 @@ char *sentinelHandleConfiguration(char **argv, int argc) {
...
@@ -1314,10 +1314,10 @@ char *sentinelHandleConfiguration(char **argv, int argc) {
{
{
return
"Wrong hostname or port for slave."
;
return
"Wrong hostname or port for slave."
;
}
}
}
else
if
(
!
strcasecmp
(
argv
[
0
],
"sentinel"
)
&&
argc
==
3
)
{
}
else
if
(
!
strcasecmp
(
argv
[
0
],
"
known-
sentinel"
)
&&
argc
==
3
)
{
sentinelRedisInstance
*
si
;
sentinelRedisInstance
*
si
;
/* sentinel <name> <ip> <port> */
/*
known-
sentinel <name> <ip> <port> */
ri
=
sentinelGetMasterByName
(
argv
[
1
]);
ri
=
sentinelGetMasterByName
(
argv
[
1
]);
if
(
!
ri
)
return
"No such master with specified name."
;
if
(
!
ri
)
return
"No such master with specified name."
;
if
((
si
=
createSentinelRedisInstance
(
NULL
,
SRI_SENTINEL
,
argv
[
2
],
if
((
si
=
createSentinelRedisInstance
(
NULL
,
SRI_SENTINEL
,
argv
[
2
],
...
@@ -1331,6 +1331,107 @@ char *sentinelHandleConfiguration(char **argv, int argc) {
...
@@ -1331,6 +1331,107 @@ char *sentinelHandleConfiguration(char **argv, int argc) {
return
NULL
;
return
NULL
;
}
}
/* Implements CONFIG REWRITE for "sentinel" option.
* This is used not just to rewrite the configuration given by the user
* (the configured masters) but also in order to retain the state of
* Sentinel across restarts: config epoch of masters, associated slaves
* and sentinel instances, and so forth. */
void
rewriteConfigSentinelOption
(
struct
rewriteConfigState
*
state
)
{
dictIterator
*
di
,
*
di2
;
dictEntry
*
de
;
/* For every master emit a "sentinel monitor" config entry. */
di
=
dictGetIterator
(
sentinel
.
masters
);
while
((
de
=
dictNext
(
di
))
!=
NULL
)
{
sentinelRedisInstance
*
master
,
*
ri
;
sds
line
;
/* sentinel monitor */
master
=
dictGetVal
(
de
);
line
=
sdscatprintf
(
sdsempty
(),
"sentinel monitor %s %s %d %d"
,
master
->
name
,
master
->
addr
->
ip
,
master
->
addr
->
port
,
master
->
quorum
);
rewriteConfigRewriteLine
(
state
,
"sentinel"
,
line
,
1
);
/* sentinel down-after-milliseconds */
if
(
master
->
down_after_period
!=
SENTINEL_DEFAULT_DOWN_AFTER
)
{
line
=
sdscatprintf
(
sdsempty
(),
"sentinel down-after-milliseconds %s %ld"
,
master
->
name
,
(
long
)
master
->
down_after_period
);
rewriteConfigRewriteLine
(
state
,
"sentinel"
,
line
,
1
);
}
/* sentinel failover-timeout */
if
(
master
->
failover_timeout
!=
SENTINEL_DEFAULT_FAILOVER_TIMEOUT
)
{
line
=
sdscatprintf
(
sdsempty
(),
"sentinel failover-timeout %s %ld"
,
master
->
name
,
(
long
)
master
->
failover_timeout
);
rewriteConfigRewriteLine
(
state
,
"sentinel"
,
line
,
1
);
}
/* sentinel parallel-syncs */
if
(
master
->
parallel_syncs
!=
SENTINEL_DEFAULT_PARALLEL_SYNCS
)
{
line
=
sdscatprintf
(
sdsempty
(),
"sentinel parallel-syncs %s %d"
,
master
->
name
,
master
->
parallel_syncs
);
rewriteConfigRewriteLine
(
state
,
"sentinel"
,
line
,
1
);
}
/* sentinel notification-script */
if
(
master
->
notification_script
)
{
line
=
sdscatprintf
(
sdsempty
(),
"sentinel notification-script %s %s"
,
master
->
name
,
master
->
notification_script
);
rewriteConfigRewriteLine
(
state
,
"sentinel"
,
line
,
1
);
}
/* sentinel client-reconfig-script */
if
(
master
->
client_reconfig_script
)
{
line
=
sdscatprintf
(
sdsempty
(),
"sentinel client-reconfig-script %s %s"
,
master
->
name
,
master
->
client_reconfig_script
);
rewriteConfigRewriteLine
(
state
,
"sentinel"
,
line
,
1
);
}
/* sentinel auth-pass */
if
(
master
->
auth_pass
)
{
line
=
sdscatprintf
(
sdsempty
(),
"sentinel auth-pass %s %s"
,
master
->
name
,
master
->
auth_pass
);
rewriteConfigRewriteLine
(
state
,
"sentinel"
,
line
,
1
);
}
/* sentinel config-epoch */
line
=
sdscatprintf
(
sdsempty
(),
"sentinel config-epoch %s %llu"
,
master
->
name
,
(
unsigned
long
long
)
master
->
config_epoch
);
rewriteConfigRewriteLine
(
state
,
"sentinel"
,
line
,
1
);
/* sentinel known-slave */
di2
=
dictGetIterator
(
master
->
slaves
);
while
((
de
=
dictNext
(
di
))
!=
NULL
)
{
ri
=
dictGetVal
(
de
);
line
=
sdscatprintf
(
sdsempty
(),
"sentinel known-slave %s %s %d"
,
master
->
name
,
ri
->
addr
->
ip
,
ri
->
addr
->
port
);
rewriteConfigRewriteLine
(
state
,
"sentinel"
,
line
,
1
);
}
dictReleaseIterator
(
di2
);
/* sentinel known-sentinel */
di2
=
dictGetIterator
(
master
->
sentinels
);
while
((
de
=
dictNext
(
di
))
!=
NULL
)
{
ri
=
dictGetVal
(
de
);
line
=
sdscatprintf
(
sdsempty
(),
"sentinel known-sentinel %s %s %d"
,
master
->
name
,
ri
->
addr
->
ip
,
ri
->
addr
->
port
);
rewriteConfigRewriteLine
(
state
,
"sentinel"
,
line
,
1
);
}
dictReleaseIterator
(
di2
);
}
dictReleaseIterator
(
di
);
}
/* ====================== hiredis connection handling ======================= */
/* ====================== hiredis connection handling ======================= */
/* Completely disconnect an hiredis link from an instance. */
/* Completely disconnect an hiredis link from an instance. */
...
...
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