* at runtime using the CONFIG command. */
int startAppendOnly(void) {
server.lastfsync = time(NULL);
- server.appendfd = open(server.appendfilename,O_WRONLY|O_APPEND|O_CREAT,0644);
+ server.appendfd = open(server.aof_filename,O_WRONLY|O_APPEND|O_CREAT,0644);
redisAssert(server.aof_state == REDIS_AOF_OFF);
if (server.appendfd == -1) {
redisLog(REDIS_WARNING,"Redis needs to enable the AOF but can't open the append only file: %s",strerror(errno));
if (sdslen(server.aofbuf) == 0) return;
- if (server.appendfsync == APPENDFSYNC_EVERYSEC)
+ if (server.aof_fsync == AOF_FSYNC_EVERYSEC)
sync_in_progress = bioPendingJobsOfType(REDIS_BIO_AOF_FSYNC) != 0;
- if (server.appendfsync == APPENDFSYNC_EVERYSEC && !force) {
+ if (server.aof_fsync == AOF_FSYNC_EVERYSEC && !force) {
/* With this append fsync policy we do background fsyncing.
* If the fsync is still in progress we can try to delay
* the write for a couple of seconds. */
}
exit(1);
}
- server.appendonly_current_size += nwritten;
+ server.aof_current_size += nwritten;
/* Re-use AOF buffer when it is small enough. The maximum comes from the
* arena size of 4k minus some overhead (but is otherwise arbitrary). */
/* Don't fsync if no-appendfsync-on-rewrite is set to yes and there are
* children doing I/O in the background. */
- if (server.no_appendfsync_on_rewrite &&
+ if (server.aof_no_fsync_on_rewrite &&
(server.bgrewritechildpid != -1 || server.bgsavechildpid != -1))
return;
/* Perform the fsync if needed. */
- if (server.appendfsync == APPENDFSYNC_ALWAYS) {
+ if (server.aof_fsync == AOF_FSYNC_ALWAYS) {
/* aof_fsync is defined as fdatasync() for Linux in order to avoid
* flushing metadata. */
aof_fsync(server.appendfd); /* Let's try to get this data on the disk */
server.lastfsync = server.unixtime;
- } else if ((server.appendfsync == APPENDFSYNC_EVERYSEC &&
+ } else if ((server.aof_fsync == AOF_FSYNC_EVERYSEC &&
server.unixtime > server.lastfsync)) {
if (!sync_in_progress) aof_background_fsync(server.appendfd);
server.lastfsync = server.unixtime;
long loops = 0;
if (fp && redis_fstat(fileno(fp),&sb) != -1 && sb.st_size == 0) {
- server.appendonly_current_size = 0;
+ server.aof_current_size = 0;
fclose(fp);
return REDIS_ERR;
}
server.aof_state = old_aof_state;
stopLoading();
aofUpdateCurrentSize();
- server.auto_aofrewrite_base_size = server.appendonly_current_size;
+ server.aof_rewrite_base_size = server.aof_current_size;
return REDIS_OK;
readerr:
while(ziplistGet(p,&vstr,&vlen,&vlong)) {
if (count == 0) {
- int cmd_items = (items > REDIS_AOFREWRITE_ITEMS_PER_CMD) ?
- REDIS_AOFREWRITE_ITEMS_PER_CMD : items;
+ int cmd_items = (items > REDIS_AOF_REWRITE_ITEMS_PER_CMD) ?
+ REDIS_AOF_REWRITE_ITEMS_PER_CMD : items;
if (rioWriteBulkCount(r,'*',2+cmd_items) == 0) return 0;
if (rioWriteBulkString(r,"RPUSH",5) == 0) return 0;
if (rioWriteBulkLongLong(r,vlong) == 0) return 0;
}
p = ziplistNext(zl,p);
- if (++count == REDIS_AOFREWRITE_ITEMS_PER_CMD) count = 0;
+ if (++count == REDIS_AOF_REWRITE_ITEMS_PER_CMD) count = 0;
items--;
}
} else if (o->encoding == REDIS_ENCODING_LINKEDLIST) {
robj *eleobj = listNodeValue(ln);
if (count == 0) {
- int cmd_items = (items > REDIS_AOFREWRITE_ITEMS_PER_CMD) ?
- REDIS_AOFREWRITE_ITEMS_PER_CMD : items;
+ int cmd_items = (items > REDIS_AOF_REWRITE_ITEMS_PER_CMD) ?
+ REDIS_AOF_REWRITE_ITEMS_PER_CMD : items;
if (rioWriteBulkCount(r,'*',2+cmd_items) == 0) return 0;
if (rioWriteBulkString(r,"RPUSH",5) == 0) return 0;
if (rioWriteBulkObject(r,key) == 0) return 0;
}
if (rioWriteBulkObject(r,eleobj) == 0) return 0;
- if (++count == REDIS_AOFREWRITE_ITEMS_PER_CMD) count = 0;
+ if (++count == REDIS_AOF_REWRITE_ITEMS_PER_CMD) count = 0;
items--;
}
} else {
while(intsetGet(o->ptr,ii++,&llval)) {
if (count == 0) {
- int cmd_items = (items > REDIS_AOFREWRITE_ITEMS_PER_CMD) ?
- REDIS_AOFREWRITE_ITEMS_PER_CMD : items;
+ int cmd_items = (items > REDIS_AOF_REWRITE_ITEMS_PER_CMD) ?
+ REDIS_AOF_REWRITE_ITEMS_PER_CMD : items;
if (rioWriteBulkCount(r,'*',2+cmd_items) == 0) return 0;
if (rioWriteBulkString(r,"SADD",4) == 0) return 0;
if (rioWriteBulkObject(r,key) == 0) return 0;
}
if (rioWriteBulkLongLong(r,llval) == 0) return 0;
- if (++count == REDIS_AOFREWRITE_ITEMS_PER_CMD) count = 0;
+ if (++count == REDIS_AOF_REWRITE_ITEMS_PER_CMD) count = 0;
items--;
}
} else if (o->encoding == REDIS_ENCODING_HT) {
while((de = dictNext(di)) != NULL) {
robj *eleobj = dictGetKey(de);
if (count == 0) {
- int cmd_items = (items > REDIS_AOFREWRITE_ITEMS_PER_CMD) ?
- REDIS_AOFREWRITE_ITEMS_PER_CMD : items;
+ int cmd_items = (items > REDIS_AOF_REWRITE_ITEMS_PER_CMD) ?
+ REDIS_AOF_REWRITE_ITEMS_PER_CMD : items;
if (rioWriteBulkCount(r,'*',2+cmd_items) == 0) return 0;
if (rioWriteBulkString(r,"SADD",4) == 0) return 0;
if (rioWriteBulkObject(r,key) == 0) return 0;
}
if (rioWriteBulkObject(r,eleobj) == 0) return 0;
- if (++count == REDIS_AOFREWRITE_ITEMS_PER_CMD) count = 0;
+ if (++count == REDIS_AOF_REWRITE_ITEMS_PER_CMD) count = 0;
items--;
}
dictReleaseIterator(di);
score = zzlGetScore(sptr);
if (count == 0) {
- int cmd_items = (items > REDIS_AOFREWRITE_ITEMS_PER_CMD) ?
- REDIS_AOFREWRITE_ITEMS_PER_CMD : items;
+ int cmd_items = (items > REDIS_AOF_REWRITE_ITEMS_PER_CMD) ?
+ REDIS_AOF_REWRITE_ITEMS_PER_CMD : items;
if (rioWriteBulkCount(r,'*',2+cmd_items*2) == 0) return 0;
if (rioWriteBulkString(r,"ZADD",4) == 0) return 0;
if (rioWriteBulkLongLong(r,vll) == 0) return 0;
}
zzlNext(zl,&eptr,&sptr);
- if (++count == REDIS_AOFREWRITE_ITEMS_PER_CMD) count = 0;
+ if (++count == REDIS_AOF_REWRITE_ITEMS_PER_CMD) count = 0;
items--;
}
} else if (o->encoding == REDIS_ENCODING_SKIPLIST) {
double *score = dictGetVal(de);
if (count == 0) {
- int cmd_items = (items > REDIS_AOFREWRITE_ITEMS_PER_CMD) ?
- REDIS_AOFREWRITE_ITEMS_PER_CMD : items;
+ int cmd_items = (items > REDIS_AOF_REWRITE_ITEMS_PER_CMD) ?
+ REDIS_AOF_REWRITE_ITEMS_PER_CMD : items;
if (rioWriteBulkCount(r,'*',2+cmd_items*2) == 0) return 0;
if (rioWriteBulkString(r,"ZADD",4) == 0) return 0;
}
if (rioWriteBulkDouble(r,*score) == 0) return 0;
if (rioWriteBulkObject(r,eleobj) == 0) return 0;
- if (++count == REDIS_AOFREWRITE_ITEMS_PER_CMD) count = 0;
+ if (++count == REDIS_AOF_REWRITE_ITEMS_PER_CMD) count = 0;
items--;
}
dictReleaseIterator(di);
while((p = zipmapNext(p,&field,&flen,&val,&vlen)) != NULL) {
if (count == 0) {
- int cmd_items = (items > REDIS_AOFREWRITE_ITEMS_PER_CMD) ?
- REDIS_AOFREWRITE_ITEMS_PER_CMD : items;
+ int cmd_items = (items > REDIS_AOF_REWRITE_ITEMS_PER_CMD) ?
+ REDIS_AOF_REWRITE_ITEMS_PER_CMD : items;
if (rioWriteBulkCount(r,'*',2+cmd_items*2) == 0) return 0;
if (rioWriteBulkString(r,"HMSET",5) == 0) return 0;
}
if (rioWriteBulkString(r,(char*)field,flen) == 0) return 0;
if (rioWriteBulkString(r,(char*)val,vlen) == 0) return 0;
- if (++count == REDIS_AOFREWRITE_ITEMS_PER_CMD) count = 0;
+ if (++count == REDIS_AOF_REWRITE_ITEMS_PER_CMD) count = 0;
items--;
}
} else {
robj *val = dictGetVal(de);
if (count == 0) {
- int cmd_items = (items > REDIS_AOFREWRITE_ITEMS_PER_CMD) ?
- REDIS_AOFREWRITE_ITEMS_PER_CMD : items;
+ int cmd_items = (items > REDIS_AOF_REWRITE_ITEMS_PER_CMD) ?
+ REDIS_AOF_REWRITE_ITEMS_PER_CMD : items;
if (rioWriteBulkCount(r,'*',2+cmd_items*2) == 0) return 0;
if (rioWriteBulkString(r,"HMSET",5) == 0) return 0;
}
if (rioWriteBulkObject(r,field) == 0) return 0;
if (rioWriteBulkObject(r,val) == 0) return 0;
- if (++count == REDIS_AOFREWRITE_ITEMS_PER_CMD) count = 0;
+ if (++count == REDIS_AOF_REWRITE_ITEMS_PER_CMD) count = 0;
items--;
}
dictReleaseIterator(di);
*
* In order to minimize the number of commands needed in the rewritten
* log Redis uses variadic commands when possible, such as RPUSH, SADD
- * and ZADD. However at max REDIS_AOFREWRITE_ITEMS_PER_CMD items per time
+ * and ZADD. However at max REDIS_AOF_REWRITE_ITEMS_PER_CMD items per time
* are inserted using a single command. */
int rewriteAppendOnlyFile(char *filename) {
dictIterator *di = NULL;
}
redisLog(REDIS_NOTICE,
"Background append only file rewriting started by pid %d",childpid);
- server.aofrewrite_scheduled = 0;
+ server.aof_rewrite_scheduled = 0;
server.bgrewritechildpid = childpid;
updateDictResizePolicy();
/* We set appendseldb to -1 in order to force the next call to the
if (server.bgrewritechildpid != -1) {
addReplyError(c,"Background append only file rewriting already in progress");
} else if (server.bgsavechildpid != -1) {
- server.aofrewrite_scheduled = 1;
+ server.aof_rewrite_scheduled = 1;
addReplyStatus(c,"Background append only file rewriting scheduled");
} else if (rewriteAppendOnlyFileBackground() == REDIS_OK) {
addReplyStatus(c,"Background append only file rewriting started");
unlink(tmpfile);
}
-/* Update the server.appendonly_current_size filed explicitly using stat(2)
+/* Update the server.aof_current_size filed 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 lenght, that is much faster. */
redisLog(REDIS_WARNING,"Unable to check the AOF length: %s",
strerror(errno));
} else {
- server.appendonly_current_size = sb.st_size;
+ server.aof_current_size = sb.st_size;
}
}
/* Don't care if this fails: oldfd will be -1 and we handle that.
* One notable case of -1 return is if the old file does
* not exist. */
- oldfd = open(server.appendfilename,O_RDONLY|O_NONBLOCK);
+ oldfd = open(server.aof_filename,O_RDONLY|O_NONBLOCK);
} else {
/* AOF enabled */
oldfd = -1; /* We'll set this to the current AOF filedes later. */
/* Rename the temporary file. This will not unlink the target file if
* it exists, because we reference it with "oldfd". */
- if (rename(tmpfile,server.appendfilename) == -1) {
+ if (rename(tmpfile,server.aof_filename) == -1) {
redisLog(REDIS_WARNING,
"Error trying to rename the temporary AOF: %s", strerror(errno));
close(newfd);
/* AOF enabled, replace the old fd with the new one. */
oldfd = server.appendfd;
server.appendfd = newfd;
- if (server.appendfsync == APPENDFSYNC_ALWAYS)
+ if (server.aof_fsync == AOF_FSYNC_ALWAYS)
aof_fsync(newfd);
- else if (server.appendfsync == APPENDFSYNC_EVERYSEC)
+ else if (server.aof_fsync == AOF_FSYNC_EVERYSEC)
aof_background_fsync(newfd);
server.appendseldb = -1; /* Make sure SELECT is re-issued */
aofUpdateCurrentSize();
- server.auto_aofrewrite_base_size = server.appendonly_current_size;
+ server.aof_rewrite_base_size = server.aof_current_size;
/* Clear regular AOF buffer since its contents was just written to
* the new AOF from the background rewrite buffer. */
server.bgrewritechildpid = -1;
/* Schedule a new rewrite if we are waiting for it to switch the AOF ON. */
if (server.aof_state == REDIS_AOF_WAIT_REWRITE)
- server.aofrewrite_scheduled = 1;
+ server.aof_rewrite_scheduled = 1;
}
}
server.aof_state = yes ? REDIS_AOF_ON : REDIS_AOF_OFF;
} else if (!strcasecmp(argv[0],"appendfilename") && argc == 2) {
- zfree(server.appendfilename);
- server.appendfilename = zstrdup(argv[1]);
+ zfree(server.aof_filename);
+ server.aof_filename = zstrdup(argv[1]);
} else if (!strcasecmp(argv[0],"no-appendfsync-on-rewrite")
&& argc == 2) {
- if ((server.no_appendfsync_on_rewrite= yesnotoi(argv[1])) == -1) {
+ if ((server.aof_no_fsync_on_rewrite= yesnotoi(argv[1])) == -1) {
err = "argument must be 'yes' or 'no'"; goto loaderr;
}
} else if (!strcasecmp(argv[0],"appendfsync") && argc == 2) {
if (!strcasecmp(argv[1],"no")) {
- server.appendfsync = APPENDFSYNC_NO;
+ server.aof_fsync = AOF_FSYNC_NO;
} else if (!strcasecmp(argv[1],"always")) {
- server.appendfsync = APPENDFSYNC_ALWAYS;
+ server.aof_fsync = AOF_FSYNC_ALWAYS;
} else if (!strcasecmp(argv[1],"everysec")) {
- server.appendfsync = APPENDFSYNC_EVERYSEC;
+ server.aof_fsync = AOF_FSYNC_EVERYSEC;
} else {
err = "argument must be 'no', 'always' or 'everysec'";
goto loaderr;
} else if (!strcasecmp(argv[0],"auto-aof-rewrite-percentage") &&
argc == 2)
{
- server.auto_aofrewrite_perc = atoi(argv[1]);
- if (server.auto_aofrewrite_perc < 0) {
+ server.aof_rewrite_perc = atoi(argv[1]);
+ if (server.aof_rewrite_perc < 0) {
err = "Invalid negative percentage for AOF auto rewrite";
goto loaderr;
}
} else if (!strcasecmp(argv[0],"auto-aof-rewrite-min-size") &&
argc == 2)
{
- server.auto_aofrewrite_min_size = memtoll(argv[1],NULL);
+ server.aof_rewrite_min_size = memtoll(argv[1],NULL);
} else if (!strcasecmp(argv[0],"requirepass") && argc == 2) {
server.requirepass = zstrdup(argv[1]);
} else if (!strcasecmp(argv[0],"pidfile") && argc == 2) {
server.maxidletime = ll;
} else if (!strcasecmp(c->argv[2]->ptr,"appendfsync")) {
if (!strcasecmp(o->ptr,"no")) {
- server.appendfsync = APPENDFSYNC_NO;
+ server.aof_fsync = AOF_FSYNC_NO;
} else if (!strcasecmp(o->ptr,"everysec")) {
- server.appendfsync = APPENDFSYNC_EVERYSEC;
+ server.aof_fsync = AOF_FSYNC_EVERYSEC;
} else if (!strcasecmp(o->ptr,"always")) {
- server.appendfsync = APPENDFSYNC_ALWAYS;
+ server.aof_fsync = AOF_FSYNC_ALWAYS;
} else {
goto badfmt;
}
int yn = yesnotoi(o->ptr);
if (yn == -1) goto badfmt;
- server.no_appendfsync_on_rewrite = yn;
+ server.aof_no_fsync_on_rewrite = yn;
} else if (!strcasecmp(c->argv[2]->ptr,"appendonly")) {
int enable = yesnotoi(o->ptr);
}
} else if (!strcasecmp(c->argv[2]->ptr,"auto-aof-rewrite-percentage")) {
if (getLongLongFromObject(o,&ll) == REDIS_ERR || ll < 0) goto badfmt;
- server.auto_aofrewrite_perc = ll;
+ server.aof_rewrite_perc = ll;
} else if (!strcasecmp(c->argv[2]->ptr,"auto-aof-rewrite-min-size")) {
if (getLongLongFromObject(o,&ll) == REDIS_ERR || ll < 0) goto badfmt;
- server.auto_aofrewrite_min_size = ll;
+ server.aof_rewrite_min_size = ll;
} else if (!strcasecmp(c->argv[2]->ptr,"save")) {
int vlen, j;
sds *v = sdssplitlen(o->ptr,sdslen(o->ptr)," ",1,&vlen);
}
if (stringmatch(pattern,"no-appendfsync-on-rewrite",0)) {
addReplyBulkCString(c,"no-appendfsync-on-rewrite");
- addReplyBulkCString(c,server.no_appendfsync_on_rewrite ? "yes" : "no");
+ addReplyBulkCString(c,server.aof_no_fsync_on_rewrite ? "yes" : "no");
matches++;
}
if (stringmatch(pattern,"appendfsync",0)) {
char *policy;
- switch(server.appendfsync) {
- case APPENDFSYNC_NO: policy = "no"; break;
- case APPENDFSYNC_EVERYSEC: policy = "everysec"; break;
- case APPENDFSYNC_ALWAYS: policy = "always"; break;
+ switch(server.aof_fsync) {
+ case AOF_FSYNC_NO: policy = "no"; break;
+ case AOF_FSYNC_EVERYSEC: policy = "everysec"; break;
+ case AOF_FSYNC_ALWAYS: policy = "always"; break;
default: policy = "unknown"; break; /* too harmless to panic */
}
addReplyBulkCString(c,"appendfsync");
}
if (stringmatch(pattern,"auto-aof-rewrite-percentage",0)) {
addReplyBulkCString(c,"auto-aof-rewrite-percentage");
- addReplyBulkLongLong(c,server.auto_aofrewrite_perc);
+ addReplyBulkLongLong(c,server.aof_rewrite_perc);
matches++;
}
if (stringmatch(pattern,"auto-aof-rewrite-min-size",0)) {
addReplyBulkCString(c,"auto-aof-rewrite-min-size");
- addReplyBulkLongLong(c,server.auto_aofrewrite_min_size);
+ addReplyBulkLongLong(c,server.aof_rewrite_min_size);
matches++;
}
if (stringmatch(pattern,"slave-serve-stale-data",0)) {
/* Start a scheduled AOF rewrite if this was requested by the user while
* a BGSAVE was in progress. */
if (server.bgsavechildpid == -1 && server.bgrewritechildpid == -1 &&
- server.aofrewrite_scheduled)
+ server.aof_rewrite_scheduled)
{
rewriteAppendOnlyFileBackground();
}
/* Trigger an AOF rewrite if needed */
if (server.bgsavechildpid == -1 &&
server.bgrewritechildpid == -1 &&
- server.auto_aofrewrite_perc &&
- server.appendonly_current_size > server.auto_aofrewrite_min_size)
+ server.aof_rewrite_perc &&
+ server.aof_current_size > server.aof_rewrite_min_size)
{
- long long base = server.auto_aofrewrite_base_size ?
- server.auto_aofrewrite_base_size : 1;
- long long growth = (server.appendonly_current_size*100/base) - 100;
- if (growth >= server.auto_aofrewrite_perc) {
+ long long base = server.aof_rewrite_base_size ?
+ server.aof_rewrite_base_size : 1;
+ long long growth = (server.aof_current_size*100/base) - 100;
+ if (growth >= server.aof_rewrite_perc) {
redisLog(REDIS_NOTICE,"Starting automatic rewriting of AOF on %lld%% growth",growth);
rewriteAppendOnlyFileBackground();
}
server.syslog_facility = LOG_LOCAL0;
server.daemonize = 0;
server.aof_state = REDIS_AOF_OFF;
- server.appendfsync = APPENDFSYNC_EVERYSEC;
- server.no_appendfsync_on_rewrite = 0;
- server.auto_aofrewrite_perc = REDIS_AUTO_AOFREWRITE_PERC;
- server.auto_aofrewrite_min_size = REDIS_AUTO_AOFREWRITE_MIN_SIZE;
- server.auto_aofrewrite_base_size = 0;
- server.aofrewrite_scheduled = 0;
+ server.aof_fsync = AOF_FSYNC_EVERYSEC;
+ server.aof_no_fsync_on_rewrite = 0;
+ server.aof_rewrite_perc = REDIS_AOF_REWRITE_PERC;
+ server.aof_rewrite_min_size = REDIS_AOF_REWRITE_MIN_SIZE;
+ server.aof_rewrite_base_size = 0;
+ server.aof_rewrite_scheduled = 0;
server.lastfsync = time(NULL);
server.appendfd = -1;
server.appendseldb = -1; /* Make sure the first time will not match */
server.aof_flush_postponed_start = 0;
server.pidfile = zstrdup("/var/run/redis.pid");
server.dbfilename = zstrdup("dump.rdb");
- server.appendfilename = zstrdup("appendonly.aof");
+ server.aof_filename = zstrdup("appendonly.aof");
server.requirepass = NULL;
server.rdbcompression = 1;
server.activerehashing = 1;
acceptUnixHandler,NULL) == AE_ERR) oom("creating file event");
if (server.aof_state == REDIS_AOF_ON) {
- server.appendfd = open(server.appendfilename,
+ server.appendfd = open(server.aof_filename,
O_WRONLY|O_APPEND|O_CREAT,0644);
if (server.appendfd == -1) {
redisLog(REDIS_WARNING, "Can't open the append-only file: %s",
"aof_pending_rewrite:%d\r\n"
"aof_buffer_length:%zu\r\n"
"aof_pending_bio_fsync:%llu\r\n",
- (long long) server.appendonly_current_size,
- (long long) server.auto_aofrewrite_base_size,
- server.aofrewrite_scheduled,
+ (long long) server.aof_current_size,
+ (long long) server.aof_rewrite_base_size,
+ server.aof_rewrite_scheduled,
sdslen(server.aofbuf),
bioPendingJobsOfType(REDIS_BIO_AOF_FSYNC));
}
#endif
start = ustime();
if (server.aof_state == REDIS_AOF_ON) {
- if (loadAppendOnlyFile(server.appendfilename) == REDIS_OK)
+ if (loadAppendOnlyFile(server.aof_filename) == REDIS_OK)
redisLog(REDIS_NOTICE,"DB loaded from append only file: %.3f seconds",(float)(ustime()-start)/1000000);
} else {
if (rdbLoad(server.dbfilename) == REDIS_OK) {