From dad7f71f157620be7d2e4168cb6b07cbd255cf61 Mon Sep 17 00:00:00 2001 From: "Meir Shpilraien (Spielrein)" Date: Tue, 6 Dec 2022 12:22:36 +0200 Subject: [PATCH] Remove dead code on sorting reply on Lua scripts. (#10701) On v6.2.7 a new mechanism was added to Lua scripts that allows filtering the globals of the Lua interpreter. This mechanism was added on the following commit: https://github.com/redis/redis/commit/11b602fbf8f9cdf8fc741c24625ab6287ab998a9 One of the globals that was filtered out was `__redis__compare_helper`. This global was missed and was not added to the allow list or to the deny list. This is why we get the following warning when Redis starts: `A key '__redis__compare_helper' was added to Lua globals which is not on the globals allow list nor listed on the deny list.` After investigating the git blame log, the conclusion is that `__redis__compare_helper` is no longer needed, the PR deletes this function, and fixes the warning. Detailed Explanation: `__redis__compare_helper` was added on this commit: https://github.com/redis/redis/commit/2c861050c1 Its purpose is to sort the replies of `SORT` command when script replication is enable and keep the replies deterministic and avoid primary and replica synchronization issues. On `SORT` command, there was a need for special compare function that are able to compare boolean values. The need to sort the `SORT` command reply was removed on this commit: https://github.com/redis/redis/commit/36741b2c818a95e8ef167818271614ee6b1bc414 The sorting was moved to be part of the `SORT` command and there was not longer a need to sort it on the Lua interpreter. The commit made `__redis__compare_helper` a dead code but did not deleted it. (cherry picked from commit 64c657a8af03c6d58507b9620947491f36e75037) --- src/scripting.c | 28 +--------------------------- 1 file changed, 1 insertion(+), 27 deletions(-) diff --git a/src/scripting.c b/src/scripting.c index c5393c16e..42d26537b 100644 --- a/src/scripting.c +++ b/src/scripting.c @@ -328,21 +328,7 @@ void luaSortArray(lua_State *lua) { lua_pushstring(lua,"sort"); lua_gettable(lua,-2); /* Stack: array, table, table.sort */ lua_pushvalue(lua,-3); /* Stack: array, table, table.sort, array */ - if (lua_pcall(lua,1,0,0)) { - /* Stack: array, table, error */ - - /* We are not interested in the error, we assume that the problem is - * that there are 'false' elements inside the array, so we try - * again with a slower function but able to handle this case, that - * is: table.sort(table, __redis__compare_helper) */ - lua_pop(lua,1); /* Stack: array, table */ - lua_pushstring(lua,"sort"); /* Stack: array, table, sort */ - lua_gettable(lua,-2); /* Stack: array, table, table.sort */ - lua_pushvalue(lua,-3); /* Stack: array, table, table.sort, array */ - lua_getglobal(lua,"__redis__compare_helper"); - /* Stack: array, table, table.sort, array, __redis__compare_helper */ - lua_call(lua,2,0); - } + lua_call(lua,1,0); /* Stack: array (sorted), table */ /* Stack: array (sorted), table */ lua_pop(lua,1); /* Stack: array (sorted) */ } @@ -1256,18 +1242,6 @@ void scriptingInit(int setup) { lua_setglobal(lua,"math"); - /* Add a helper function that we use to sort the multi bulk output of non - * deterministic commands, when containing 'false' elements. */ - { - char *compare_func = "function __redis__compare_helper(a,b)\n" - " if a == false then a = '' end\n" - " if b == false then b = '' end\n" - " return a