A background append only file rewriting (BGREWRITEAOF) terminated its work. * Handle this. */
| 1972 | /* A background append only file rewriting (BGREWRITEAOF) terminated its work. |
| 1973 | * Handle this. */ |
| 1974 | void backgroundRewriteDoneHandler(int exitcode, int bysignal) { |
| 1975 | if (!bysignal && exitcode == 0) { |
| 1976 | int newfd, oldfd; |
| 1977 | char tmpfile[256]; |
| 1978 | long long now = ustime(); |
| 1979 | mstime_t latency; |
| 1980 | |
| 1981 | serverLog(LL_NOTICE, |
| 1982 | "Background AOF rewrite terminated with success"); |
| 1983 | |
| 1984 | /* Flush the differences accumulated by the parent to the |
| 1985 | * rewritten AOF. */ |
| 1986 | latencyStartMonitor(latency); |
| 1987 | snprintf(tmpfile,sizeof(tmpfile),"temp-rewriteaof-bg-%d.aof", |
| 1988 | (int)g_pserver->child_pid); |
| 1989 | newfd = open(tmpfile,O_WRONLY|O_APPEND); |
| 1990 | if (newfd == -1) { |
| 1991 | serverLog(LL_WARNING, |
| 1992 | "Unable to open the temporary AOF produced by the child: %s", strerror(errno)); |
| 1993 | goto cleanup; |
| 1994 | } |
| 1995 | |
| 1996 | if (aofRewriteBufferWrite(newfd) == -1) { |
| 1997 | serverLog(LL_WARNING, |
| 1998 | "Error trying to flush the parent diff to the rewritten AOF: %s", strerror(errno)); |
| 1999 | close(newfd); |
| 2000 | goto cleanup; |
| 2001 | } |
| 2002 | latencyEndMonitor(latency); |
| 2003 | latencyAddSampleIfNeeded("aof-rewrite-diff-write",latency); |
| 2004 | |
| 2005 | if (g_pserver->aof_fsync == AOF_FSYNC_EVERYSEC) { |
| 2006 | aof_background_fsync(newfd); |
| 2007 | } else if (g_pserver->aof_fsync == AOF_FSYNC_ALWAYS) { |
| 2008 | latencyStartMonitor(latency); |
| 2009 | if (redis_fsync(newfd) == -1) { |
| 2010 | serverLog(LL_WARNING, |
| 2011 | "Error trying to fsync the parent diff to the rewritten AOF: %s", strerror(errno)); |
| 2012 | close(newfd); |
| 2013 | goto cleanup; |
| 2014 | } |
| 2015 | latencyEndMonitor(latency); |
| 2016 | latencyAddSampleIfNeeded("aof-rewrite-done-fsync",latency); |
| 2017 | } |
| 2018 | |
| 2019 | serverLog(LL_NOTICE, |
| 2020 | "Residual parent diff successfully flushed to the rewritten AOF (%.2f MB)", (double) aofRewriteBufferSize() / (1024*1024)); |
| 2021 | |
| 2022 | /* The only remaining thing to do is to rename the temporary file to |
| 2023 | * the configured file and switch the file descriptor used to do AOF |
| 2024 | * writes. We don't want close(2) or rename(2) calls to block the |
| 2025 | * server on old file deletion. |
| 2026 | * |
| 2027 | * There are two possible scenarios: |
| 2028 | * |
| 2029 | * 1) AOF is DISABLED and this was a one time rewrite. The temporary |
| 2030 | * file will be renamed to the configured file. When this file already |
| 2031 | * exists, it will be unlinked, which may block the g_pserver-> |
no test coverage detected