mirror of
https://codeberg.org/redict/redict.git
synced 2025-01-23 00:28:26 -05:00
Fix AOF bug: expire could be removed from key on AOF rewrite.
There was a race condition in the AOF rewrite code that, with bad enough timing, could cause a volatile key just about to expire to be turned into a non-volatile key. The bug was never reported to cause actualy issues, but was found analytically by an user in the Redis mailing list: https://groups.google.com/forum/?fromgroups=#!topic/redis-db/Kvh2FAGK4Uk This commit fixes issue #1079.
This commit is contained in:
parent
e5ef85c444
commit
9cd06e4406
@ -884,6 +884,9 @@ int rewriteAppendOnlyFile(char *filename) {
|
|||||||
|
|
||||||
expiretime = getExpire(db,&key);
|
expiretime = getExpire(db,&key);
|
||||||
|
|
||||||
|
/* If this key is already expired skip it */
|
||||||
|
if (expiretime != -1 && expiretime < now) continue;
|
||||||
|
|
||||||
/* Save the key and associated value */
|
/* Save the key and associated value */
|
||||||
if (o->type == REDIS_STRING) {
|
if (o->type == REDIS_STRING) {
|
||||||
/* Emit a SET command */
|
/* Emit a SET command */
|
||||||
@ -906,8 +909,6 @@ int rewriteAppendOnlyFile(char *filename) {
|
|||||||
/* Save the expire time */
|
/* Save the expire time */
|
||||||
if (expiretime != -1) {
|
if (expiretime != -1) {
|
||||||
char cmd[]="*3\r\n$9\r\nPEXPIREAT\r\n";
|
char cmd[]="*3\r\n$9\r\nPEXPIREAT\r\n";
|
||||||
/* If this key is already expired skip it */
|
|
||||||
if (expiretime < now) continue;
|
|
||||||
if (rioWrite(&aof,cmd,sizeof(cmd)-1) == 0) goto werr;
|
if (rioWrite(&aof,cmd,sizeof(cmd)-1) == 0) goto werr;
|
||||||
if (rioWriteBulkObject(&aof,&key) == 0) goto werr;
|
if (rioWriteBulkObject(&aof,&key) == 0) goto werr;
|
||||||
if (rioWriteBulkLongLong(&aof,expiretime) == 0) goto werr;
|
if (rioWriteBulkLongLong(&aof,expiretime) == 0) goto werr;
|
||||||
|
Loading…
Reference in New Issue
Block a user