summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMeir Shpilraien (Spielrein) <meir@redis.com>2022-01-19 21:21:42 +0200
committerGitHub <noreply@github.com>2022-01-19 21:21:42 +0200
commitc556c57e5e8e348a28e4276f8ec2efed06b074d4 (patch)
treec9872a8e292c5de480ed4bbd2ef330b0518170f0 /src
parent834fa5870c6f1260cdf300dd5db4430fbf2db485 (diff)
downloadredis-c556c57e5e8e348a28e4276f8ec2efed06b074d4.tar.gz
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: Oran Agra <oran@redislabs.com>
Diffstat (limited to 'src')
-rw-r--r--src/aof.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/aof.c b/src/aof.c
index a587fb863..80b951200 100644
--- a/src/aof.c
+++ b/src/aof.c
@@ -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;