Lua scripts promoted from eval to script load to avoid evict (#637)

In ad28d222edcef9d4496fd7a94656013f07dd08e5, we added a Lua eval
scripts eviction. If the script was previously added via EVAL, we
promote it to SCRIPT LOAD, prevent it from being evicted later.

Signed-off-by: Binbin <binloveplay1314@qq.com>
This commit is contained in:
Binbin 2024-06-14 23:32:19 +08:00 committed by GitHub
parent 4c6bf30f58
commit d5496e42bc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 0 deletions

View File

@ -447,6 +447,13 @@ sds luaCreateFunction(client *c, robj *body, int evalsha) {
sha1hex(funcname + 2, body->ptr, sdslen(body->ptr));
if ((de = dictFind(lctx.lua_scripts, funcname + 2)) != NULL) {
/* If the script was previously added via EVAL, we promote it to
* SCRIPT LOAD, prevent it from being evicted later. */
luaScript *l = dictGetVal(de);
if (evalsha && l->node) {
listDelNode(lctx.lua_scripts_lru_list, l->node);
l->node = NULL;
}
return dictGetKey(de);
}

View File

@ -1646,6 +1646,19 @@ start_server {tags {"scripting external:skip"}} {
# cached = num load scripts + 500 eval scripts
assert_equal $cached [expr $num+500]
}
test {Lua scripts promoted from eval to script load} {
r script flush
r config resetstat
r eval "return 'hello world'" 0
set sha [r script load "return 'hello world'"]
for {set j 1} {$j <= 500} {incr j} {
r script load "return $j"
r eval "return 'str_$j'" 0
}
assert_equal {hello world} [r evalsha $sha 0]
}
}
} ;# is_eval