diff options
author | Viktor Söderqvist <viktor.soderqvist@est.tech> | 2021-11-28 10:26:28 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-28 11:26:28 +0200 |
commit | acf3495eb823df8d1f358b1fe59b759fcc49666f (patch) | |
tree | d4975294079d9458ce7203289a1f1473bd68ed9f /tests/modules | |
parent | 4d8700786e2f198f9ef44961196122bbb80ee640 (diff) | |
download | redis-acf3495eb823df8d1f358b1fe59b759fcc49666f.tar.gz |
Sort out the mess around writable replicas and lookupKeyRead/Write (#9572)
Writable replicas now no longer use the values of expired keys. Expired keys are
deleted when lookupKeyWrite() is used, even on a writable replica. Previously,
writable replicas could use the value of an expired key in write commands such
as INCR, SUNIONSTORE, etc..
This commit also sorts out the mess around the functions lookupKeyRead() and
lookupKeyWrite() so they now indicate what we intend to do with the key and
are not affected by the command calling them.
Multi-key commands like SUNIONSTORE, ZUNIONSTORE, COPY and SORT with the
store option now use lookupKeyRead() for the keys they're reading from (which will
not allow reading from logically expired keys).
This commit also fixes a bug where PFCOUNT could return a value of an
expired key.
Test modules commands have their readonly and write flags updated to correctly
reflect their lookups for reading or writing. Modules are not required to
correctly reflect this in their command flags, but this change is made for
consistency since the tests serve as usage examples.
Fixes #6842. Fixes #7475.
Diffstat (limited to 'tests/modules')
-rw-r--r-- | tests/modules/aclcheck.c | 5 | ||||
-rw-r--r-- | tests/modules/basics.c | 4 | ||||
-rw-r--r-- | tests/modules/blockedclient.c | 3 | ||||
-rw-r--r-- | tests/modules/blockonkeys.c | 16 | ||||
-rw-r--r-- | tests/modules/datatype.c | 9 | ||||
-rw-r--r-- | tests/modules/hash.c | 2 | ||||
-rw-r--r-- | tests/modules/keyspace_events.c | 12 | ||||
-rw-r--r-- | tests/modules/list.c | 10 | ||||
-rw-r--r-- | tests/modules/propagate.c | 6 | ||||
-rw-r--r-- | tests/modules/stream.c | 10 | ||||
-rw-r--r-- | tests/modules/test_lazyfree.c | 2 | ||||
-rw-r--r-- | tests/modules/testrdb.c | 2 | ||||
-rw-r--r-- | tests/modules/zset.c | 2 |
13 files changed, 46 insertions, 37 deletions
diff --git a/tests/modules/aclcheck.c b/tests/modules/aclcheck.c index 739890132..e307744fd 100644 --- a/tests/modules/aclcheck.c +++ b/tests/modules/aclcheck.c @@ -157,7 +157,7 @@ int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) if (RedisModule_Init(ctx,"aclcheck",1,REDISMODULE_APIVER_1)== REDISMODULE_ERR) return REDISMODULE_ERR; - if (RedisModule_CreateCommand(ctx,"aclcheck.set.check.key", set_aclcheck_key,"",0,0,0) == REDISMODULE_ERR) + if (RedisModule_CreateCommand(ctx,"aclcheck.set.check.key", set_aclcheck_key,"write",0,0,0) == REDISMODULE_ERR) return REDISMODULE_ERR; if (RedisModule_CreateCommand(ctx,"aclcheck.publish.check.channel", publish_aclcheck_channel,"",0,0,0) == REDISMODULE_ERR) @@ -169,7 +169,8 @@ int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) if (RedisModule_CreateCommand(ctx,"aclcheck.rm_call.check.cmd.module.user", rm_call_aclcheck_cmd_module_user,"",0,0,0) == REDISMODULE_ERR) return REDISMODULE_ERR; - if (RedisModule_CreateCommand(ctx,"aclcheck.rm_call", rm_call_aclcheck,"",0,0,0) == REDISMODULE_ERR) + if (RedisModule_CreateCommand(ctx,"aclcheck.rm_call", rm_call_aclcheck, + "write",0,0,0) == REDISMODULE_ERR) return REDISMODULE_ERR; return REDISMODULE_OK; diff --git a/tests/modules/basics.c b/tests/modules/basics.c index 7f4383759..dd2e0e165 100644 --- a/tests/modules/basics.c +++ b/tests/modules/basics.c @@ -936,12 +936,12 @@ int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) return REDISMODULE_ERR; if (RedisModule_CreateCommand(ctx,"test.basics", - TestBasics,"readonly",1,1,1) == REDISMODULE_ERR) + TestBasics,"write",1,1,1) == REDISMODULE_ERR) return REDISMODULE_ERR; /* the following commands are used by an external test and should not be added to TestBasics */ if (RedisModule_CreateCommand(ctx,"test.rmcallautomode", - TestCallRespAutoMode,"readonly",1,1,1) == REDISMODULE_ERR) + TestCallRespAutoMode,"write",1,1,1) == REDISMODULE_ERR) return REDISMODULE_ERR; if (RedisModule_CreateCommand(ctx,"test.getresp", diff --git a/tests/modules/blockedclient.c b/tests/modules/blockedclient.c index ebe89ecb2..5df51f63d 100644 --- a/tests/modules/blockedclient.c +++ b/tests/modules/blockedclient.c @@ -214,7 +214,8 @@ int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) if (RedisModule_CreateCommand(ctx, "acquire_gil", acquire_gil, "", 0, 0, 0) == REDISMODULE_ERR) return REDISMODULE_ERR; - if (RedisModule_CreateCommand(ctx, "do_rm_call", do_rm_call, "", 0, 0, 0) == REDISMODULE_ERR) + if (RedisModule_CreateCommand(ctx, "do_rm_call", do_rm_call, + "write", 0, 0, 0) == REDISMODULE_ERR) return REDISMODULE_ERR; if (RedisModule_CreateCommand(ctx, "do_bg_rm_call", do_bg_rm_call, "", 0, 0, 0) == REDISMODULE_ERR) diff --git a/tests/modules/blockonkeys.c b/tests/modules/blockonkeys.c index 48b408d59..72ccbcf38 100644 --- a/tests/modules/blockonkeys.c +++ b/tests/modules/blockonkeys.c @@ -470,35 +470,35 @@ int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) if (fsltype == NULL) return REDISMODULE_ERR; - if (RedisModule_CreateCommand(ctx,"fsl.push",fsl_push,"",1,1,1) == REDISMODULE_ERR) + if (RedisModule_CreateCommand(ctx,"fsl.push",fsl_push,"write",1,1,1) == REDISMODULE_ERR) return REDISMODULE_ERR; - if (RedisModule_CreateCommand(ctx,"fsl.bpop",fsl_bpop,"",1,1,1) == REDISMODULE_ERR) + if (RedisModule_CreateCommand(ctx,"fsl.bpop",fsl_bpop,"write",1,1,1) == REDISMODULE_ERR) return REDISMODULE_ERR; - if (RedisModule_CreateCommand(ctx,"fsl.bpopgt",fsl_bpopgt,"",1,1,1) == REDISMODULE_ERR) + if (RedisModule_CreateCommand(ctx,"fsl.bpopgt",fsl_bpopgt,"write",1,1,1) == REDISMODULE_ERR) return REDISMODULE_ERR; - if (RedisModule_CreateCommand(ctx,"fsl.bpoppush",fsl_bpoppush,"",1,2,1) == REDISMODULE_ERR) + if (RedisModule_CreateCommand(ctx,"fsl.bpoppush",fsl_bpoppush,"write",1,2,1) == REDISMODULE_ERR) return REDISMODULE_ERR; if (RedisModule_CreateCommand(ctx,"fsl.getall",fsl_getall,"",1,1,1) == REDISMODULE_ERR) return REDISMODULE_ERR; if (RedisModule_CreateCommand(ctx, "blockonkeys.popall", blockonkeys_popall, - "", 1, 1, 1) == REDISMODULE_ERR) + "write", 1, 1, 1) == REDISMODULE_ERR) return REDISMODULE_ERR; if (RedisModule_CreateCommand(ctx, "blockonkeys.lpush", blockonkeys_lpush, - "", 1, 1, 1) == REDISMODULE_ERR) + "write", 1, 1, 1) == REDISMODULE_ERR) return REDISMODULE_ERR; if (RedisModule_CreateCommand(ctx, "blockonkeys.lpush_unblock", blockonkeys_lpush, - "", 1, 1, 1) == REDISMODULE_ERR) + "write", 1, 1, 1) == REDISMODULE_ERR) return REDISMODULE_ERR; if (RedisModule_CreateCommand(ctx, "blockonkeys.blpopn", blockonkeys_blpopn, - "", 1, 1, 1) == REDISMODULE_ERR) + "write", 1, 1, 1) == REDISMODULE_ERR) return REDISMODULE_ERR; return REDISMODULE_OK; diff --git a/tests/modules/datatype.c b/tests/modules/datatype.c index 8a70d4be1..d763a2412 100644 --- a/tests/modules/datatype.c +++ b/tests/modules/datatype.c @@ -206,19 +206,22 @@ int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) if (datatype == NULL) return REDISMODULE_ERR; - if (RedisModule_CreateCommand(ctx,"datatype.set", datatype_set,"deny-oom",1,1,1) == REDISMODULE_ERR) + if (RedisModule_CreateCommand(ctx,"datatype.set", datatype_set, + "write deny-oom", 1, 1, 1) == REDISMODULE_ERR) return REDISMODULE_ERR; if (RedisModule_CreateCommand(ctx,"datatype.get", datatype_get,"",1,1,1) == REDISMODULE_ERR) return REDISMODULE_ERR; - if (RedisModule_CreateCommand(ctx,"datatype.restore", datatype_restore,"deny-oom",1,1,1) == REDISMODULE_ERR) + if (RedisModule_CreateCommand(ctx,"datatype.restore", datatype_restore, + "write deny-oom", 1, 1, 1) == REDISMODULE_ERR) return REDISMODULE_ERR; if (RedisModule_CreateCommand(ctx,"datatype.dump", datatype_dump,"",1,1,1) == REDISMODULE_ERR) return REDISMODULE_ERR; - if (RedisModule_CreateCommand(ctx,"datatype.swap", datatype_swap,"",1,1,1) == REDISMODULE_ERR) + if (RedisModule_CreateCommand(ctx, "datatype.swap", datatype_swap, + "write", 1, 1, 1) == REDISMODULE_ERR) return REDISMODULE_ERR; return REDISMODULE_OK; diff --git a/tests/modules/hash.c b/tests/modules/hash.c index 05ab03800..001a34e49 100644 --- a/tests/modules/hash.c +++ b/tests/modules/hash.c @@ -81,7 +81,7 @@ int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) REDISMODULE_NOT_USED(argc); if (RedisModule_Init(ctx, "hash", 1, REDISMODULE_APIVER_1) == REDISMODULE_OK && - RedisModule_CreateCommand(ctx, "hash.set", hash_set, "", + RedisModule_CreateCommand(ctx, "hash.set", hash_set, "write", 1, 1, 1) == REDISMODULE_OK) { return REDISMODULE_OK; } else { diff --git a/tests/modules/keyspace_events.c b/tests/modules/keyspace_events.c index 8a55e0f44..1cfeae998 100644 --- a/tests/modules/keyspace_events.c +++ b/tests/modules/keyspace_events.c @@ -250,19 +250,23 @@ int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) return REDISMODULE_ERR; } - if (RedisModule_CreateCommand(ctx,"keyspace.del_key_copy", cmdDelKeyCopy,"",0,0,0) == REDISMODULE_ERR){ + if (RedisModule_CreateCommand(ctx, "keyspace.del_key_copy", cmdDelKeyCopy, + "write", 0, 0, 0) == REDISMODULE_ERR){ return REDISMODULE_ERR; } - if (RedisModule_CreateCommand(ctx,"keyspace.incr_case1", cmdIncrCase1,"",0,0,0) == REDISMODULE_ERR){ + if (RedisModule_CreateCommand(ctx, "keyspace.incr_case1", cmdIncrCase1, + "write", 0, 0, 0) == REDISMODULE_ERR){ return REDISMODULE_ERR; } - if (RedisModule_CreateCommand(ctx,"keyspace.incr_case2", cmdIncrCase2,"",0,0,0) == REDISMODULE_ERR){ + if (RedisModule_CreateCommand(ctx, "keyspace.incr_case2", cmdIncrCase2, + "write", 0, 0, 0) == REDISMODULE_ERR){ return REDISMODULE_ERR; } - if (RedisModule_CreateCommand(ctx,"keyspace.incr_case3", cmdIncrCase3,"",0,0,0) == REDISMODULE_ERR){ + if (RedisModule_CreateCommand(ctx, "keyspace.incr_case3", cmdIncrCase3, + "write", 0, 0, 0) == REDISMODULE_ERR){ return REDISMODULE_ERR; } diff --git a/tests/modules/list.c b/tests/modules/list.c index fcbd446ce..727b05d6f 100644 --- a/tests/modules/list.c +++ b/tests/modules/list.c @@ -219,15 +219,15 @@ int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) if (RedisModule_Init(ctx, "list", 1, REDISMODULE_APIVER_1) == REDISMODULE_OK && RedisModule_CreateCommand(ctx, "list.getall", list_getall, "", 1, 1, 1) == REDISMODULE_OK && - RedisModule_CreateCommand(ctx, "list.edit", list_edit, "", + RedisModule_CreateCommand(ctx, "list.edit", list_edit, "write", 1, 1, 1) == REDISMODULE_OK && - RedisModule_CreateCommand(ctx, "list.get", list_get, "", + RedisModule_CreateCommand(ctx, "list.get", list_get, "write", 1, 1, 1) == REDISMODULE_OK && - RedisModule_CreateCommand(ctx, "list.set", list_set, "", + RedisModule_CreateCommand(ctx, "list.set", list_set, "write", 1, 1, 1) == REDISMODULE_OK && - RedisModule_CreateCommand(ctx, "list.insert", list_insert, "", + RedisModule_CreateCommand(ctx, "list.insert", list_insert, "write", 1, 1, 1) == REDISMODULE_OK && - RedisModule_CreateCommand(ctx, "list.delete", list_delete, "", + RedisModule_CreateCommand(ctx, "list.delete", list_delete, "write", 1, 1, 1) == REDISMODULE_OK) { return REDISMODULE_OK; } else { diff --git a/tests/modules/propagate.c b/tests/modules/propagate.c index 766c61ea5..b9852c158 100644 --- a/tests/modules/propagate.c +++ b/tests/modules/propagate.c @@ -239,17 +239,17 @@ int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) if (RedisModule_CreateCommand(ctx,"propagate-test.mixed", propagateTestMixedCommand, - "",1,1,1) == REDISMODULE_ERR) + "write",1,1,1) == REDISMODULE_ERR) return REDISMODULE_ERR; if (RedisModule_CreateCommand(ctx,"propagate-test.nested", propagateTestNestedCommand, - "",1,1,1) == REDISMODULE_ERR) + "write",1,1,1) == REDISMODULE_ERR) return REDISMODULE_ERR; if (RedisModule_CreateCommand(ctx,"propagate-test.incr", propagateTestIncr, - "",1,1,1) == REDISMODULE_ERR) + "write",1,1,1) == REDISMODULE_ERR) return REDISMODULE_ERR; return REDISMODULE_OK; diff --git a/tests/modules/stream.c b/tests/modules/stream.c index b82568b94..65762a399 100644 --- a/tests/modules/stream.c +++ b/tests/modules/stream.c @@ -238,19 +238,19 @@ int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) if (RedisModule_Init(ctx, "stream", 1, REDISMODULE_APIVER_1) == REDISMODULE_ERR) return REDISMODULE_ERR; - if (RedisModule_CreateCommand(ctx, "stream.add", stream_add, "", + if (RedisModule_CreateCommand(ctx, "stream.add", stream_add, "write", 1, 1, 1) == REDISMODULE_ERR) return REDISMODULE_ERR; - if (RedisModule_CreateCommand(ctx, "stream.addn", stream_addn, "", + if (RedisModule_CreateCommand(ctx, "stream.addn", stream_addn, "write", 1, 1, 1) == REDISMODULE_ERR) return REDISMODULE_ERR; - if (RedisModule_CreateCommand(ctx, "stream.delete", stream_delete, "", + if (RedisModule_CreateCommand(ctx, "stream.delete", stream_delete, "write", 1, 1, 1) == REDISMODULE_ERR) return REDISMODULE_ERR; - if (RedisModule_CreateCommand(ctx, "stream.range", stream_range, "", + if (RedisModule_CreateCommand(ctx, "stream.range", stream_range, "write", 1, 1, 1) == REDISMODULE_ERR) return REDISMODULE_ERR; - if (RedisModule_CreateCommand(ctx, "stream.trim", stream_trim, "", + if (RedisModule_CreateCommand(ctx, "stream.trim", stream_trim, "write", 1, 1, 1) == REDISMODULE_ERR) return REDISMODULE_ERR; diff --git a/tests/modules/test_lazyfree.c b/tests/modules/test_lazyfree.c index 144dab9b3..7ba213ff8 100644 --- a/tests/modules/test_lazyfree.c +++ b/tests/modules/test_lazyfree.c @@ -98,7 +98,7 @@ int LazyFreeLinkLen_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, if (argc != 2) return RedisModule_WrongArity(ctx); RedisModuleKey *key = RedisModule_OpenKey(ctx,argv[1], - REDISMODULE_READ|REDISMODULE_WRITE); + REDISMODULE_READ); int type = RedisModule_KeyType(key); if (type != REDISMODULE_KEYTYPE_EMPTY && RedisModule_ModuleTypeGetType(key) != LazyFreeLinkType) diff --git a/tests/modules/testrdb.c b/tests/modules/testrdb.c index 6786fdf2e..6f2ca2a14 100644 --- a/tests/modules/testrdb.c +++ b/tests/modules/testrdb.c @@ -262,7 +262,7 @@ int testrdb_get_key(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) return REDISMODULE_OK; } - RedisModuleKey *key = RedisModule_OpenKey(ctx, argv[1], REDISMODULE_WRITE); + RedisModuleKey *key = RedisModule_OpenKey(ctx, argv[1], REDISMODULE_READ); RedisModuleString *str = RedisModule_ModuleTypeGetValue(key); RedisModule_CloseKey(key); RedisModule_ReplyWithString(ctx, str); diff --git a/tests/modules/zset.c b/tests/modules/zset.c index 4806f6549..91791f907 100644 --- a/tests/modules/zset.c +++ b/tests/modules/zset.c @@ -22,7 +22,7 @@ int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) REDISMODULE_NOT_USED(argc); if (RedisModule_Init(ctx, "zset", 1, REDISMODULE_APIVER_1) == REDISMODULE_OK && - RedisModule_CreateCommand(ctx, "zset.rem", zset_rem, "", + RedisModule_CreateCommand(ctx, "zset.rem", zset_rem, "write", 1, 1, 1) == REDISMODULE_OK) return REDISMODULE_OK; else |