187 Commits

Author SHA1 Message Date
antirez
eeb4bcbd85 Change indentation and other minor details of PR #4489.
The main change introduced by this commit is pretending that help
arrays are more text than code, thus indenting them at level 0. This
improves readability, and is an old practice when defining arrays of
C strings describing text.

Additionally a few useless return statements are removed, and the HELP
subcommand capitalized when printed to the user.
2017-12-06 12:05:14 +01:00
Itamar Haber
29f1a3ee20 Merge remote-tracking branch 'upstream/unstable' into help_subcommands 2017-12-05 18:14:59 +02:00
antirez
0f55991907 Refactoring: improve luaCreateFunction() API.
The function in its initial form, and after the fixes for the PSYNC2
bugs, required code duplication in multiple spots. This commit modifies
it in order to always compute the script name independently, and to
return the SDS of the SHA of the body: this way it can be used in all
the places, including for SCRIPT LOAD, without duplicating the code to
create the Lua function name. Note that this requires to re-compute the
body SHA1 in the case of EVAL seeing a script for the first time, but
this should not change scripting performance in any way because new
scripts definition is a rare event happening the first time a script is
seen, and the SHA1 computation is anyway not a very slow process against
the typical Redis script and compared to the actua Lua byte compiling of
the body.

Note that the function used to assert() if a duplicated script was
loaded, however actually now two times over three, we want the function
to handle duplicated scripts just fine: this happens in SCRIPT LOAD and
in RDB AUX "lua" loading. Moreover the assert was not defending against
some obvious failure mode, so now the function always tests against
already defined functions at start.
2017-12-04 11:25:20 +01:00
antirez
4492b2f383 Remove useless variable check from luaCreateFunction().
The block is already inside if (allow_dup).
2017-12-04 10:55:54 +01:00
antirez
e44e844751 Fix issue #4505, Lua RDB AUX field loading of existing scripts.
Unfortunately, as outlined by @soloestoy in #4505, "lua" AUX RDB field
loading in case of duplicated script was still broken. This commit fixes
this problem and also a memory leak introduced by the past commit.

Note that now we have a regression test able to duplicate the issue, so
this commit was actually tested against the regression. The original PR
also had a valid fix, but I prefer to hide the details of scripting.c
outside scripting.c, and later "SCRIPT LOAD" should also be able to use
the function luaCreateFunction() instead of redoing the work.
2017-12-04 10:33:04 +01:00
antirez
5ac21dab66 Fix loading of RDB files lua AUX fields when the script is defined.
In the case of slaves loading the RDB from master, or in other similar
cases, the script is already defined, and the function registering the
script should not fail in the assert() call.
2017-12-01 16:01:10 +01:00
antirez
77c4f82b55 PSYNC2: Fix off by one buffer size in luaCreateFunction(). 2017-11-30 18:38:29 +01:00
antirez
4f1b09e79a PSYNC2: just store script bodies into RDB.
Related to #4483. As suggested by @soloestoy, we can retrieve the SHA1
from the body. Given that in the new implementation using AUX fields we
ended copying around a lot to create new objects and strings, extremize
such concept and trade CPU for space inside the RDB file.
2017-11-30 18:38:26 +01:00
antirez
29427aa85c PSYNC2: luaCreateFunction() should handle NULL client parameter.
See #4483. This is needed because luaCreateFunction() is now called
from RDB loading code outside a client context.
2017-11-30 18:37:52 +01:00
Itamar Haber
50ce8124a3 Standardizes the 'help' subcommand
This adds a new `addReplyHelp` helper that's used by commands
when returning a help text. The following commands have been
touched: DEBUG, OBJECT, COMMAND, PUBSUB, SCRIPT and SLOWLOG.

WIP

Fix entry command table entry for OBJECT for HELP option.

After #4472 the command may have just 2 arguments.

Improve OBJECT HELP descriptions.

See #4472.

WIP 2

WIP 3
2017-11-28 21:15:45 +02:00
Yossi Gottlieb
4902e26fef Nested MULTI/EXEC may replicate in different cases.
For example:
1. A module command called within a MULTI section.
2. A Lua script with replicate_commands() called within a MULTI section.
3. A module command called from a Lua script in the above context.
2017-11-22 22:02:51 +02:00
liangsijian
3682597e34 Fix lua ldb command log 2017-07-24 19:24:06 +08:00
antirez
4d519b35f3 Fix abort typo in Lua debugger help screen. 2017-06-30 12:12:00 +02:00
antirez
292e63a2e1 Set lua-time-limit default value at safe place.
Otherwise, as it was, it will overwrite whatever the user set.

Close #3703.
2017-04-11 16:56:00 +02:00
Salvatore Sanfilippo
08e745c5c0 Merge pull request #732 from evilpacket/remove_dofile
Removes dofile() from Lua
2016-05-08 18:04:41 +02:00
antirez
605bcd0f1a Cluster: don't check scripts key slots during AOF loading. 2016-05-05 23:37:08 +02:00
Salvatore Sanfilippo
1907d9b6f5 Merge pull request #2956 from pkulchenko/global-protection-msg-typo
Update global protection error message
2016-05-05 17:26:35 +02:00
antirez
6d82a27995 Fix INFO commandstats reporting when argv is rewritten.
We want to report the original command in the stats, for example GEOADD,
even when what is actually executed is the ZADD implementation.
2016-03-02 08:56:50 +01:00
antirez
9361687f30 Scripting: handle trailing comments.
This fix, provided by Paul Kulchenko (@pkulchenko), allows the Lua
scripting engine to evaluate statements with a trailing comment like the
following one:

    EVAL "print() --comment" 0

