Unverified Commit 6b297cd6 authored by Oran Agra's avatar Oran Agra Committed by GitHub
Browse files

Improve errno reporting on fork and fopen rdbLoad failures (#9649)

I moved a bunch of stats in redisFork to be executed only on successful
fork, since they seem wrong to be done when it failed.
I guess when fork fails it does that immediately, no latency spike.
parent 48e4d770
...@@ -3110,7 +3110,6 @@ int rdbSaveToSlavesSockets(rdbSaveInfo *rsi) { ...@@ -3110,7 +3110,6 @@ int rdbSaveToSlavesSockets(rdbSaveInfo *rsi) {
exitFromChild((retval == C_OK) ? 0 : 1); exitFromChild((retval == C_OK) ? 0 : 1);
} else { } else {
/* Parent */ /* Parent */
close(safe_to_exit_pipe);
if (childpid == -1) { if (childpid == -1) {
serverLog(LL_WARNING,"Can't save in background: fork: %s", serverLog(LL_WARNING,"Can't save in background: fork: %s",
strerror(errno)); strerror(errno));
...@@ -3141,6 +3140,7 @@ int rdbSaveToSlavesSockets(rdbSaveInfo *rsi) { ...@@ -3141,6 +3140,7 @@ int rdbSaveToSlavesSockets(rdbSaveInfo *rsi) {
serverPanic("Unrecoverable error creating server.rdb_pipe_read file event."); serverPanic("Unrecoverable error creating server.rdb_pipe_read file event.");
} }
} }
close(safe_to_exit_pipe);
return (childpid == -1) ? C_ERR : C_OK; return (childpid == -1) ? C_ERR : C_OK;
} }
return C_OK; /* Unreached. */ return C_OK; /* Unreached. */
......
...@@ -1859,7 +1859,7 @@ void readSyncBulkPayload(connection *conn) { ...@@ -1859,7 +1859,7 @@ void readSyncBulkPayload(connection *conn) {
if (rdbLoad(server.rdb_filename,&rsi,RDBFLAGS_REPLICATION) != C_OK) { if (rdbLoad(server.rdb_filename,&rsi,RDBFLAGS_REPLICATION) != C_OK) {
serverLog(LL_WARNING, serverLog(LL_WARNING,
"Failed trying to load the MASTER synchronization " "Failed trying to load the MASTER synchronization "
"DB from disk"); "DB from disk: %s", strerror(errno));
cancelReplicationHandshake(1); cancelReplicationHandshake(1);
if (server.rdb_del_sync_files && allPersistenceDisabled()) { if (server.rdb_del_sync_files && allPersistenceDisabled()) {
serverLog(LL_NOTICE,"Removing the RDB file obtained from " serverLog(LL_NOTICE,"Removing the RDB file obtained from "
......
...@@ -2164,7 +2164,7 @@ int ldbStartSession(client *c) { ...@@ -2164,7 +2164,7 @@ int ldbStartSession(client *c) {
if (ldb.forked) { if (ldb.forked) {
pid_t cp = redisFork(CHILD_TYPE_LDB); pid_t cp = redisFork(CHILD_TYPE_LDB);
if (cp == -1) { if (cp == -1) {
addReplyError(c,"Fork() failed: can't run EVAL in debugging mode."); addReplyErrorFormat(c,"Fork() failed: can't run EVAL in debugging mode: %s", strerror(errno));
return 0; return 0;
} else if (cp == 0) { } else if (cp == 0) {
/* Child. Let's ignore important signals handled by the parent. */ /* Child. Let's ignore important signals handled by the parent. */
......
...@@ -7405,15 +7405,18 @@ int redisFork(int purpose) { ...@@ -7405,15 +7405,18 @@ int redisFork(int purpose) {
closeChildUnusedResourceAfterFork(); closeChildUnusedResourceAfterFork();
} else { } else {
/* Parent */ /* Parent */
server.stat_total_forks++;
server.stat_fork_time = ustime()-start;
server.stat_fork_rate = (double) zmalloc_used_memory() * 1000000 / server.stat_fork_time / (1024*1024*1024); /* GB per second. */
latencyAddSampleIfNeeded("fork",server.stat_fork_time/1000);
if (childpid == -1) { if (childpid == -1) {
int fork_errno = errno;
if (isMutuallyExclusiveChildType(purpose)) closeChildInfoPipe(); if (isMutuallyExclusiveChildType(purpose)) closeChildInfoPipe();
errno = fork_errno;
return -1; return -1;
} }
server.stat_total_forks++;
server.stat_fork_time = ustime()-start;
server.stat_fork_rate = (double) zmalloc_used_memory() * 1000000 / server.stat_fork_time / (1024*1024*1024); /* GB per second. */
latencyAddSampleIfNeeded("fork",server.stat_fork_time/1000);
/* The child_pid and child_type are only for mutual exclusive children. /* The child_pid and child_type are only for mutual exclusive children.
* other child types should handle and store their pid's in dedicated variables. * other child types should handle and store their pid's in dedicated variables.
* *
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment