diff options
author | antirez <antirez@gmail.com> | 2014-09-05 11:48:35 +0200 |
---|---|---|
committer | antirez <antirez@gmail.com> | 2014-09-08 10:57:57 +0200 |
commit | 683cf5b8721dae7ebb4aea17fda9ad2df0d919e9 (patch) | |
tree | cea79a483cbf5b776da488e63b3753f75c271e2b /src/aof.c | |
parent | 94f79794147e60d943a4e60d21f30f0502078167 (diff) | |
download | redis-683cf5b8721dae7ebb4aea17fda9ad2df0d919e9.tar.gz |
AOF ability to load truncated files.
Diffstat (limited to 'src/aof.c')
-rw-r--r-- | src/aof.c | 14 |
1 files changed, 11 insertions, 3 deletions
@@ -590,6 +590,7 @@ int loadAppendOnlyFile(char *filename) { goto readerr; } if (buf[0] != '*') goto fmterr; + if (buf[1] == '\0') goto readerr; argc = atoi(buf+1); if (argc < 1) goto fmterr; @@ -599,7 +600,7 @@ int loadAppendOnlyFile(char *filename) { if (buf[0] != '$') goto fmterr; len = strtol(buf+1,NULL,10); argsds = sdsnewlen(NULL,len); - if (len && fread(argsds,len,1,fp) == 0) goto fmterr; + if (len && fread(argsds,len,1,fp) == 0) goto readerr; argv[j] = createObject(REDIS_STRING,argsds); if (fread(buf,2,1,fp) == 0) goto readerr; /* discard CRLF */ } @@ -631,6 +632,7 @@ int loadAppendOnlyFile(char *filename) { * If the client is in the middle of a MULTI/EXEC, log error and quit. */ if (fakeClient->flags & REDIS_MULTI) goto uxeof; +loaded_ok: /* DB loaded, cleanup and return REDIS_OK to the caller. */ fclose(fp); freeFakeClient(fakeClient); server.aof_state = old_aof_state; @@ -646,7 +648,13 @@ readerr: /* Read error. If feof(fp) is true, fall through to unexpected EOF. */ } uxeof: /* Unexpected AOF end of file. */ - redisLog(REDIS_WARNING,"Unexpected end of file reading the append only file"); + if (server.aof_load_truncated) { + redisLog(REDIS_WARNING,"!!! Warning: short read while loading the AOF file !!!"); + redisLog(REDIS_WARNING, + "AOF loaded anyway because aof-load-truncated is enabled"); + goto loaded_ok; + } + redisLog(REDIS_WARNING,"Unexpected end of file reading the append only file. You can: 1) Make a backup of your AOF file, then use ./redis-check-aof --fix <filename>. 2) Alternatively you can set the 'aof-load-truncated' configuration option to yes and restart the server."); exit(1); fmterr: /* Format error. */ @@ -1099,7 +1107,7 @@ void aofRemoveTempFile(pid_t childpid) { unlink(tmpfile); } -/* Update the server.aof_current_size filed explicitly using stat(2) +/* Update the server.aof_current_size field explicitly using stat(2) * to check the size of the file. This is useful after a rewrite or after * a restart, normally the size is updated just adding the write length * to the current length, that is much faster. */ |