redisLog(REDIS_WARNING,"Used tried to switch on AOF via CONFIG, but I can't open the AOF file: %s",strerror(errno));
return REDIS_ERR;
}
if (rewriteAppendOnlyFileBackground() == REDIS_ERR) {
server.appendonly = 0;
close(server.appendfd);
redisLog(REDIS_WARNING,"Used tried to switch on AOF via CONFIG, I can't trigger a background AOF rewrite operation. Check the above logs for more info about the error.",strerror(errno));
return REDIS_ERR;
}
return REDIS_OK;
}
/* Write the append only file buffer on disk.
/* Write the append only file buffer on disk.
*
*
* Since we are required to write the AOF before replying to the client,
* Since we are required to write the AOF before replying to the client,
...
@@ -8598,24 +8692,26 @@ static int rewriteAppendOnlyFile(char *filename) {
...
@@ -8598,24 +8692,26 @@ static int rewriteAppendOnlyFile(char *filename) {
/* Iterate this DB writing every entry */
/* Iterate this DB writing every entry */
while((de = dictNext(di)) != NULL) {
while((de = dictNext(di)) != NULL) {
robj *key, *o;
sds keystr = dictGetEntryKey(de);
robj key, *o;
time_t expiretime;
time_t expiretime;
int swapped;
int swapped;
key = dictGetEntryKey(de);
keystr = dictGetEntryKey(de);
o = dictGetEntryVal(de);
initStaticStringObject(key,keystr);
/* If the value for this key is swapped, load a preview in memory.
/* If the value for this key is swapped, load a preview in memory.
* We use a "swapped" flag to remember if we need to free the
* We use a "swapped" flag to remember if we need to free the
* value object instead to just increment the ref count anyway
* value object instead to just increment the ref count anyway
* in order to avoid copy-on-write of pages if we are forked() */
* in order to avoid copy-on-write of pages if we are forked() */
if (!server.vm_enabled || key->storage == REDIS_VM_MEMORY ||
if (!server.vm_enabled || o->storage == REDIS_VM_MEMORY ||
key->storage == REDIS_VM_SWAPPING) {
o->storage == REDIS_VM_SWAPPING) {
o = dictGetEntryVal(de);
swapped = 0;
swapped = 0;
} else {
} else {
o = vmPreviewObject(key);
o = vmPreviewObject(o);
swapped = 1;
swapped = 1;
}
}
expiretime = getExpire(db,key);
expiretime = getExpire(db,&key);
/* Save the key and associated value */
/* Save the key and associated value */
if (o->type == REDIS_STRING) {
if (o->type == REDIS_STRING) {
...
@@ -8623,7 +8719,7 @@ static int rewriteAppendOnlyFile(char *filename) {
...
@@ -8623,7 +8719,7 @@ static int rewriteAppendOnlyFile(char *filename) {
char cmd[]="*3\r\n$3\r\nSET\r\n";
char cmd[]="*3\r\n$3\r\nSET\r\n";
if (fwrite(cmd,sizeof(cmd)-1,1,fp) == 0) goto werr;
if (fwrite(cmd,sizeof(cmd)-1,1,fp) == 0) goto werr;
/* Key and value */
/* Key and value */
if (fwriteBulkObject(fp,key) == 0) goto werr;
if (fwriteBulkObject(fp,&key) == 0) goto werr;
if (fwriteBulkObject(fp,o) == 0) goto werr;
if (fwriteBulkObject(fp,o) == 0) goto werr;
} else if (o->type == REDIS_LIST) {
} else if (o->type == REDIS_LIST) {
/* Emit the RPUSHes needed to rebuild the list */
/* Emit the RPUSHes needed to rebuild the list */
...
@@ -8637,7 +8733,7 @@ static int rewriteAppendOnlyFile(char *filename) {
...
@@ -8637,7 +8733,7 @@ static int rewriteAppendOnlyFile(char *filename) {
robj *eleobj = listNodeValue(ln);
robj *eleobj = listNodeValue(ln);
if (fwrite(cmd,sizeof(cmd)-1,1,fp) == 0) goto werr;
if (fwrite(cmd,sizeof(cmd)-1,1,fp) == 0) goto werr;
if (fwriteBulkObject(fp,key) == 0) goto werr;
if (fwriteBulkObject(fp,&key) == 0) goto werr;
if (fwriteBulkObject(fp,eleobj) == 0) goto werr;
if (fwriteBulkObject(fp,eleobj) == 0) goto werr;
}
}
} else if (o->type == REDIS_SET) {
} else if (o->type == REDIS_SET) {
...
@@ -8651,7 +8747,7 @@ static int rewriteAppendOnlyFile(char *filename) {
...
@@ -8651,7 +8747,7 @@ static int rewriteAppendOnlyFile(char *filename) {
robj *eleobj = dictGetEntryKey(de);
robj *eleobj = dictGetEntryKey(de);
if (fwrite(cmd,sizeof(cmd)-1,1,fp) == 0) goto werr;
if (fwrite(cmd,sizeof(cmd)-1,1,fp) == 0) goto werr;
if (fwriteBulkObject(fp,key) == 0) goto werr;
if (fwriteBulkObject(fp,&key) == 0) goto werr;
if (fwriteBulkObject(fp,eleobj) == 0) goto werr;
if (fwriteBulkObject(fp,eleobj) == 0) goto werr;
}
}
dictReleaseIterator(di);
dictReleaseIterator(di);
...
@@ -8667,7 +8763,7 @@ static int rewriteAppendOnlyFile(char *filename) {
...
@@ -8667,7 +8763,7 @@ static int rewriteAppendOnlyFile(char *filename) {
double *score = dictGetEntryVal(de);
double *score = dictGetEntryVal(de);
if (fwrite(cmd,sizeof(cmd)-1,1,fp) == 0) goto werr;
if (fwrite(cmd,sizeof(cmd)-1,1,fp) == 0) goto werr;
if (fwriteBulkObject(fp,key) == 0) goto werr;
if (fwriteBulkObject(fp,&key) == 0) goto werr;
if (fwriteBulkDouble(fp,*score) == 0) goto werr;
if (fwriteBulkDouble(fp,*score) == 0) goto werr;
if (fwriteBulkObject(fp,eleobj) == 0) goto werr;
if (fwriteBulkObject(fp,eleobj) == 0) goto werr;
}
}
...
@@ -8683,7 +8779,7 @@ static int rewriteAppendOnlyFile(char *filename) {
...
@@ -8683,7 +8779,7 @@ static int rewriteAppendOnlyFile(char *filename) {
redisLog(REDIS_WARNING,"Used tried to switch on AOF via CONFIG, but I can't open the AOF file: %s",strerror(errno));
return REDIS_ERR;
}
if (rewriteAppendOnlyFileBackground() == REDIS_ERR) {
server.appendonly = 0;
close(server.appendfd);
redisLog(REDIS_WARNING,"Used tried to switch on AOF via CONFIG, I can't trigger a background AOF rewrite operation. Check the above logs for more info about the error.",strerror(errno));
return REDIS_ERR;
}
return REDIS_OK;
}
/* =================== Virtual Memory - Blocking Side ====================== */