summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2014-07-04 17:51:03 +0200
committerantirez <antirez@gmail.com>2014-07-04 17:51:03 +0200
commit20a0959964b9214fab02556f11ef3aad95f77333 (patch)
tree49c372eb5f7b64e23cf4e119ac752d6a0e98b86b
parentcc24447a1a9c05b04b369106776d01e95c91c4c9 (diff)
downloadredis-20a0959964b9214fab02556f11ef3aad95f77333.tar.gz
Fine tuning of aofReadDiffFromParent() calls trigger.
-rw-r--r--src/aof.c31
1 files changed, 27 insertions, 4 deletions
diff --git a/src/aof.c b/src/aof.c
index b666154f2..6858120c9 100644
--- a/src/aof.c
+++ b/src/aof.c
@@ -940,14 +940,16 @@ int rewriteHashObject(rio *r, robj *key, robj *o) {
/* This function is called by the child rewriting the AOF file to read
* the difference accumulated from the parent into a buffer, that is
* concatenated at the end of the rewrite. */
-void aofReadDiffFromParent(void) {
- char buf[1024*16];
- ssize_t nread;
+ssize_t aofReadDiffFromParent(void) {
+ char buf[65536]; /* Default pipe buffer size on most Linux sytems. */
+ ssize_t nread, total = 0;
while ((nread =
read(server.aof_pipe_read_data_from_parent,buf,sizeof(buf))) > 0) {
server.aof_child_diff = sdscatlen(server.aof_child_diff,buf,nread);
+ total += nread;
}
+ return total;
}
/* Write a sequence of commands able to fully rebuild the dataset into
@@ -1038,7 +1040,7 @@ int rewriteAppendOnlyFile(char *filename) {
if (rioWriteBulkLongLong(&aof,expiretime) == 0) goto werr;
}
/* Read some diff from the parent process from time to time. */
- if (aof.processed_bytes > processed+REDIS_AOF_AUTOSYNC_BYTES) {
+ if (aof.processed_bytes > processed+1024*10) {
processed = aof.processed_bytes;
aofReadDiffFromParent();
}
@@ -1046,6 +1048,27 @@ int rewriteAppendOnlyFile(char *filename) {
dictReleaseIterator(di);
}
+ /* Do an initial slow fsync here while the parent is still sending
+ * data, in order to make the next final fsync faster. */
+ if (fflush(fp) == EOF) goto werr;
+ if (fsync(fileno(fp)) == -1) goto werr;
+
+ /* Read again a few times to get more data from the parent.
+ * We can't read forever (the server may receive data from clients
+ * fater than it is able to send data to the child), so we try to read
+ * some more data in a loop and wait a bit if data is not available, but
+ * don't wait more than 100 ms total. */
+ int nodata = 0;
+ for (j = 0; j < 100; j++) {
+ ssize_t nread_from_parent = aofReadDiffFromParent();
+ printf("%lld\n", (long long) nread_from_parent);
+ if (nread_from_parent == 0) {
+ nodata++;
+ if (nodata == 10) break;
+ usleep(10000);
+ }
+ }
+
/* Ask the master to stop sending diffs. */
if (write(server.aof_pipe_write_ack_to_parent,"!",1) != 1) goto werr;
if (anetNonBlock(NULL,server.aof_pipe_read_ack_from_parent) != ANET_OK)