X-Git-Url: https://git.saurik.com/redis.git/blobdiff_plain/a3e60027e7d4419971406c6da7d6e8accbcaf9b0..cc209063904ed5d86a34b2297ceac00854ff6c01:/src/aof.c diff --git a/src/aof.c b/src/aof.c index dffe95ed..959a5f52 100644 --- a/src/aof.c +++ b/src/aof.c @@ -218,6 +218,7 @@ int loadAppendOnlyFile(char *filename) { FILE *fp = fopen(filename,"r"); struct redis_stat sb; int appendonly = server.appendonly; + long loops = 0; if (redis_fstat(fileno(fp),&sb) != -1 && sb.st_size == 0) return REDIS_ERR; @@ -232,6 +233,8 @@ int loadAppendOnlyFile(char *filename) { server.appendonly = 0; fakeClient = createFakeClient(); + startLoading(fp); + while(1) { int argc, j; unsigned long len; @@ -241,6 +244,12 @@ int loadAppendOnlyFile(char *filename) { struct redisCommand *cmd; int force_swapout; + /* Serve the clients from time to time */ + if (!(loops++ % 1000)) { + loadingProgress(ftello(fp)); + aeProcessEvents(server.el, AE_FILE_EVENTS|AE_DONT_WAIT); + } + if (fgets(buf,sizeof(buf),fp) == NULL) { if (feof(fp)) break; @@ -280,11 +289,11 @@ int loadAppendOnlyFile(char *filename) { /* Handle swapping while loading big datasets when VM is on */ force_swapout = 0; - if ((redisEstimateRSS() - server.vm_max_memory) > 1024*1024*32) + if ((zmalloc_used_memory() - server.vm_max_memory) > 1024*1024*32) force_swapout = 1; if (server.vm_enabled && force_swapout) { - while (redisEstimateRSS() > server.vm_max_memory) { + while (zmalloc_used_memory() > server.vm_max_memory) { if (vmSwapOneObjectBlocking() == REDIS_ERR) break; } } @@ -297,6 +306,7 @@ int loadAppendOnlyFile(char *filename) { fclose(fp); freeFakeClient(fakeClient); server.appendonly = appendonly; + stopLoading(); return REDIS_OK; readerr: @@ -549,7 +559,8 @@ int rewriteAppendOnlyFileBackground(void) { char tmpfile[256]; if (server.vm_enabled) vmReopenSwapFile(); - close(server.fd); + if (server.ipfd > 0) close(server.ipfd); + if (server.sofd > 0) close(server.sofd); snprintf(tmpfile,256,"temp-rewriteaof-bg-%d.aof", (int) getpid()); if (rewriteAppendOnlyFile(tmpfile) == REDIS_OK) { _exit(0);