Lua can't parse the above if the string does not end with a newline, so
now a final newline is always added automatically. This does not change
the SHA1 of scripts since the SHA1 is computed on the body we pass to
EVAL, without the other code we add to register the function.

Close #2951.
2016-01-08 15:44:21 +01:00
antirez
7449c0d69b Lua debugger: fix crash printing nested or deep objects.
Example of offending code:

> script debug yes
OK
> eval "local a = {1} a[1] = a\nprint(a)" 0
1) * Stopped at 1, stop reason = step over
2) -> 1   local a = {1} a[1] = a
> next
1) * Stopped at 2, stop reason = step over
2) -> 2   print(a)
> print

... server crash ...

Close #2955.
2016-01-08 09:14:13 +01:00
Salvatore Sanfilippo
54aad61ef4 Merge pull request #2954 from pkulchenko/debug-table-pretty-printing
Update pretty printing during debugging to generate valid Lua code for tables
2015-12-22 09:00:36 +01:00
Salvatore Sanfilippo
3fa0ad1201 Merge pull request #2957 from pkulchenko/debug-userdata-pretty-printing
Update pretty printing in debugging to generate valid Lua code for userdata-like types.
2015-12-22 08:59:48 +01:00
antirez
21c3376ef7 Suppress harmless warnings. 2015-12-16 12:36:32 +01:00
Paul Kulchenko
df7810e566 Update pretty printing in debugging to generate valid Lua code for userdata-like types. 2015-12-15 20:24:41 -08:00
Paul Kulchenko
a057e69bdb Update pretty printing in debugging to generate valid Lua code for tables. 2015-12-15 18:15:39 -08:00
Paul Kulchenko
74b63775e2 Update global protection error message to fix a typo. 2015-12-15 18:13:09 -08:00
Itamar Haber
ebaff08613 Revert Lua's redis.LOG_<level> to original
Fixes #2898
2015-11-27 15:55:38 +02:00
antirez
ba7f378da0 Lua debugger: infinite loop detection. 2015-11-18 10:23:49 +01:00
antirez
4ab3cff9be Lua debugger: fix trace command infinite loop.
Thanks to Itamar Haber for bug report and test case to reproduce.
2015-11-17 16:24:27 +01:00
antirez
57f51983b1 Lua debugger: maxlen command implemented.
Let the user control the replies truncation.
2015-11-17 15:43:24 +01:00
antirez
06db360f1d Lua debugger: trace command implemented. 2015-11-17 15:43:24 +01:00
antirez
7b71a14380 Lua debugger: print without args show all local vars. 2015-11-17 15:43:23 +01:00
antirez
c0a0e2c26f Lua debugger: default behavior of "list" command changed.
Now it lists code around the current position by default. Can list any
other part using other arguments, but a new "whole" command was added in
order to show the whole source code easily.
2015-11-17 15:43:23 +01:00
antirez
ab792f66b0 Lua debugging: fix error message for SCRIPT DEBUG.
"async" -> "sync".

Thanks to Itamar Haber for reporting.
2015-11-17 15:43:23 +01:00
antirez
030f64f5f6 Lua debugger: reply +OK to SCRIPT DEBUG no.
Thanks to Itamar Haber for reporting.
2015-11-17 15:43:23 +01:00
antirez
76fd26e778 Lua debugger: call wait3() if there are pending forked debugging sessions. 2015-11-17 15:43:23 +01:00
antirez
d18ba0a14b Lua debugger: abort implemented. 2015-11-17 15:43:23 +01:00
antirez
be3d13cb1c Lua debugger: ldbSendLogs() memory leak fixed. 2015-11-17 15:43:23 +01:00
antirez
2f64b9d5d8 Lua debugger: better support for synchronous mode. 2015-11-17 15:43:22 +01:00
antirez
5c05038252 Lua debugger: handle forked sessions children during shutdown. 2015-11-17 15:43:22 +01:00
antirez
42aa5b768a Lua debugger: fix help typo, beark -> break. 2015-11-17 15:43:22 +01:00
antirez
b2e30575e2 Lua debugger: clear end of session protocol.
When the debugger exits now it produces an <endsession> tag that informs
redis-cli (or other debugging clients) that the session terminated.
This way the client knows there is yet another reply to read (the one of
the EVAL script itself), and can switch to non-debugging mode ASAP.
2015-11-17 15:43:22 +01:00
antirez
bbb8a712c7 Lua debugger: redis.debug() implemented. 2015-11-17 15:43:22 +01:00
antirez
eff4ea27a7 Lua debugger: removing breakpoints now works. 2015-11-17 15:43:22 +01:00
antirez
63acf80344 Lua debugger: redis command implemented. 2015-11-17 15:43:22 +01:00
antirez
5b43ff2e5b Lua debugger: try to eval as expression first.
It's handly to just eval "5+5" without the return and see it printed on
the screen as result. However prepending "return" does not always result
into valid Lua code. So what we do is to exploit a common Lua community
trick of trying to compile with return prepended, and if compilation
fails then it's not an expression that can be returned, so we try again
without prepending "return". Works great apparently.
2015-11-17 15:43:21 +01:00
antirez
02e8af90fb Lua debugger: much better Lua values pretty printer. 2015-11-17 15:43:21 +01:00
antirez
40e8b39bbb Lua debugger: print now handles ARGV and KEYS. 2015-11-17 15:43:21 +01:00
antirez
84d6160eb8 Lua debugger: added comment about helper functions. 2015-11-17 15:43:21 +01:00
antirez
717d6de03f Lua debugger: redis.breakpoint() implemented. 2015-11-17 15:43:21 +01:00