AOF fileds in the global server state, and define names, renamed with more consistent names. More work to do.

This commit is contained in:
antirez 2011-12-21 11:58:42 +01:00
parent e394114d95
commit 2c915bcf6d
5 changed files with 100 additions and 100 deletions

View File

@ -45,7 +45,7 @@ void stopAppendOnly(void) {
* 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));
@ -86,10 +86,10 @@ void flushAppendOnlyFile(int force) {
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. */
@ -130,7 +130,7 @@ void flushAppendOnlyFile(int force) {
}
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). */
@ -143,17 +143,17 @@ void flushAppendOnlyFile(int force) {
/* 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;
@ -314,7 +314,7 @@ int loadAppendOnlyFile(char *filename) {
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;
}
@ -398,7 +398,7 @@ int loadAppendOnlyFile(char *filename) {
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:
@ -441,8 +441,8 @@ int rewriteListObject(rio *r, robj *key, robj *o) {
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;
@ -454,7 +454,7 @@ int rewriteListObject(rio *r, robj *key, robj *o) {
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) {
@ -467,15 +467,15 @@ int rewriteListObject(rio *r, robj *key, robj *o) {
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 {
@ -495,15 +495,15 @@ int rewriteSetObject(rio *r, robj *key, robj *o) {
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) {
@ -513,15 +513,15 @@ int rewriteSetObject(rio *r, robj *key, robj *o) {
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);
@ -554,8 +554,8 @@ int rewriteSortedSetObject(rio *r, robj *key, robj *o) {
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;
@ -568,7 +568,7 @@ int rewriteSortedSetObject(rio *r, robj *key, robj *o) {
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) {
@ -581,8 +581,8 @@ int rewriteSortedSetObject(rio *r, robj *key, robj *o) {
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;
@ -590,7 +590,7 @@ int rewriteSortedSetObject(rio *r, robj *key, robj *o) {
}
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);
@ -612,8 +612,8 @@ int rewriteHashObject(rio *r, robj *key, robj *o) {
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;
@ -621,7 +621,7 @@ int rewriteHashObject(rio *r, robj *key, robj *o) {
}
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 {
@ -633,8 +633,8 @@ int rewriteHashObject(rio *r, robj *key, robj *o) {
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;
@ -642,7 +642,7 @@ int rewriteHashObject(rio *r, robj *key, robj *o) {
}
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);
@ -655,7 +655,7 @@ int rewriteHashObject(rio *r, robj *key, robj *o) {
*
* 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;
@ -799,7 +799,7 @@ int rewriteAppendOnlyFileBackground(void) {
}
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
@ -816,7 +816,7 @@ void bgrewriteaofCommand(redisClient *c) {
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");
@ -832,7 +832,7 @@ void aofRemoveTempFile(pid_t childpid) {
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. */
@ -843,7 +843,7 @@ void aofUpdateCurrentSize(void) {
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;
}
}
@ -919,7 +919,7 @@ void backgroundRewriteDoneHandler(int exitcode, int bysignal) {
/* 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. */
@ -927,7 +927,7 @@ void backgroundRewriteDoneHandler(int exitcode, int bysignal) {
/* 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);
@ -943,13 +943,13 @@ void backgroundRewriteDoneHandler(int exitcode, int bysignal) {
/* 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. */
@ -982,5 +982,5 @@ cleanup:
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;
}

View File

@ -220,20 +220,20 @@ void loadServerConfigFromString(char *config) {
}
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;
@ -241,15 +241,15 @@ void loadServerConfigFromString(char *config) {
} 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) {
@ -415,11 +415,11 @@ void configSetCommand(redisClient *c) {
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;
}
@ -427,7 +427,7 @@ void configSetCommand(redisClient *c) {
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);
@ -443,10 +443,10 @@ void configSetCommand(redisClient *c) {
}
} 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);
@ -621,16 +621,16 @@ void configGetCommand(redisClient *c) {
}
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");
@ -655,12 +655,12 @@ void configGetCommand(redisClient *c) {
}
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)) {

View File

@ -229,7 +229,7 @@ void debugCommand(redisClient *c) {
addReply(c,shared.ok);
} else if (!strcasecmp(c->argv[1]->ptr,"loadaof")) {
emptyDb();
if (loadAppendOnlyFile(server.appendfilename) != REDIS_OK) {
if (loadAppendOnlyFile(server.aof_filename) != REDIS_OK) {
addReply(c,shared.err);
return;
}

View File

@ -693,7 +693,7 @@ int serverCron(struct aeEventLoop *eventLoop, long long id, void *clientData) {
/* 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();
}
@ -736,13 +736,13 @@ int serverCron(struct aeEventLoop *eventLoop, long long id, void *clientData) {
/* 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();
}
@ -874,19 +874,19 @@ void initServerConfig() {
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;
@ -1068,7 +1068,7 @@ void initServer() {
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",
@ -1510,9 +1510,9 @@ sds genRedisInfoString(char *section) {
"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));
}
@ -2099,7 +2099,7 @@ int main(int argc, char **argv) {
#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) {

View File

@ -52,9 +52,9 @@
#define REDIS_SHARED_INTEGERS 10000
#define REDIS_REPLY_CHUNK_BYTES (16*1024) /* 16k output buffer */
#define REDIS_MAX_LOGMSG_LEN 1024 /* Default maximum length of syslog messages */
#define REDIS_AUTO_AOFREWRITE_PERC 100
#define REDIS_AUTO_AOFREWRITE_MIN_SIZE (1024*1024)
#define REDIS_AOFREWRITE_ITEMS_PER_CMD 64
#define REDIS_AOF_REWRITE_PERC 100
#define REDIS_AOF_REWRITE_MIN_SIZE (1024*1024)
#define REDIS_AOF_REWRITE_ITEMS_PER_CMD 64
#define REDIS_SLOWLOG_LOG_SLOWER_THAN 10000
#define REDIS_SLOWLOG_MAX_LEN 64
#define REDIS_MAX_CLIENTS 10000
@ -189,9 +189,9 @@
#define ZSKIPLIST_P 0.25 /* Skiplist P = 1/4 */
/* Append only defines */
#define APPENDFSYNC_NO 0
#define APPENDFSYNC_ALWAYS 1
#define APPENDFSYNC_EVERYSEC 2
#define AOF_FSYNC_NO 0
#define AOF_FSYNC_ALWAYS 1
#define AOF_FSYNC_EVERYSEC 2
/* Zip structure related defaults */
#define REDIS_HASH_MAX_ZIPMAP_ENTRIES 512
@ -552,14 +552,14 @@ struct redisServer {
int daemonize; /* True if running as a daemon */
/* AOF persistence */
int aof_state; /* REDIS_AOF_(ON|OFF|WAIT_REWRITE) */
int appendfsync; /* Kind of fsync() policy */
char *appendfilename; /* Name of the AOF file */
int no_appendfsync_on_rewrite; /* Don't fsync if a rewrite is in prog. */
int auto_aofrewrite_perc; /* Rewrite AOF if % growth is > M and... */
off_t auto_aofrewrite_min_size; /* the AOF file is at least N bytes. */
off_t auto_aofrewrite_base_size;/* AOF size on latest startup or rewrite. */
off_t appendonly_current_size; /* AOF current size. */
int aofrewrite_scheduled; /* Rewrite once BGSAVE terminates. */
int aof_fsync; /* Kind of fsync() policy */
char *aof_filename; /* Name of the AOF file */
int aof_no_fsync_on_rewrite; /* Don't fsync if a rewrite is in prog. */
int aof_rewrite_perc; /* Rewrite AOF if % growth is > M and... */
off_t aof_rewrite_min_size; /* the AOF file is at least N bytes. */
off_t aof_rewrite_base_size; /* AOF size on latest startup or rewrite. */
off_t aof_current_size; /* AOF current size. */
int aof_rewrite_scheduled; /* Rewrite once BGSAVE terminates. */
pid_t bgrewritechildpid; /* PID if rewriting process */
sds bgrewritebuf; /* buffer taken by parent during oppend only rewrite */
sds aofbuf; /* AOF buffer, written before entering the event loop */