From 87672adee2c282ad9d6a989f4401094fda90ebba Mon Sep 17 00:00:00 2001 From: antirez Date: Fri, 13 Nov 2015 10:17:34 +0100 Subject: [PATCH] Lua debugger: better support for synchronous mode. --- src/redis-cli.c | 19 ++++++++++++++++--- src/scripting.c | 6 ++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/redis-cli.c b/src/redis-cli.c index 216544ce..f85463f2 100644 --- a/src/redis-cli.c +++ b/src/redis-cli.c @@ -112,7 +112,8 @@ static struct config { char prompt[128]; char *eval; int eval_ldb; - int eval_ldb_end; + int eval_ldb_sync; /* Ask for synchronous mode of the Lua debugger. */ + int eval_ldb_end; /* Lua debugging session ended. */ int last_cmd_type; } config; @@ -890,6 +891,10 @@ static int parseOptions(int argc, char **argv) { } else if (!strcmp(argv[i],"--ldb")) { config.eval_ldb = 1; config.output = OUTPUT_RAW; + } else if (!strcmp(argv[i],"--ldb-sync-mode")) { + config.eval_ldb = 1; + config.eval_ldb_sync = 1; + config.output = OUTPUT_RAW; } else if (!strcmp(argv[i],"-c")) { config.cluster_mode = 1; } else if (!strcmp(argv[i],"-d") && !lastarg) { @@ -973,6 +978,9 @@ static void usage(void) { " The test will run for the specified amount of seconds.\n" " --eval Send an EVAL command using the Lua script at .\n" " --ldb Used with --eval enable the Redis Lua debugger.\n" +" --ldb-sync-mode Like --ldb but uses the synchronous Lua debugger, in\n" +" this mode the server is blocked and script changes are\n" +" are not rolled back from the server memory.\n" " --help Output this help and exit.\n" " --version Output version and exit.\n" "\n" @@ -1116,7 +1124,9 @@ static void repl(void) { if (config.eval_ldb_end) { config.eval_ldb_end = 0; cliReadReply(0); - printf("\n(Lua debugging session ended. Dataset changes rolled back)\n\n"); + printf("\n(Lua debugging session ended%s)\n\n", + config.eval_ldb_sync ? "" : + " -- dataset changes rolled back"); } elapsed = mstime()-start_time; @@ -1172,7 +1182,8 @@ static int evalMode(int argc, char **argv) { /* If we are debugging a script, enable the Lua debugger. */ if (config.eval_ldb) { - redisReply *reply = redisCommand(context, "SCRIPT DEBUG yes"); + redisReply *reply = redisCommand(context, + config.eval_ldb_sync ? "SCRIPT DEBUG sync": "SCRIPT DEBUG yes"); if (reply) freeReplyObject(reply); } @@ -2321,6 +2332,8 @@ int main(int argc, char **argv) { config.auth = NULL; config.eval = NULL; config.eval_ldb = 0; + config.eval_ldb_end = 0; + config.eval_ldb_sync = 0; config.last_cmd_type = -1; spectrum_palette = spectrum_palette_color; diff --git a/src/scripting.c b/src/scripting.c index d071e59a..e4b7580f 100644 --- a/src/scripting.c +++ b/src/scripting.c @@ -1581,6 +1581,9 @@ int ldbStartSession(client *c) { freeClientAsync(c); /* Close the client in the parent side. */ return 0; } + } else { + serverLog(LL_WARNING, + "Redis synchronous debugging eval session started"); } /* Setup our debugging session. */ @@ -1615,6 +1618,9 @@ void ldbEndSession(client *c) { writeToClient(c->fd, c, 0); serverLog(LL_WARNING,"Lua debugging session child exiting"); exitFromChild(0); + } else { + serverLog(LL_WARNING, + "Redis synchronous debugging eval session ended"); } /* Otherwise let's restore client's state. */