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
dfe7f797
Commit
dfe7f797
authored
Oct 29, 2015
by
antirez
Browse files
Lua script selective replication fixes.
parent
a1d1ca14
Changes
3
Show whitespace changes
Inline
Side-by-side
src/scripting.c
View file @
dfe7f797
...
@@ -385,11 +385,11 @@ int luaRedisGenericCommand(lua_State *lua, int raise_error) {
...
@@ -385,11 +385,11 @@ int luaRedisGenericCommand(lua_State *lua, int raise_error) {
/* Run the command */
/* Run the command */
int
call_flags
=
CMD_CALL_SLOWLOG
|
CMD_CALL_STATS
;
int
call_flags
=
CMD_CALL_SLOWLOG
|
CMD_CALL_STATS
;
if
(
server
.
lua_replicate_commands
)
{
if
(
server
.
lua_replicate_commands
)
{
call_flags
|=
CMD_CALL_PROPAGATE
;
/* Set flags according to redis.set_repl() settings. */
/* Don't propagate AOf / replication stream if a redis.set_repl(
)
if
(
server
.
lua_repl
&
PROPAGATE_AOF
)
*
call
changed the default replication policy. */
call
_flags
|=
CMD_CALL_PROPAGATE_AOF
;
if
(
!
(
server
.
lua_repl
&
PROPAGATE_
AOF
))
preventCommandAOF
(
c
);
if
(
server
.
lua_repl
&
PROPAGATE_
REPL
)
if
(
!
(
server
.
lua_repl
&
PROPAGATE_REPL
))
preventCommandReplication
(
c
)
;
call_flags
|=
CMD_CALL_PROPAGATE_REPL
;
}
}
call
(
c
,
call_flags
);
call
(
c
,
call_flags
);
...
...
src/server.c
View file @
dfe7f797
...
@@ -2202,29 +2202,34 @@ void call(client *c, int flags) {
...
@@ -2202,29 +2202,34 @@ void call(client *c, int flags) {
}
}
/* Propagate the command into the AOF and replication link */
/* Propagate the command into the AOF and replication link */
if
(
flags
&
CMD_CALL_PROPAGATE
&&
(
c
->
flags
&
CLIENT_PREVENT_PROP
)
==
0
)
{
if
(
flags
&
CMD_CALL_PROPAGATE
&&
int
flags
=
PROPAGATE_NONE
;
(
c
->
flags
&
CLIENT_PREVENT_PROP
)
!=
CLIENT_PREVENT_PROP
)
{
int
propagate_flags
=
PROPAGATE_NONE
;
/* Check if the command operated changes in the data set. If so
/* Check if the command operated changes in the data set. If so
* set for replication / AOF propagation. */
* set for replication / AOF propagation. */
if
(
dirty
)
if
(
dirty
)
propagate_flags
|=
(
PROPAGATE_AOF
|
PROPAGATE_REPL
);
flags
|=
(
PROPAGATE_REPL
|
PROPAGATE_AOF
);
/* If the command forced AOF / replication of the command, set
/* If the command forced AOF / replication of the command, set
* the flags regardless of the command effects on the data set. */
* the flags regardless of the command effects on the data set. */
if
(
c
->
flags
&
CLIENT_FORCE_REPL
)
flags
|=
PROPAGATE_REPL
;
if
(
c
->
flags
&
CLIENT_FORCE_REPL
)
flags
|=
PROPAGATE_REPL
;
if
(
c
->
flags
&
CLIENT_FORCE_AOF
)
flags
|=
PROPAGATE_AOF
;
if
(
c
->
flags
&
CLIENT_FORCE_AOF
)
flags
|=
PROPAGATE_AOF
;
/* However calls to preventCommandPropagation() or its selective
/* However prevent AOF / replication propagation if the command
* variants preventCommandAOF() and preventCommandReplicaiton()
* implementatino called preventCommandPropagation() or similar,
* will clear the flags to avoid propagation. */
* or if we don't have the call() flags to do so. */
if
(
c
->
flags
&
CLIENT_PREVENT_REPL_PROP
)
flags
&=
~
PROPAGATE_REPL
;
if
(
c
->
flags
&
CLIENT_PREVENT_REPL_PROP
||
if
(
c
->
flags
&
CLIENT_PREVENT_AOF_PROP
)
flags
&=
~
PROPAGATE_AOF
;
!
(
flags
&
CMD_CALL_PROPAGATE_REPL
))
propagate_flags
&=
~
PROPAGATE_REPL
;
if
(
c
->
flags
&
CLIENT_PREVENT_AOF_PROP
||
!
(
flags
&
CMD_CALL_PROPAGATE_AOF
))
propagate_flags
&=
~
PROPAGATE_AOF
;
/* Call propagate() only if at least one of AOF / replication
/* Call propagate() only if at least one of AOF / replication
* propagation is needed. */
* propagation is needed. */
if
(
flags
!=
PROPAGATE_NONE
)
if
(
propagate_
flags
!=
PROPAGATE_NONE
)
propagate
(
c
->
cmd
,
c
->
db
->
id
,
c
->
argv
,
c
->
argc
,
flags
);
propagate
(
c
->
cmd
,
c
->
db
->
id
,
c
->
argv
,
c
->
argc
,
propagate_
flags
);
}
}
/* Restore the old replication flags, since call() can be executed
/* Restore the old replication flags, since call() can be executed
...
@@ -2243,7 +2248,12 @@ void call(client *c, int flags) {
...
@@ -2243,7 +2248,12 @@ void call(client *c, int flags) {
if
(
flags
&
CMD_CALL_PROPAGATE
)
{
if
(
flags
&
CMD_CALL_PROPAGATE
)
{
for
(
j
=
0
;
j
<
server
.
also_propagate
.
numops
;
j
++
)
{
for
(
j
=
0
;
j
<
server
.
also_propagate
.
numops
;
j
++
)
{
rop
=
&
server
.
also_propagate
.
ops
[
j
];
rop
=
&
server
.
also_propagate
.
ops
[
j
];
propagate
(
rop
->
cmd
,
rop
->
dbid
,
rop
->
argv
,
rop
->
argc
,
rop
->
target
);
int
target
=
rop
->
target
;
/* Whatever the command wish is, we honor the call() flags. */
if
(
!
(
flags
&
CMD_CALL_PROPAGATE_AOF
))
target
&=
~
PROPAGATE_AOF
;
if
(
!
(
flags
&
CMD_CALL_PROPAGATE_REPL
))
target
&=
~
PROPAGATE_REPL
;
if
(
target
)
propagate
(
rop
->
cmd
,
rop
->
dbid
,
rop
->
argv
,
rop
->
argc
,
target
);
}
}
}
}
redisOpArrayFree
(
&
server
.
also_propagate
);
redisOpArrayFree
(
&
server
.
also_propagate
);
...
...
src/server.h
View file @
dfe7f797
...
@@ -399,9 +399,11 @@ typedef long long mstime_t; /* millisecond time type. */
...
@@ -399,9 +399,11 @@ typedef long long mstime_t; /* millisecond time type. */
/* Command call flags, see call() function */
/* Command call flags, see call() function */
#define CMD_CALL_NONE 0
#define CMD_CALL_NONE 0
#define CMD_CALL_SLOWLOG 1
#define CMD_CALL_SLOWLOG (1<<0)
#define CMD_CALL_STATS 2
#define CMD_CALL_STATS (1<<1)
#define CMD_CALL_PROPAGATE 4
#define CMD_CALL_PROPAGATE_AOF (1<<2)
#define CMD_CALL_PROPAGATE_REPL (1<<3)
#define CMD_CALL_PROPAGATE (CMD_CALL_PROPAGATE_AOF|CMD_CALL_PROPAGATE_REPL)
#define CMD_CALL_FULL (CMD_CALL_SLOWLOG | CMD_CALL_STATS | CMD_CALL_PROPAGATE)
#define CMD_CALL_FULL (CMD_CALL_SLOWLOG | CMD_CALL_STATS | CMD_CALL_PROPAGATE)
/* Command propagation flags, see propagate() function */
/* Command propagation flags, see propagate() function */
...
...
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