Unverified Commit c556c57e authored by Meir Shpilraien (Spielrein)'s avatar Meir Shpilraien (Spielrein) Committed by GitHub
Browse files

Added AOF rewrite support for functions. (#10141)



Function PR was merged without AOF rw support because we thought this feature was going
to be removed on Redis 7.

Tests was added on aofrw.tcl
Other existing aofrw tests where slow due to unwanted rdb-key-save-delay
Co-authored-by: default avatarOran Agra <oran@redislabs.com>
parent 834fa587
......@@ -2102,6 +2102,35 @@ int rewriteModuleObject(rio *r, robj *key, robj *o, int dbid) {
return io.error ? 0 : 1;
}
static int rewriteFunctions(rio *aof) {
dict *functions = functionsLibGet();
dictIterator *iter = dictGetIterator(functions);
dictEntry *entry = NULL;
while ((entry = dictNext(iter))) {
functionLibInfo *li = dictGetVal(entry);
if (li->desc) {
if (rioWrite(aof, "*7\r\n", 4) == 0) goto werr;
} else {
if (rioWrite(aof, "*5\r\n", 4) == 0) goto werr;
}
char fucntion_load[] = "$8\r\nFUNCTION\r\n$4\r\nLOAD\r\n";
if (rioWrite(aof, fucntion_load, sizeof(fucntion_load) - 1) == 0) goto werr;
if (rioWriteBulkString(aof, li->ei->name, sdslen(li->ei->name)) == 0) goto werr;
if (rioWriteBulkString(aof, li->name, sdslen(li->name)) == 0) goto werr;
if (li->desc) {
if (rioWriteBulkString(aof, "description", 11) == 0) goto werr;
if (rioWriteBulkString(aof, li->desc, sdslen(li->desc)) == 0) goto werr;
}
if (rioWriteBulkString(aof, li->code, sdslen(li->code)) == 0) goto werr;
}
dictReleaseIterator(iter);
return 1;
werr:
dictReleaseIterator(iter);
return 0;
}
int rewriteAppendOnlyFileRio(rio *aof) {
dictIterator *di = NULL;
dictEntry *de;
......@@ -2116,6 +2145,8 @@ int rewriteAppendOnlyFileRio(rio *aof) {
sdsfree(ts);
}
if (rewriteFunctions(aof) == 0) goto werr;
for (j = 0; j < server.dbnum; j++) {
char selectcmd[] = "*2\r\n$6\r\nSELECT\r\n";
redisDb *db = server.db+j;
......
......@@ -74,6 +74,7 @@ start_server {tags {"aofrw external:skip"} overrides {aof-use-rdb-preamble no}}
} else {
fail "Can't find 'Killing AOF child' into recent logs"
}
r config set rdb-key-save-delay 0
}
foreach d {string int} {
......@@ -182,6 +183,19 @@ start_server {tags {"aofrw external:skip"} overrides {aof-use-rdb-preamble no}}
}
}
test "AOF rewrite functions" {
r flushall
r FUNCTION LOAD LUA test DESCRIPTION {desc} {
redis.register_function('test', function() return 1 end)
}
r bgrewriteaof
waitForBgrewriteaof r
r function flush
r debug loadaof
assert_equal [r fcall test 0] 1
r FUNCTION LIST
} {{library_name test engine LUA description desc functions {{name test description {} flags {}}}}}
test {BGREWRITEAOF is delayed if BGSAVE is in progress} {
r flushall
r set k v
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment