From 7a3353de5c0b186e92dd48df8de643d395f1eaee Mon Sep 17 00:00:00 2001 From: "wei.kukey" Date: Mon, 10 Jun 2024 11:50:56 +0800 Subject: [PATCH 01/13] script add dump subcommand Change-Id: I60aacd3198652174883f335b36efc18d69a1fb43 Signed-off-by: wei.kukey --- src/commands.def | 26 +++++++++++++++++++++ src/commands/script-dump.json | 44 +++++++++++++++++++++++++++++++++++ src/eval.c | 22 ++++++++++++++++++ tests/unit/scripting.tcl | 5 ++++ 4 files changed, 97 insertions(+) create mode 100644 src/commands/script-dump.json diff --git a/src/commands.def b/src/commands.def index c59cb01dc1..8cfd40fce7 100644 --- a/src/commands.def +++ b/src/commands.def @@ -5210,6 +5210,31 @@ struct COMMAND_ARG SCRIPT_DEBUG_Args[] = { {MAKE_ARG("mode",ARG_TYPE_ONEOF,-1,NULL,NULL,NULL,CMD_ARG_NONE,3,NULL),.subargs=SCRIPT_DEBUG_mode_Subargs}, }; +/********** SCRIPT DUMP ********************/ + +#ifndef SKIP_CMD_HISTORY_TABLE +/* SCRIPT DUMP history */ +#define SCRIPT_DUMP_History NULL +#endif + +#ifndef SKIP_CMD_TIPS_TABLE +/* SCRIPT DUMP tips */ +const char *SCRIPT_DUMP_Tips[] = { +"request_policy:all_shards", +"response_policy:agg_logical_and", +}; +#endif + +#ifndef SKIP_CMD_KEY_SPECS_TABLE +/* SCRIPT DUMP key specs */ +#define SCRIPT_DUMP_Keyspecs NULL +#endif + +/* SCRIPT DUMP argument table */ +struct COMMAND_ARG SCRIPT_DUMP_Args[] = { +{MAKE_ARG("sha1",ARG_TYPE_STRING,-1,NULL,NULL,NULL,CMD_ARG_MULTIPLE,0,NULL)}, +}; + /********** SCRIPT EXISTS ********************/ #ifndef SKIP_CMD_HISTORY_TABLE @@ -5333,6 +5358,7 @@ struct COMMAND_ARG SCRIPT_LOAD_Args[] = { /* SCRIPT command table */ struct COMMAND_STRUCT SCRIPT_Subcommands[] = { {MAKE_CMD("debug","Sets the debug mode of server-side Lua scripts.","O(1)","3.2.0",CMD_DOC_NONE,NULL,NULL,"scripting",COMMAND_GROUP_SCRIPTING,SCRIPT_DEBUG_History,0,SCRIPT_DEBUG_Tips,0,scriptCommand,3,CMD_NOSCRIPT,ACL_CATEGORY_SCRIPTING,SCRIPT_DEBUG_Keyspecs,0,NULL,1),.args=SCRIPT_DEBUG_Args}, +{MAKE_CMD("dump","Dump server-side Lua scripts in the script cache.","O(N) with N being the number of scripts to check (so checking a single script is an O(1) operation).","7.2.4",CMD_DOC_NONE,NULL,NULL,"scripting",COMMAND_GROUP_SCRIPTING,SCRIPT_DUMP_History,0,SCRIPT_DUMP_Tips,2,scriptCommand,-3,CMD_NOSCRIPT,ACL_CATEGORY_SCRIPTING,SCRIPT_DUMP_Keyspecs,0,NULL,1),.args=SCRIPT_DUMP_Args}, {MAKE_CMD("exists","Determines whether server-side Lua scripts exist in the script cache.","O(N) with N being the number of scripts to check (so checking a single script is an O(1) operation).","2.6.0",CMD_DOC_NONE,NULL,NULL,"scripting",COMMAND_GROUP_SCRIPTING,SCRIPT_EXISTS_History,0,SCRIPT_EXISTS_Tips,2,scriptCommand,-3,CMD_NOSCRIPT,ACL_CATEGORY_SCRIPTING,SCRIPT_EXISTS_Keyspecs,0,NULL,1),.args=SCRIPT_EXISTS_Args}, {MAKE_CMD("flush","Removes all server-side Lua scripts from the script cache.","O(N) with N being the number of scripts in cache","2.6.0",CMD_DOC_NONE,NULL,NULL,"scripting",COMMAND_GROUP_SCRIPTING,SCRIPT_FLUSH_History,1,SCRIPT_FLUSH_Tips,2,scriptCommand,-2,CMD_NOSCRIPT,ACL_CATEGORY_SCRIPTING,SCRIPT_FLUSH_Keyspecs,0,NULL,1),.args=SCRIPT_FLUSH_Args}, {MAKE_CMD("help","Returns helpful text about the different subcommands.","O(1)","5.0.0",CMD_DOC_NONE,NULL,NULL,"scripting",COMMAND_GROUP_SCRIPTING,SCRIPT_HELP_History,0,SCRIPT_HELP_Tips,0,scriptCommand,2,CMD_LOADING|CMD_STALE,ACL_CATEGORY_SCRIPTING,SCRIPT_HELP_Keyspecs,0,NULL,0)}, diff --git a/src/commands/script-dump.json b/src/commands/script-dump.json new file mode 100644 index 0000000000..e97318dc42 --- /dev/null +++ b/src/commands/script-dump.json @@ -0,0 +1,44 @@ +{ + "DUMP": { + "summary": "Dump server-side Lua scripts in the script cache.", + "complexity": "O(N) with N being the number of scripts to check (so checking a single script is an O(1) operation).", + "group": "scripting", + "since": "7.2.4", + "arity": -3, + "container": "SCRIPT", + "function": "scriptCommand", + "command_flags": [ + "NOSCRIPT" + ], + "acl_categories": [ + "SCRIPTING" + ], + "command_tips": [ + "REQUEST_POLICY:ALL_SHARDS", + "RESPONSE_POLICY:AGG_LOGICAL_AND" + ], + "arguments": [ + { + "name": "sha1", + "type": "string", + "multiple": true + } + ], + "reply_schema": { + "description": "An array of lua scripts that correspond to the specified SHA1 digest arguments.", + "type": "array", + "items": { + "oneOf": [ + { + "description": "lua script if sha1 hash exists in script cache.", + "type": "string" + }, + { + "description": "null if sha1 hash does not exist in script cache.", + "type": "null" + } + ] + } + } + } +} diff --git a/src/eval.c b/src/eval.c index 464c8ef487..ca54d66fca 100644 --- a/src/eval.c +++ b/src/eval.c @@ -35,6 +35,7 @@ * 2. scriptingInit() - initServer() function from server.c invokes this to initialize LUA at startup. * It is also invoked between 2 eval invocations to reset Lua. */ +#include "dict.h" #include "server.h" #include "sha1.h" #include "rand.h" @@ -675,6 +676,8 @@ void scriptCommand(client *c) { " Kill the currently executing Lua script.", "LOAD