Skip to content

Commit

Permalink
change error message for aox-max-size exceeding
Browse files Browse the repository at this point in the history
Signed-off-by: kronwerk <[email protected]>
  • Loading branch information
kronwerk committed Jan 27, 2025
1 parent dc010a3 commit d6cafa1
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/aof.c
Original file line number Diff line number Diff line change
Expand Up @@ -1012,12 +1012,12 @@ int startAppendOnly(void) {
* is likely to fail. However apparently in modern systems this is no longer
* true, and in general it looks just more resilient to retry the write. If
* there is an actual error condition we'll get it at the next try.
* We also check for aof-max-size limit here returning "no space" on exceed. */
* We also check for aof-max-size limit here returning custom error on exceed. */
ssize_t aofWrite(int fd, const char *buf, size_t len, off_t aof_current_size, unsigned long long aof_max_size) {
ssize_t nwritten = 0, totwritten = 0, nonewritten = -1;

if (aof_max_size && (unsigned long long)aof_current_size >= aof_max_size) {
errno = ENOSPC;
errno = EFBIG;
return nonewritten;
}

Expand Down Expand Up @@ -1158,7 +1158,7 @@ void flushAppendOnlyFile(int force) {
/* Log the AOF write error and record the error code. */
if (nwritten == -1) {
if (can_log) {
serverLog(LL_WARNING, "Error writing to the AOF file: %s", strerror(errno));
serverLog(LL_WARNING, "Error writing to the AOF file: %s", getAofWriteErrStr(errno));
}
server.aof_last_write_errno = errno;
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/script.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ int scriptPrepareForRun(scriptRunCtx *run_ctx,
"Writable scripts are blocked. Use 'no-writes' flag for read only scripts. "
"AOF error: %s",
server.extended_redis_compat ? "Redis" : SERVER_TITLE,
strerror(server.aof_last_write_errno));
getAofWriteErrStr(server.aof_last_write_errno));
return C_ERR;
}

Expand Down
6 changes: 5 additions & 1 deletion src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -4627,13 +4627,17 @@ int writeCommandsDeniedByDiskError(void) {
return DISK_ERROR_TYPE_NONE;
}

char* getAofWriteErrStr(int error_code) {
return (errno == EFBIG) ? "Reached aof-max-size" : strerror(error_code);
}

sds writeCommandsGetDiskErrorMessage(int error_code) {
sds ret = NULL;
if (error_code == DISK_ERROR_TYPE_RDB) {
ret = sdsdup(shared.bgsaveerr->ptr);
} else {
ret = sdscatfmt(sdsempty(), "-MISCONF Errors writing to the AOF file: %s\r\n",
strerror(server.aof_last_write_errno));
getAofWriteErrStr(server.aof_last_write_errno));
}
return ret;
}
Expand Down
1 change: 1 addition & 0 deletions src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -2965,6 +2965,7 @@ int allPersistenceDisabled(void);
#define DISK_ERROR_TYPE_RDB 2 /* Don't accept writes: RDB errors. */
#define DISK_ERROR_TYPE_NONE 0 /* No problems, we can accept writes. */
int writeCommandsDeniedByDiskError(void);
char* getAofWriteErrStr(int);
sds writeCommandsGetDiskErrorMessage(int);

/* RDB persistence */
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/aof-max-size.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ start_server {tags {"external:skip"}} {
set master_host [srv 0 host]
set master_port [srv 0 port]

test "Low aof-max-size stops writing AOF with ENOSPC" {
test "Low aof-max-size stops writing AOF with EFBIG" {
setup
wait_for_log_messages 0 {"*Error writing to the AOF file: No space left on device*"} 0 100 10
wait_for_log_messages 0 {"*Error writing to the AOF file: Reached aof-max-size*"} 0 100 10
cleanup
}

Expand All @@ -29,7 +29,7 @@ start_server {tags {"external:skip"}} {
set len1 [getInfoProperty $info1 aof_buffer_length]

catch {r set somelongerkey somelongrvalue} err
assert {$err eq "MISCONF Errors writing to the AOF file: No space left on device"}
assert {$err eq "MISCONF Errors writing to the AOF file: Reached aof-max-size"}
assert_equal [r get somelongerkey] ""

set info2 [r info]
Expand Down

0 comments on commit d6cafa1

Please sign in to comment.