summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2018-07-31 13:16:43 +0200
committerantirez <antirez@gmail.com>2018-07-31 13:16:43 +0200
commitdb693be00d4debc474cb52e471a9a4c91e6f263e (patch)
treec761943a6a008412f062a96851f74ea065020869
parent11dd3f4b034566259b2f81484619975928963a89 (diff)
downloadredis-db693be00d4debc474cb52e471a9a4c91e6f263e.tar.gz
Refactoring: replace low-level checks with writeCommandsDeniedByDiskError().
-rw-r--r--src/scripting.c10
-rw-r--r--src/server.c9
2 files changed, 6 insertions, 13 deletions
diff --git a/src/scripting.c b/src/scripting.c
index b046ea1ff..2732c87fb 100644
--- a/src/scripting.c
+++ b/src/scripting.c
@@ -483,6 +483,7 @@ int luaRedisGenericCommand(lua_State *lua, int raise_error) {
* command marked as non-deterministic was already called in the context
* of this script. */
if (cmd->flags & CMD_WRITE) {
+ int deny_write_type = writeCommandsDeniedByDiskError();
if (server.lua_random_dirty && !server.lua_replicate_commands) {
luaPushError(lua,
"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.");
@@ -493,13 +494,8 @@ int luaRedisGenericCommand(lua_State *lua, int raise_error) {
{
luaPushError(lua, shared.roslaveerr->ptr);
goto cleanup;
- } else if ((server.stop_writes_on_bgsave_err &&
- server.saveparamslen > 0 &&
- server.lastbgsave_status == C_ERR) ||
- (server.aof_state != AOF_OFF &&
- server.aof_last_write_status == C_ERR))
- {
- if (server.aof_last_write_status == C_OK) {
+ } else if (deny_write_type != DISK_ERROR_TYPE_NONE) {
+ if (deny_write_type == DISK_ERROR_TYPE_RDB) {
luaPushError(lua, shared.bgsaveerr->ptr);
} else {
sds aof_write_err = sdscatfmt(sdsempty(),
diff --git a/src/server.c b/src/server.c
index 28750ab72..66d42ee6c 100644
--- a/src/server.c
+++ b/src/server.c
@@ -2609,17 +2609,14 @@ int processCommand(client *c) {
/* Don't accept write commands if there are problems persisting on disk
* and if this is a master instance. */
- if (((server.stop_writes_on_bgsave_err &&
- server.saveparamslen > 0 &&
- server.lastbgsave_status == C_ERR) ||
- (server.aof_state != AOF_OFF &&
- server.aof_last_write_status == C_ERR)) &&
+ int deny_write_type = writeCommandsDeniedByDiskError();
+ if (deny_write_type != DISK_ERROR_TYPE_NONE &&
server.masterhost == NULL &&
(c->cmd->flags & CMD_WRITE ||
c->cmd->proc == pingCommand))
{
flagTransaction(c);
- if (server.aof_last_write_status == C_OK)
+ if (deny_write_type == DISK_ERROR_TYPE_RDB)
addReply(c, shared.bgsaveerr);
else
addReplySds(c,