diff options
author | yoav-steinberg <yoav@monfort.co.il> | 2022-01-24 16:50:02 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-24 16:50:02 +0200 |
commit | 7eadc5ee7062c6de00323c1b8a9598d1b5684217 (patch) | |
tree | 5c0286bb7bd3f8689f2a346f389f006e64e3477e /src/commands | |
parent | 857dc5bacd85a9a4c31b7ef9eb350690ca0a85ad (diff) | |
download | redis-7eadc5ee7062c6de00323c1b8a9598d1b5684217.tar.gz |
Support function flags in script EVAL via shebang header (#10126)
In #10025 we added a mechanism for flagging certain properties for Redis Functions.
This lead us to think we'd like to "port" this mechanism to Redis Scripts (`EVAL`) as well.
One good reason for this, other than the added functionality is because it addresses the
poor behavior we currently have in `EVAL` in case the script performs a (non DENY_OOM) write operation
during OOM state. See #8478 (And a previous attempt to handle it via #10093) for details.
Note that in Redis Functions **all** write operations (including DEL) will return an error during OOM state
unless the function is flagged as `allow-oom` in which case no OOM checking is performed at all.
This PR:
- Enables setting `EVAL` (and `SCRIPT LOAD`) script flags as defined in #10025.
- Provides a syntactical framework via [shebang](https://en.wikipedia.org/wiki/Shebang_(Unix)) for
additional script annotations and even engine selection (instead of just lua) for scripts.
- Provides backwards compatibility so scripts without the new annotations will behave as they did before.
- Appropriate tests.
- Changes `EVAL[SHA]/_RO` to be flagged as `STALE` commands. This makes it possible to flag individual
scripts as `allow-stale` or not flag them as such. In backwards compatibility mode these commands will
return the `MASTERDOWN` error as before.
- Changes `SCRIPT LOAD` to be flagged as a `STALE` command. This is mainly to make it logically
compatible with the change to `EVAL` in the previous point. It enables loading a script on a stale server
which is technically okay it doesn't relate directly to the server's dataset. Running the script does, but that
won't work unless the script is explicitly marked as `allow-stale`.
Note that even though the LUA syntax doesn't support hash tag comments `.lua` files do support a shebang
tag on the top so they can be executed on Unix systems like any shell script. LUA's `luaL_loadfile` handles
this as part of the LUA library. In the case of `luaL_loadbuffer`, which is what Redis uses, I needed to fix the
input script in case of a shebang manually. I did this the same way `luaL_loadfile` does, by replacing the
first line with a single line feed character.
Diffstat (limited to 'src/commands')
-rw-r--r-- | src/commands/eval.json | 3 | ||||
-rw-r--r-- | src/commands/eval_ro.json | 3 | ||||
-rw-r--r-- | src/commands/evalsha.json | 3 | ||||
-rw-r--r-- | src/commands/evalsha_ro.json | 3 | ||||
-rw-r--r-- | src/commands/script-load.json | 3 |
5 files changed, 10 insertions, 5 deletions
diff --git a/src/commands/eval.json b/src/commands/eval.json index cbd79bc87..673722cf5 100644 --- a/src/commands/eval.json +++ b/src/commands/eval.json @@ -11,7 +11,8 @@ "NOSCRIPT", "SKIP_MONITOR", "MAY_REPLICATE", - "NO_MANDATORY_KEYS" + "NO_MANDATORY_KEYS", + "STALE" ], "acl_categories": [ "SCRIPTING" diff --git a/src/commands/eval_ro.json b/src/commands/eval_ro.json index 75e717b3e..58b744591 100644 --- a/src/commands/eval_ro.json +++ b/src/commands/eval_ro.json @@ -10,7 +10,8 @@ "command_flags": [ "NOSCRIPT", "SKIP_MONITOR", - "NO_MANDATORY_KEYS" + "NO_MANDATORY_KEYS", + "STALE" ], "acl_categories": [ "SCRIPTING" diff --git a/src/commands/evalsha.json b/src/commands/evalsha.json index 50646858d..9b68b87f1 100644 --- a/src/commands/evalsha.json +++ b/src/commands/evalsha.json @@ -11,7 +11,8 @@ "NOSCRIPT", "SKIP_MONITOR", "MAY_REPLICATE", - "NO_MANDATORY_KEYS" + "NO_MANDATORY_KEYS", + "STALE" ], "acl_categories": [ "SCRIPTING" diff --git a/src/commands/evalsha_ro.json b/src/commands/evalsha_ro.json index ab47e4773..d876c5d76 100644 --- a/src/commands/evalsha_ro.json +++ b/src/commands/evalsha_ro.json @@ -10,7 +10,8 @@ "command_flags": [ "NOSCRIPT", "SKIP_MONITOR", - "NO_MANDATORY_KEYS" + "NO_MANDATORY_KEYS", + "STALE" ], "acl_categories": [ "SCRIPTING" diff --git a/src/commands/script-load.json b/src/commands/script-load.json index 0a19c9193..b0b4e67e5 100644 --- a/src/commands/script-load.json +++ b/src/commands/script-load.json @@ -8,7 +8,8 @@ "container": "SCRIPT", "function": "scriptCommand", "command_flags": [ - "NOSCRIPT" + "NOSCRIPT", + "STALE" ], "acl_categories": [ "SCRIPTING" |