Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
85a83172
Commit
85a83172
authored
Nov 26, 2009
by
antirez
Browse files
append only file fixes
parent
9d65a1bb
Changes
1
Hide whitespace changes
Inline
Side-by-side
redis.c
View file @
85a83172
...
@@ -924,6 +924,7 @@ void backgroundRewriteDoneHandler(int statloc) {
...
@@ -924,6 +924,7 @@ void backgroundRewriteDoneHandler(int statloc) {
close(server.appendfd);
close(server.appendfd);
server.appendfd = fd;
server.appendfd = fd;
fsync(fd);
fsync(fd);
server.appendseldb = -1; /* Make sure it will issue SELECT */
redisLog(REDIS_NOTICE,"The new append only file was selected for future appends.");
redisLog(REDIS_NOTICE,"The new append only file was selected for future appends.");
} else {
} else {
/* If append only is disabled we just generate a dump in this
/* If append only is disabled we just generate a dump in this
...
@@ -5656,6 +5657,14 @@ static void feedAppendOnlyFile(struct redisCommand *cmd, int dictid, robj **argv
...
@@ -5656,6 +5657,14 @@ static void feedAppendOnlyFile(struct redisCommand *cmd, int dictid, robj **argv
}
}
exit(1);
exit(1);
}
}
/* If a background append only file rewriting is in progress we want to
* accumulate the differences between the child DB and the current one
* in a buffer, so that when the child process will do its work we
* can append the differences to the new append only file. */
if (server.bgrewritechildpid != -1)
server.bgrewritebuf = sdscatlen(server.bgrewritebuf,buf,sdslen(buf));
sdsfree(buf);
now = time(NULL);
now = time(NULL);
if (server.appendfsync == APPENDFSYNC_ALWAYS ||
if (server.appendfsync == APPENDFSYNC_ALWAYS ||
(server.appendfsync == APPENDFSYNC_EVERYSEC &&
(server.appendfsync == APPENDFSYNC_EVERYSEC &&
...
@@ -5845,7 +5854,7 @@ static int rewriteAppendOnlyFile(char *filename) {
...
@@ -5845,7 +5854,7 @@ static int rewriteAppendOnlyFile(char *filename) {
/* SELECT the new DB */
/* SELECT the new DB */
if (fwrite(selectcmd,sizeof(selectcmd)-1,1,fp) == 0) goto werr;
if (fwrite(selectcmd,sizeof(selectcmd)-1,1,fp) == 0) goto werr;
if (fwriteBulkLong(fp,j
+1
) == 0) goto werr;
if (fwriteBulkLong(fp,j) == 0) goto werr;
/* Iterate this DB writing every entry */
/* Iterate this DB writing every entry */
while((de = dictNext(di)) != NULL) {
while((de = dictNext(di)) != NULL) {
...
@@ -5854,7 +5863,6 @@ static int rewriteAppendOnlyFile(char *filename) {
...
@@ -5854,7 +5863,6 @@ static int rewriteAppendOnlyFile(char *filename) {
time_t expiretime = getExpire(db,key);
time_t expiretime = getExpire(db,key);
/* Save the key and associated value */
/* Save the key and associated value */
if (rdbSaveStringObject(fp,key) == -1) goto werr;
if (o->type == REDIS_STRING) {
if (o->type == REDIS_STRING) {
/* Emit a SET command */
/* Emit a SET command */
char cmd[]="*3\r\n$3\r\nSET\r\n";
char cmd[]="*3\r\n$3\r\nSET\r\n";
...
@@ -5985,6 +5993,11 @@ static int rewriteAppendOnlyFileBackground(void) {
...
@@ -5985,6 +5993,11 @@ static int rewriteAppendOnlyFileBackground(void) {
redisLog(REDIS_NOTICE,
redisLog(REDIS_NOTICE,
"Background append only file rewriting started by pid %d",childpid);
"Background append only file rewriting started by pid %d",childpid);
server.bgrewritechildpid = childpid;
server.bgrewritechildpid = childpid;
/* We set appendseldb to -1 in order to force the next call to the
* feedAppendOnlyFile() to issue a SELECT command, so the differences
* accumulated by the parent into server.bgrewritebuf will start
* with a SELECT statement and it will be safe to merge. */
server.appendseldb = -1;
return REDIS_OK;
return REDIS_OK;
}
}
return REDIS_OK; /* unreached */
return REDIS_OK; /* unreached */
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment