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

Function bg_unlink

app/redis-6.2.6/src/replication.c:86–106  ·  view source on GitHub ↗

Plain unlink() can block for quite some time in order to actually apply * the file deletion to the filesystem. This call removes the file in a * background thread instead. We actually just do close() in the thread, * by using the fact that if there is another instance of the same file open, * the foreground unlink() will only remove the fs name, and deleting the * file's storage space will on

Source from the content-addressed store, hash-verified

84 * the foreground unlink() will only remove the fs name, and deleting the
85 * file's storage space will only happen once the last reference is lost. */
86int bg_unlink(const char *filename) {
87 int fd = open(filename,O_RDONLY|O_NONBLOCK);
88 if (fd == -1) {
89 /* Can't open the file? Fall back to unlinking in the main thread. */
90 return unlink(filename);
91 } else {
92 /* The following unlink() removes the name but doesn't free the
93 * file contents because a process still has it open. */
94 int retval = unlink(filename);
95 if (retval == -1) {
96 /* If we got an unlink error, we just return it, closing the
97 * new reference we have to the file. */
98 int old_errno = errno;
99 close(fd); /* This would overwrite our errno. So we saved it. */
100 errno = old_errno;
101 return -1;
102 }
103 bioCreateCloseJob(fd);
104 return 0; /* Success. */
105 }
106}
107
108/* ---------------------------------- MASTER -------------------------------- */
109

Callers 5

readSyncBulkPayloadFunction · 0.85
rdbRemoveTempFileFunction · 0.85
aofRemoveTempFileFunction · 0.85

Calls 2

bioCreateCloseJobFunction · 0.85
closeFunction · 0.70

Tested by

no test coverage detected