Set `old_li` to NULL to avoid linking it again on error. Before the fix, loading an already existing library will cause the existing library to be added again. This cause not harm other then wrong statistics. The statistics that are effected by the issue are: * `libraries_count` and `functions_count` returned by `function stats` command * `used_memory_functions` returned on `info memory` command * `functions.caches` returned on `memory stats` command
This commit is contained in:
parent
a3df2777e8
commit
442e73ea09
@ -963,6 +963,7 @@ sds functionsCreateWithLibraryCtx(sds code, int replace, sds* err, functionsLibC
|
||||
|
||||
old_li = dictFetchValue(lib_ctx->libraries, md.name);
|
||||
if (old_li && !replace) {
|
||||
old_li = NULL;
|
||||
*err = sdscatfmt(sdsempty(), "Library '%S' already exists", md.name);
|
||||
goto error;
|
||||
}
|
||||
|
@ -1141,6 +1141,23 @@ start_server {tags {"scripting"}} {
|
||||
r function stats
|
||||
} {running_script {} engines {LUA {libraries_count 1 functions_count 1}}}
|
||||
|
||||
test {FUNCTION - test function stats on loading failure} {
|
||||
r FUNCTION FLUSH
|
||||
|
||||
r FUNCTION load {#!lua name=test1
|
||||
redis.register_function('f1', function() return 1 end)
|
||||
redis.register_function('f2', function() return 1 end)
|
||||
}
|
||||
|
||||
catch {r FUNCTION load {#!lua name=test1
|
||||
redis.register_function('f3', function() return 1 end)
|
||||
}} e
|
||||
assert_match "*Library 'test1' already exists*" $e
|
||||
|
||||
|
||||
r function stats
|
||||
} {running_script {} engines {LUA {libraries_count 1 functions_count 2}}}
|
||||
|
||||
test {FUNCTION - function stats cleaned after flush} {
|
||||
r function flush
|
||||
r function stats
|
||||
|
Loading…
x
Reference in New Issue
Block a user