MCPcopy Create free account
hub / github.com/F-Stack/f-stack / backgroundRewriteDoneHandler

Function backgroundRewriteDoneHandler

app/redis-6.2.6/src/aof.c:1851–2010  ·  view source on GitHub ↗

A background append only file rewriting (BGREWRITEAOF) terminated its work. * Handle this. */

Source from the content-addressed store, hash-verified

1849/* A background append only file rewriting (BGREWRITEAOF) terminated its work.
1850 * Handle this. */
1851void 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.

Callers 1

checkChildrenDoneFunction · 0.85

Calls 13

snprintfFunction · 0.85
aofRewriteBufferWriteFunction · 0.85
aof_background_fsyncFunction · 0.85
aofRewriteBufferSizeFunction · 0.85
aofUpdateCurrentSizeFunction · 0.85
sdsfreeFunction · 0.85
sdsemptyFunction · 0.85
bioCreateCloseJobFunction · 0.85
aofClosePipesFunction · 0.85
aofRewriteBufferResetFunction · 0.85
aofRemoveTempFileFunction · 0.85
ustimeFunction · 0.70

Tested by

no test coverage detected