Unverified Commit 4505eb18 authored by Binbin's avatar Binbin Committed by GitHub
Browse files

errno cleanup around rdbLoad (#11042)

This is an addition to #11039, which cleans up rdbLoad* related errno. Remove the
errno print from the outer message (may be invalid since errno may have been overwritten).

Our aim should be the code that detects the error and knows which system call
triggered it, is the one to print errno, and not the code way up above (in some cases
a result of a logical error and not a system one).

Remove the code to update errno in rdbLoadRioWithLoadingCtx, signature check
and the rdb version check, in these cases, we do print the error message.
The caller dose not have the specific logic for handling EINVAL.

Small fix around rdb-preamble AOF: A truncated RDB is considered a failure,
not handled the same as a truncated AOF file.
parent 6686c6d7
...@@ -1432,7 +1432,8 @@ int loadSingleAppendOnlyFile(char *filename) { ...@@ -1432,7 +1432,8 @@ int loadSingleAppendOnlyFile(char *filename) {
else else
serverLog(LL_WARNING, "Error reading the RDB base file %s, AOF loading aborted", filename); serverLog(LL_WARNING, "Error reading the RDB base file %s, AOF loading aborted", filename);
goto readerr; ret = AOF_FAILED;
goto cleanup;
} else { } else {
loadingAbsProgress(ftello(fp)); loadingAbsProgress(ftello(fp));
last_progress_report_size = ftello(fp); last_progress_report_size = ftello(fp);
......
...@@ -568,7 +568,7 @@ NULL ...@@ -568,7 +568,7 @@ NULL
int ret = rdbLoad(server.rdb_filename,NULL,flags); int ret = rdbLoad(server.rdb_filename,NULL,flags);
unprotectClient(c); unprotectClient(c);
if (ret != RDB_OK) { if (ret != RDB_OK) {
addReplyError(c,"Error trying to load the RDB dump"); addReplyError(c,"Error trying to load the RDB dump, check server logs.");
return; return;
} }
serverLog(LL_WARNING,"DB reloaded by DEBUG RELOAD"); serverLog(LL_WARNING,"DB reloaded by DEBUG RELOAD");
......
...@@ -2889,7 +2889,7 @@ int rdbLoadRio(rio *rdb, int rdbflags, rdbSaveInfo *rsi) { ...@@ -2889,7 +2889,7 @@ int rdbLoadRio(rio *rdb, int rdbflags, rdbSaveInfo *rsi) {
/* Load an RDB file from the rio stream 'rdb'. On success C_OK is returned, /* Load an RDB file from the rio stream 'rdb'. On success C_OK is returned,
* otherwise C_ERR is returned and 'errno' is set accordingly. * otherwise C_ERR is returned.
* The rdb_loading_ctx argument holds objects to which the rdb will be loaded to, * The rdb_loading_ctx argument holds objects to which the rdb will be loaded to,
* currently it only allow to set db object and functionLibCtx to which the data * currently it only allow to set db object and functionLibCtx to which the data
* will be loaded (in the future it might contains more such objects). */ * will be loaded (in the future it might contains more such objects). */
...@@ -2907,13 +2907,11 @@ int rdbLoadRioWithLoadingCtx(rio *rdb, int rdbflags, rdbSaveInfo *rsi, rdbLoadin ...@@ -2907,13 +2907,11 @@ int rdbLoadRioWithLoadingCtx(rio *rdb, int rdbflags, rdbSaveInfo *rsi, rdbLoadin
buf[9] = '\0'; buf[9] = '\0';
if (memcmp(buf,"REDIS",5) != 0) { if (memcmp(buf,"REDIS",5) != 0) {
serverLog(LL_WARNING,"Wrong signature trying to load DB from file"); serverLog(LL_WARNING,"Wrong signature trying to load DB from file");
errno = EINVAL;
return C_ERR; return C_ERR;
} }
rdbver = atoi(buf+5); rdbver = atoi(buf+5);
if (rdbver < 1 || rdbver > RDB_VERSION) { if (rdbver < 1 || rdbver > RDB_VERSION) {
serverLog(LL_WARNING,"Can't handle RDB format version %d",rdbver); serverLog(LL_WARNING,"Can't handle RDB format version %d",rdbver);
errno = EINVAL;
return C_ERR; return C_ERR;
} }
...@@ -3254,9 +3252,10 @@ int rdbLoad(char *filename, rdbSaveInfo *rsi, int rdbflags) { ...@@ -3254,9 +3252,10 @@ int rdbLoad(char *filename, rdbSaveInfo *rsi, int rdbflags) {
fp = fopen(filename, "r"); fp = fopen(filename, "r");
if (fp == NULL) { if (fp == NULL) {
retval = (errno == ENOENT) ? RDB_NOT_EXIST : RDB_FAILED; if (errno == ENOENT) return RDB_NOT_EXIST;
serverLog(LL_WARNING,"Fatal error: can't open the RDB file %s for reading: %s", filename, strerror(errno)); serverLog(LL_WARNING,"Fatal error: can't open the RDB file %s for reading: %s", filename, strerror(errno));
return retval; return RDB_FAILED;
} }
if (fstat(fileno(fp), &sb) == -1) if (fstat(fileno(fp), &sb) == -1)
......
...@@ -2055,7 +2055,7 @@ void readSyncBulkPayload(connection *conn) { ...@@ -2055,7 +2055,7 @@ void readSyncBulkPayload(connection *conn) {
/* RDB loading failed. */ /* RDB loading failed. */
serverLog(LL_WARNING, serverLog(LL_WARNING,
"Failed trying to load the MASTER synchronization DB " "Failed trying to load the MASTER synchronization DB "
"from socket: %s", strerror(errno)); "from socket, check server logs.");
loadingFailed = 1; loadingFailed = 1;
} else if (usemark) { } else if (usemark) {
/* Verify the end mark is correct. */ /* Verify the end mark is correct. */
...@@ -2164,7 +2164,7 @@ void readSyncBulkPayload(connection *conn) { ...@@ -2164,7 +2164,7 @@ void readSyncBulkPayload(connection *conn) {
if (rdbLoad(server.rdb_filename,&rsi,RDBFLAGS_REPLICATION) != RDB_OK) { if (rdbLoad(server.rdb_filename,&rsi,RDBFLAGS_REPLICATION) != RDB_OK) {
serverLog(LL_WARNING, serverLog(LL_WARNING,
"Failed trying to load the MASTER synchronization " "Failed trying to load the MASTER synchronization "
"DB from disk: %s", strerror(errno)); "DB from disk, check server logs.");
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 "
......
...@@ -6551,7 +6551,7 @@ void loadDataFromDisk(void) { ...@@ -6551,7 +6551,7 @@ void loadDataFromDisk(void) {
} }
} }
} else if (rdb_load_ret != RDB_NOT_EXIST) { } else if (rdb_load_ret != RDB_NOT_EXIST) {
serverLog(LL_WARNING,"Fatal error loading the DB: %s. Exiting.",strerror(errno)); serverLog(LL_WARNING, "Fatal error loading the DB, check server logs. Exiting.");
exit(1); exit(1);
} }
......
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