summaryrefslogtreecommitdiff
path: root/src/script.c
diff options
context:
space:
mode:
authorzhugezy <44550833+zhugezy@users.noreply.github.com>2021-12-21 14:32:42 +0800
committerGitHub <noreply@github.com>2021-12-21 08:32:42 +0200
commit1b0968df46f9f838e7daa540675b29073a00cf30 (patch)
treed0bf1e2b5c6e3566dfe8486963e7b55f4ce8431a /src/script.c
parentfebc3f63b2b57afe3553b22c69c3ce27b5a3e842 (diff)
downloadredis-1b0968df46f9f838e7daa540675b29073a00cf30.tar.gz
Remove EVAL script verbatim replication, propagation, and deterministic execution logic (#9812)
# Background The main goal of this PR is to remove relevant logics on Lua script verbatim replication, only keeping effects replication logic, which has been set as default since Redis 5.0. As a result, Lua in Redis 7.0 would be acting the same as Redis 6.0 with default configuration from users' point of view. There are lots of reasons to remove verbatim replication. Antirez has listed some of the benefits in Issue #5292: >1. No longer need to explain to users side effects into scripts. They can do whatever they want. >2. No need for a cache about scripts that we sent or not to the slaves. >3. No need to sort the output of certain commands inside scripts (SMEMBERS and others): this both simplifies and gains speed. >4. No need to store scripts inside the RDB file in order to startup correctly. >5. No problems about evicting keys during the script execution. When looking back at Redis 5.0, antirez and core team decided to set the config `lua-replicate-commands yes` by default instead of removing verbatim replication directly, in case some bad situations happened. 3 years later now before Redis 7.0, it's time to remove it formally. # Changes - configuration for lua-replicate-commands removed - created config file stub for backward compatibility - Replication script cache removed - this is useless under script effects replication - relevant statistics also removed - script persistence in RDB files is also removed - Propagation of SCRIPT LOAD and SCRIPT FLUSH to replica / AOF removed - Deterministic execution logic in scripts removed (i.e. don't run write commands after random ones, and sorting output of commands with random order) - the flags indicating which commands have non-deterministic results are kept as hints to clients. - `redis.replicate_commands()` & `redis.set_repl()` changed - now `redis.replicate_commands()` does nothing and return an 1 - ...and then `redis.set_repl()` can be issued before `redis.replicate_commands()` now - Relevant TCL cases adjusted - DEBUG lua-always-replicate-commands removed # Other changes - Fix a recent bug comparing CLIENT_ID_AOF to original_client->flags instead of id. (introduced in #9780) Co-authored-by: Oran Agra <oran@redislabs.com>
Diffstat (limited to 'src/script.c')
-rw-r--r--src/script.c36
1 files changed, 11 insertions, 25 deletions
diff --git a/src/script.c b/src/script.c
index 34e4953d3..fdafadae8 100644
--- a/src/script.c
+++ b/src/script.c
@@ -148,11 +148,10 @@ void scriptResetRun(scriptRunCtx *run_ctx) {
unprotectClient(run_ctx->original_client);
}
- if (!(run_ctx->flags & SCRIPT_EVAL_REPLICATION)) {
- preventCommandPropagation(run_ctx->original_client);
- if (run_ctx->flags & SCRIPT_MULTI_EMMITED) {
- execCommandPropagateExec(run_ctx->original_client->db->id);
- }
+ /* emit EXEC if MULTI has been propagated. */
+ preventCommandPropagation(run_ctx->original_client);
+ if (run_ctx->flags & SCRIPT_MULTI_EMMITED) {
+ execCommandPropagateExec(run_ctx->original_client->db->id);
}
/* unset curr_run_ctx so we will know there is no running script */
@@ -258,17 +257,12 @@ static int scriptVerifyWriteCommandAllow(scriptRunCtx *run_ctx, char **err) {
return C_ERR;
}
- if ((run_ctx->flags & SCRIPT_RANDOM_DIRTY) && (run_ctx->flags & SCRIPT_EVAL_REPLICATION)) {
- *err = sdsnew("Write commands not allowed after non deterministic commands. Call redis.replicate_commands() at the start of your script in order to switch to single commands replication mode.");
- return C_ERR;
- }
-
/* Write commands are forbidden against read-only slaves, or if a
* command marked as non-deterministic was already called in the context
* of this script. */
int deny_write_type = writeCommandsDeniedByDiskError();
- if (server.masterhost && server.repl_slave_ro && run_ctx->original_client->flags != CLIENT_ID_AOF
+ if (server.masterhost && server.repl_slave_ro && run_ctx->original_client->id != CLIENT_ID_AOF
&& !(run_ctx->original_client->flags & CLIENT_MASTER))
{
*err = sdsdup(shared.roslaveerr->ptr);
@@ -343,8 +337,7 @@ static void scriptEmitMultiIfNeeded(scriptRunCtx *run_ctx) {
* we propagate into a MULTI/EXEC block, so that it will be atomic like
* a Lua script in the context of AOF and slaves. */
client *c = run_ctx->c;
- if (!(run_ctx->flags & SCRIPT_EVAL_REPLICATION)
- && !(run_ctx->flags & SCRIPT_MULTI_EMMITED)
+ if (!(run_ctx->flags & SCRIPT_MULTI_EMMITED)
&& !(run_ctx->original_client->flags & CLIENT_MULTI)
&& (run_ctx->flags & SCRIPT_WRITE_DIRTY)
&& ((run_ctx->repl_flags & PROPAGATE_AOF)
@@ -426,11 +419,6 @@ void scriptCall(scriptRunCtx *run_ctx, robj* *argv, int argc, sds *err) {
run_ctx->flags |= SCRIPT_WRITE_DIRTY;
}
- if (cmd->flags & CMD_RANDOM) {
- /* signify that we already perform a random command in this execution */
- run_ctx->flags |= SCRIPT_RANDOM_DIRTY;
- }
-
if (scriptVerifyClusterState(c, run_ctx->original_client, err) != C_OK) {
return;
}
@@ -438,13 +426,11 @@ void scriptCall(scriptRunCtx *run_ctx, robj* *argv, int argc, sds *err) {
scriptEmitMultiIfNeeded(run_ctx);
int call_flags = CMD_CALL_SLOWLOG | CMD_CALL_STATS;
- if (!(run_ctx->flags & SCRIPT_EVAL_REPLICATION)) {
- if (run_ctx->repl_flags & PROPAGATE_AOF) {
- call_flags |= CMD_CALL_PROPAGATE_AOF;
- }
- if (run_ctx->repl_flags & PROPAGATE_REPL) {
- call_flags |= CMD_CALL_PROPAGATE_REPL;
- }
+ if (run_ctx->repl_flags & PROPAGATE_AOF) {
+ call_flags |= CMD_CALL_PROPAGATE_AOF;
+ }
+ if (run_ctx->repl_flags & PROPAGATE_REPL) {
+ call_flags |= CMD_CALL_PROPAGATE_REPL;
}
call(c, call_flags);
serverAssert((c->flags & CLIENT_BLOCKED) == 0);