mirror of
https://github.com/fluencelabs/redis
synced 2025-03-19 09:00:51 +00:00
Nested MULTI/EXEC may replicate in different cases.
For example: 1. A module command called within a MULTI section. 2. A Lua script with replicate_commands() called within a MULTI section. 3. A module command called from a Lua script in the above context.
This commit is contained in:
parent
57bd8feb8d
commit
2c70d28295
@ -1164,6 +1164,8 @@ int RM_ReplyWithDouble(RedisModuleCtx *ctx, double d) {
|
|||||||
* in the context of a command execution. EXEC will be handled by the
|
* in the context of a command execution. EXEC will be handled by the
|
||||||
* RedisModuleCommandDispatcher() function. */
|
* RedisModuleCommandDispatcher() function. */
|
||||||
void moduleReplicateMultiIfNeeded(RedisModuleCtx *ctx) {
|
void moduleReplicateMultiIfNeeded(RedisModuleCtx *ctx) {
|
||||||
|
/* Skip this if client explicitly wrap the command with MULTI */
|
||||||
|
if (ctx->client->flags & CLIENT_MULTI) return;
|
||||||
/* If we already emitted MULTI return ASAP. */
|
/* If we already emitted MULTI return ASAP. */
|
||||||
if (ctx->flags & REDISMODULE_CTX_MULTI_EMITTED) return;
|
if (ctx->flags & REDISMODULE_CTX_MULTI_EMITTED) return;
|
||||||
/* If this is a thread safe context, we do not want to wrap commands
|
/* If this is a thread safe context, we do not want to wrap commands
|
||||||
|
@ -358,6 +358,13 @@ int luaRedisGenericCommand(lua_State *lua, int raise_error) {
|
|||||||
static size_t cached_objects_len[LUA_CMD_OBJCACHE_SIZE];
|
static size_t cached_objects_len[LUA_CMD_OBJCACHE_SIZE];
|
||||||
static int inuse = 0; /* Recursive calls detection. */
|
static int inuse = 0; /* Recursive calls detection. */
|
||||||
|
|
||||||
|
/* Reflect MULTI state */
|
||||||
|
if (server.lua_multi_emitted || (server.lua_caller->flags & CLIENT_MULTI)) {
|
||||||
|
c->flags |= CLIENT_MULTI;
|
||||||
|
} else {
|
||||||
|
c->flags &= ~CLIENT_MULTI;
|
||||||
|
}
|
||||||
|
|
||||||
/* By using Lua debug hooks it is possible to trigger a recursive call
|
/* By using Lua debug hooks it is possible to trigger a recursive call
|
||||||
* to luaRedisGenericCommand(), which normally should never happen.
|
* to luaRedisGenericCommand(), which normally should never happen.
|
||||||
* To make this function reentrant is futile and makes it slower, but
|
* To make this function reentrant is futile and makes it slower, but
|
||||||
@ -535,6 +542,7 @@ int luaRedisGenericCommand(lua_State *lua, int raise_error) {
|
|||||||
* a Lua script in the context of AOF and slaves. */
|
* a Lua script in the context of AOF and slaves. */
|
||||||
if (server.lua_replicate_commands &&
|
if (server.lua_replicate_commands &&
|
||||||
!server.lua_multi_emitted &&
|
!server.lua_multi_emitted &&
|
||||||
|
!(server.lua_caller->flags & CLIENT_MULTI) &&
|
||||||
server.lua_write_dirty &&
|
server.lua_write_dirty &&
|
||||||
server.lua_repl != PROPAGATE_NONE)
|
server.lua_repl != PROPAGATE_NONE)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user