Refactoring: replace low-level checks with writeCommandsDeniedByDiskError().

This commit is contained in:
antirez 2018-07-31 13:16:43 +02:00
parent 11dd3f4b03
commit db693be00d
2 changed files with 6 additions and 13 deletions

View File

@ -483,6 +483,7 @@ int luaRedisGenericCommand(lua_State *lua, int raise_error) {
* command marked as non-deterministic was already called in the context * command marked as non-deterministic was already called in the context
* of this script. */ * of this script. */
if (cmd->flags & CMD_WRITE) { if (cmd->flags & CMD_WRITE) {
int deny_write_type = writeCommandsDeniedByDiskError();
if (server.lua_random_dirty && !server.lua_replicate_commands) { if (server.lua_random_dirty && !server.lua_replicate_commands) {
luaPushError(lua, 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."); "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); luaPushError(lua, shared.roslaveerr->ptr);
goto cleanup; goto cleanup;
} else if ((server.stop_writes_on_bgsave_err && } else if (deny_write_type != DISK_ERROR_TYPE_NONE) {
server.saveparamslen > 0 && if (deny_write_type == DISK_ERROR_TYPE_RDB) {
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) {
luaPushError(lua, shared.bgsaveerr->ptr); luaPushError(lua, shared.bgsaveerr->ptr);
} else { } else {
sds aof_write_err = sdscatfmt(sdsempty(), sds aof_write_err = sdscatfmt(sdsempty(),

View File

@ -2609,17 +2609,14 @@ int processCommand(client *c) {
/* Don't accept write commands if there are problems persisting on disk /* Don't accept write commands if there are problems persisting on disk
* and if this is a master instance. */ * and if this is a master instance. */
if (((server.stop_writes_on_bgsave_err && int deny_write_type = writeCommandsDeniedByDiskError();
server.saveparamslen > 0 && if (deny_write_type != DISK_ERROR_TYPE_NONE &&
server.lastbgsave_status == C_ERR) ||
(server.aof_state != AOF_OFF &&
server.aof_last_write_status == C_ERR)) &&
server.masterhost == NULL && server.masterhost == NULL &&
(c->cmd->flags & CMD_WRITE || (c->cmd->flags & CMD_WRITE ||
c->cmd->proc == pingCommand)) c->cmd->proc == pingCommand))
{ {
flagTransaction(c); flagTransaction(c);
if (server.aof_last_write_status == C_OK) if (deny_write_type == DISK_ERROR_TYPE_RDB)
addReply(c, shared.bgsaveerr); addReply(c, shared.bgsaveerr);
else else
addReplySds(c, addReplySds(c,