A background append only file rewriting (BGREWRITEAOF) terminated its work. * Handle this. */
| 1849 | /* A background append only file rewriting (BGREWRITEAOF) terminated its work. |
| 1850 | * Handle this. */ |
| 1851 | void backgroundRewriteDoneHandler(int exitcode, int bysignal) { |
| 1852 | if (!bysignal && exitcode == 0) { |
| 1853 | int newfd, oldfd; |
| 1854 | char tmpfile[256]; |
| 1855 | long long now = ustime(); |
| 1856 | mstime_t latency; |
| 1857 | |
| 1858 | serverLog(LL_NOTICE, |
| 1859 | "Background AOF rewrite terminated with success"); |
| 1860 | |
| 1861 | /* Flush the differences accumulated by the parent to the |
| 1862 | * rewritten AOF. */ |
| 1863 | latencyStartMonitor(latency); |
| 1864 | snprintf(tmpfile,256,"temp-rewriteaof-bg-%d.aof", |
| 1865 | (int)server.child_pid); |
| 1866 | newfd = open(tmpfile,O_WRONLY|O_APPEND); |
| 1867 | if (newfd == -1) { |
| 1868 | serverLog(LL_WARNING, |
| 1869 | "Unable to open the temporary AOF produced by the child: %s", strerror(errno)); |
| 1870 | goto cleanup; |
| 1871 | } |
| 1872 | |
| 1873 | if (aofRewriteBufferWrite(newfd) == -1) { |
| 1874 | serverLog(LL_WARNING, |
| 1875 | "Error trying to flush the parent diff to the rewritten AOF: %s", strerror(errno)); |
| 1876 | close(newfd); |
| 1877 | goto cleanup; |
| 1878 | } |
| 1879 | latencyEndMonitor(latency); |
| 1880 | latencyAddSampleIfNeeded("aof-rewrite-diff-write",latency); |
| 1881 | |
| 1882 | if (server.aof_fsync == AOF_FSYNC_EVERYSEC) { |
| 1883 | aof_background_fsync(newfd); |
| 1884 | } else if (server.aof_fsync == AOF_FSYNC_ALWAYS) { |
| 1885 | latencyStartMonitor(latency); |
| 1886 | if (redis_fsync(newfd) == -1) { |
| 1887 | serverLog(LL_WARNING, |
| 1888 | "Error trying to fsync the parent diff to the rewritten AOF: %s", strerror(errno)); |
| 1889 | close(newfd); |
| 1890 | goto cleanup; |
| 1891 | } |
| 1892 | latencyEndMonitor(latency); |
| 1893 | latencyAddSampleIfNeeded("aof-rewrite-done-fsync",latency); |
| 1894 | } |
| 1895 | |
| 1896 | serverLog(LL_NOTICE, |
| 1897 | "Residual parent diff successfully flushed to the rewritten AOF (%.2f MB)", (double) aofRewriteBufferSize() / (1024*1024)); |
| 1898 | |
| 1899 | /* The only remaining thing to do is to rename the temporary file to |
| 1900 | * the configured file and switch the file descriptor used to do AOF |
| 1901 | * writes. We don't want close(2) or rename(2) calls to block the |
| 1902 | * server on old file deletion. |
| 1903 | * |
| 1904 | * There are two possible scenarios: |
| 1905 | * |
| 1906 | * 1) AOF is DISABLED and this was a one time rewrite. The temporary |
| 1907 | * file will be renamed to the configured file. When this file already |
| 1908 | * exists, it will be unlinked, which may block the server. |
no test coverage detected