Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
4ebfc455
Commit
4ebfc455
authored
Nov 04, 2010
by
antirez
Browse files
config option to select if when replication link with master a slave should or not serve stale data
parent
12ebe2ac
Changes
4
Hide whitespace changes
Inline
Side-by-side
redis.conf
View file @
4ebfc455
...
...
@@ -110,6 +110,19 @@ dir ./
#
# masterauth <master-password>
# When a slave lost the connection with the master, or when the replication
# is still in progress, the slave can act in two different ways:
#
# 1) if slave-serve-stale-data is set to 'yes' (the default) the slave will
# still reply to client requests, possibly with out of data data, or the
# data set may just be empty if this is the first synchronization.
#
# 2) if slave-serve-stale data is set to 'no' the slave will reply with
# an error "SYNC with master in progress" to all the kind of commands
# but to INFO and SLAVEOF.
#
slave
-
serve
-
stale
-
data
yes
################################## SECURITY ###################################
# Require clients to issue AUTH <PASSWORD> before processing any other
...
...
src/config.c
View file @
4ebfc455
...
...
@@ -152,6 +152,10 @@ void loadServerConfig(char *filename) {
server
.
replstate
=
REDIS_REPL_CONNECT
;
}
else
if
(
!
strcasecmp
(
argv
[
0
],
"masterauth"
)
&&
argc
==
2
)
{
server
.
masterauth
=
zstrdup
(
argv
[
1
]);
}
else
if
(
!
strcasecmp
(
argv
[
0
],
"slave-serve-stale-data"
)
&&
argc
==
2
)
{
if
((
server
.
repl_serve_stale_data
=
yesnotoi
(
argv
[
1
]))
==
-
1
)
{
err
=
"argument must be 'yes' or 'no'"
;
goto
loaderr
;
}
}
else
if
(
!
strcasecmp
(
argv
[
0
],
"glueoutputbuf"
)
&&
argc
==
2
)
{
if
((
server
.
glueoutputbuf
=
yesnotoi
(
argv
[
1
]))
==
-
1
)
{
err
=
"argument must be 'yes' or 'no'"
;
goto
loaderr
;
...
...
@@ -379,6 +383,11 @@ void configSetCommand(redisClient *c) {
appendServerSaveParams
(
seconds
,
changes
);
}
sdsfreesplitres
(
v
,
vlen
);
}
else
if
(
!
strcasecmp
(
c
->
argv
[
2
]
->
ptr
,
"slave-serve-stale-data"
))
{
int
yn
=
yesnotoi
(
o
->
ptr
);
if
(
yn
==
-
1
)
goto
badfmt
;
server
.
repl_serve_stale_data
=
yn
;
}
else
{
addReplyErrorFormat
(
c
,
"Unsupported CONFIG parameter: %s"
,
(
char
*
)
c
->
argv
[
2
]
->
ptr
);
...
...
@@ -488,6 +497,11 @@ void configGetCommand(redisClient *c) {
sdsfree
(
buf
);
matches
++
;
}
if
(
stringmatch
(
pattern
,
"slave-serve-stale-data"
,
0
))
{
addReplyBulkCString
(
c
,
"slave-serve-stale-data"
);
addReplyBulkCString
(
c
,
server
.
repl_serve_stale_data
?
"yes"
:
"no"
);
matches
++
;
}
setDeferredMultiBulkLength
(
c
,
replylen
,
matches
*
2
);
}
...
...
src/redis.c
View file @
4ebfc455
...
...
@@ -786,6 +786,7 @@ void initServerConfig() {
server
.
masterport
=
6379
;
server
.
master
=
NULL
;
server
.
replstate
=
REDIS_REPL_NONE
;
server
.
repl_serve_stale_data
=
1
;
/* Double constants initialization */
R_Zero
=
0
.
0
;
...
...
@@ -994,6 +995,17 @@ int processCommand(redisClient *c) {
return
REDIS_OK
;
}
/* Only allow INFO and SLAVEOF when slave-serve-stale-data is no and
* we are a slave with a broken link with master. */
if
(
server
.
masterhost
&&
server
.
replstate
!=
REDIS_REPL_CONNECTED
&&
server
.
repl_serve_stale_data
==
0
&&
cmd
->
proc
!=
infoCommand
&&
cmd
->
proc
!=
slaveofCommand
)
{
addReplyError
(
c
,
"link with MASTER is down and slave-serve-stale-data is set to no"
);
return
REDIS_OK
;
}
/* Exec the command */
if
(
c
->
flags
&
REDIS_MULTI
&&
cmd
->
proc
!=
execCommand
&&
cmd
->
proc
!=
discardCommand
&&
...
...
src/redis.h
View file @
4ebfc455
...
...
@@ -361,7 +361,8 @@ struct redisServer {
long
long
dirty_before_bgsave
;
/* used to restore dirty on failed BGSAVE */
list
*
clients
;
dict
*
commands
;
/* Command table hahs table */
struct
redisCommand
*
delCommand
,
*
multiCommand
;
/* often lookedup cmds */
/* Fast pointers to often looked up command */
struct
redisCommand
*
delCommand
,
*
multiCommand
;
list
*
slaves
,
*
monitors
;
char
neterr
[
ANET_ERR_LEN
];
aeEventLoop
*
el
;
...
...
@@ -413,6 +414,7 @@ struct redisServer {
int
repl_transfer_fd
;
/* slave -> master SYNC temp file descriptor */
char
*
repl_transfer_tmpfile
;
/* slave-> master SYNC temp file name */
time_t
repl_transfer_lastio
;
/* unix time of the latest read, for timeout */
int
repl_serve_stale_data
;
/* Serve stale data when link is down? */
/* Limits */
unsigned
int
maxclients
;
unsigned
long
long
maxmemory
;
...
...
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