From 337fc3d6fd8bc672f3e038f8046d2edda5b9eb18 Mon Sep 17 00:00:00 2001 From: antirez Date: Mon, 3 Feb 2025 11:28:48 +0100 Subject: [PATCH] Don't use threaded VADD in replicas, lua, multi. --- vset.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/vset.c b/vset.c index 12ad472842..308d187563 100644 --- a/vset.c +++ b/vset.c @@ -297,13 +297,6 @@ int VADD_CASReply(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) { RedisModule_DictSet(vset->dict,val,newnode); val = NULL; // Don't free it later. - /* FIXME: probably it's better to drop the CAS argument when - * replicating. Other VADDs with CAS against the same item may arrive - * and can be executed out of order. Also DEL commands may arrive - * while the VADD is in progress. - * - * The problem of dropping CAS however is that the replica may no - * longer be able to keep with the insertion load. */ RedisModule_ReplicateVerbatim(ctx); } @@ -358,6 +351,20 @@ int VADD_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) { } } + /* Drop CAS if this is a replica and we are getting the command from the + * replication link: we want to add/delete items in the same order as + * the master, while with CAS the timing would be different. + * + * Also for Lua scripts and MULTI/EXEC, we want to run the command + * on the main thread. */ + if (RedisModule_GetContextFlags(ctx) & + (REDISMODULE_CTX_FLAGS_REPLICATED| + REDISMODULE_CTX_FLAGS_LUA| + REDISMODULE_CTX_FLAGS_MULTI)) + { + cas = 0; + } + /* Open/create key */ RedisModuleKey *key = RedisModule_OpenKey(ctx,argv[1], REDISMODULE_READ|REDISMODULE_WRITE);