From 940753d24782e99d175eddfe482d41225dfbba03 Mon Sep 17 00:00:00 2001 From: Binbin Date: Tue, 17 Dec 2024 12:29:18 +0800 Subject: [PATCH 1/2] Dont print lua script body when doing check-rdb In old versions, if we are saving the replication info on disk, we will save the lua scripts in the RDB see f11a7585a8498689e8fd1afbcab4fdc2ba38c38f. Currently check-rdb prints all the aux fields, this including lua scripts. Although we no longer save lua scripts to RDB file, we may use the new check-rdb tool to check the old RDB files, and the printing of lua scripts will pollute the output. If it is an RDB file that abuses lua eval scripts, it will print a lot of content. At the end, if there is a lua script, we will print an info to show the number of lua scripts. This may be a potential breaking change, but i dont think someone is using it to get the lua scripts output, people should not rely on it and we should not print lua body anyway. Signed-off-by: Binbin --- src/valkey-check-rdb.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/valkey-check-rdb.c b/src/valkey-check-rdb.c index ba94c172c7..dceedba94c 100644 --- a/src/valkey-check-rdb.c +++ b/src/valkey-check-rdb.c @@ -47,6 +47,7 @@ struct { unsigned long keys; /* Number of keys processed. */ unsigned long expires; /* Number of keys with an expire. */ unsigned long already_expired; /* Number of keys already expired. */ + unsigned long lua_scripts; /* Number of lua scripts. */ int doing; /* The state while reading the RDB. */ int error_set; /* True if error is populated. */ char error[1024]; @@ -108,6 +109,9 @@ void rdbShowGenericInfo(void) { printf("[info] %lu keys read\n", rdbstate.keys); printf("[info] %lu expires\n", rdbstate.expires); printf("[info] %lu already expired\n", rdbstate.already_expired); + if (rdbstate.lua_scripts) { + printf("[info] %lu lua scripts read\n", rdbstate.lua_scripts); + } } /* Called on RDB errors. Provides details about the RDB and the offset @@ -280,7 +284,13 @@ int redis_check_rdb(char *rdbfilename, FILE *fp) { goto eoferr; } - rdbCheckInfo("AUX FIELD %s = '%s'", (char *)auxkey->ptr, (char *)auxval->ptr); + if (!strcasecmp(auxkey->ptr, "lua")) { + /* We do not print the lua aux field in here, otherwise a large number of lua + * scripts will pollute the output. */ + rdbstate.lua_scripts++; + } else { + rdbCheckInfo("AUX FIELD %s = '%s'", (char *)auxkey->ptr, (char *)auxval->ptr); + } decrRefCount(auxkey); decrRefCount(auxval); continue; /* Read type again. */ From 812b10e347c255ad9b42b1d7cf6b90ba76c22f3c Mon Sep 17 00:00:00 2001 From: Binbin Date: Fri, 20 Dec 2024 10:22:41 +0800 Subject: [PATCH 2/2] update comment and print the lua Signed-off-by: Binbin --- src/valkey-check-rdb.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/valkey-check-rdb.c b/src/valkey-check-rdb.c index dceedba94c..463f25053e 100644 --- a/src/valkey-check-rdb.c +++ b/src/valkey-check-rdb.c @@ -285,12 +285,13 @@ int redis_check_rdb(char *rdbfilename, FILE *fp) { } if (!strcasecmp(auxkey->ptr, "lua")) { - /* We do not print the lua aux field in here, otherwise a large number of lua - * scripts will pollute the output. */ + /* In older version before 7.0, we may save lua scripts in a replication RDB, + * although it is not an actually aux field, we will still print it in here since + * it's easy to filter using external grep. Use a counter so that at the end we + * can print its number, if any. */ rdbstate.lua_scripts++; - } else { - rdbCheckInfo("AUX FIELD %s = '%s'", (char *)auxkey->ptr, (char *)auxval->ptr); } + rdbCheckInfo("AUX FIELD %s = '%s'", (char *)auxkey->ptr, (char *)auxval->ptr); decrRefCount(auxkey); decrRefCount(auxval); continue; /* Read type again. */