mirror of
https://github.com/fluencelabs/redis
synced 2025-03-19 09:00:51 +00:00
Don't expire keys while loading RDB from AOF preamble.
The AOF tail of a combined RDB+AOF is based on the premise of applying the AOF commands to the exact state that there was in the server while the RDB was persisted. By expiring keys while loading the RDB file, we change the state, so applying the AOF tail later may change the state. Test case: * Time1: SET a 10 * Time2: EXPIREAT a $time5 * Time3: INCR a * Time4: PERSIT A. Start bgrewiteaof with RDB preamble. The value of a is 11 without expire time. * Time5: Restart redis from the RDB+AOF: consistency violation. Thanks to @soloestoy for providing the patch. Thanks to @trevor211 for the original issue report and the initial fix. Check issue #4950 for more info.
This commit is contained in:
parent
2a887bd53f
commit
49147f36e9
@ -713,7 +713,7 @@ int loadAppendOnlyFile(char *filename) {
|
|||||||
serverLog(LL_NOTICE,"Reading RDB preamble from AOF file...");
|
serverLog(LL_NOTICE,"Reading RDB preamble from AOF file...");
|
||||||
if (fseek(fp,0,SEEK_SET) == -1) goto readerr;
|
if (fseek(fp,0,SEEK_SET) == -1) goto readerr;
|
||||||
rioInitWithFile(&rdb,fp);
|
rioInitWithFile(&rdb,fp);
|
||||||
if (rdbLoadRio(&rdb,NULL) != C_OK) {
|
if (rdbLoadRio(&rdb,NULL,1) != C_OK) {
|
||||||
serverLog(LL_WARNING,"Error reading the RDB preamble of the AOF file, AOF loading aborted");
|
serverLog(LL_WARNING,"Error reading the RDB preamble of the AOF file, AOF loading aborted");
|
||||||
goto readerr;
|
goto readerr;
|
||||||
} else {
|
} else {
|
||||||
|
@ -1822,7 +1822,7 @@ void rdbLoadProgressCallback(rio *r, const void *buf, size_t len) {
|
|||||||
|
|
||||||
/* 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 and 'errno' is set accordingly. */
|
||||||
int rdbLoadRio(rio *rdb, rdbSaveInfo *rsi) {
|
int rdbLoadRio(rio *rdb, rdbSaveInfo *rsi, int loading_aof) {
|
||||||
uint64_t dbid;
|
uint64_t dbid;
|
||||||
int type, rdbver;
|
int type, rdbver;
|
||||||
redisDb *db = server.db+0;
|
redisDb *db = server.db+0;
|
||||||
@ -1987,7 +1987,7 @@ int rdbLoadRio(rio *rdb, rdbSaveInfo *rsi) {
|
|||||||
* received from the master. In the latter case, the master is
|
* received from the master. In the latter case, the master is
|
||||||
* responsible for key expiry. If we would expire keys here, the
|
* responsible for key expiry. If we would expire keys here, the
|
||||||
* snapshot taken by the master may not be reflected on the slave. */
|
* snapshot taken by the master may not be reflected on the slave. */
|
||||||
if (server.masterhost == NULL && expiretime != -1 && expiretime < now) {
|
if (server.masterhost == NULL && !loading_aof && expiretime != -1 && expiretime < now) {
|
||||||
decrRefCount(key);
|
decrRefCount(key);
|
||||||
decrRefCount(val);
|
decrRefCount(val);
|
||||||
} else {
|
} else {
|
||||||
@ -2060,7 +2060,7 @@ int rdbLoad(char *filename, rdbSaveInfo *rsi) {
|
|||||||
if ((fp = fopen(filename,"r")) == NULL) return C_ERR;
|
if ((fp = fopen(filename,"r")) == NULL) return C_ERR;
|
||||||
startLoading(fp);
|
startLoading(fp);
|
||||||
rioInitWithFile(&rdb,fp);
|
rioInitWithFile(&rdb,fp);
|
||||||
retval = rdbLoadRio(&rdb,rsi);
|
retval = rdbLoadRio(&rdb,rsi,0);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
stopLoading();
|
stopLoading();
|
||||||
return retval;
|
return retval;
|
||||||
|
@ -151,7 +151,7 @@ int rdbSaveBinaryDoubleValue(rio *rdb, double val);
|
|||||||
int rdbLoadBinaryDoubleValue(rio *rdb, double *val);
|
int rdbLoadBinaryDoubleValue(rio *rdb, double *val);
|
||||||
int rdbSaveBinaryFloatValue(rio *rdb, float val);
|
int rdbSaveBinaryFloatValue(rio *rdb, float val);
|
||||||
int rdbLoadBinaryFloatValue(rio *rdb, float *val);
|
int rdbLoadBinaryFloatValue(rio *rdb, float *val);
|
||||||
int rdbLoadRio(rio *rdb, rdbSaveInfo *rsi);
|
int rdbLoadRio(rio *rdb, rdbSaveInfo *rsi, int loading_aof);
|
||||||
rdbSaveInfo *rdbPopulateSaveInfo(rdbSaveInfo *rsi);
|
rdbSaveInfo *rdbPopulateSaveInfo(rdbSaveInfo *rsi);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user