MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / bg_unlink

Function bg_unlink

src/replication.cpp:166–186  ·  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

164 * the foreground unlink() will only remove the fs name, and deleting the
165 * file's storage space will only happen once the last reference is lost. */
166int bg_unlink(const char *filename) {
167 int fd = open(filename,O_RDONLY|O_NONBLOCK);
168 if (fd == -1) {
169 /* Can't open the file? Fall back to unlinking in the main thread. */
170 return unlink(filename);
171 } else {
172 /* The following unlink() removes the name but doesn't free the
173 * file contents because a process still has it open. */
174 int retval = unlink(filename);
175 if (retval == -1) {
176 /* If we got an unlink error, we just return it, closing the
177 * new reference we have to the file. */
178 int old_errno = errno;
179 close(fd); /* This would overwrite our errno. So we saved it. */
180 errno = old_errno;
181 return -1;
182 }
183 bioCreateCloseJob(fd);
184 return 0; /* Success. */
185 }
186}
187
188/* ---------------------------------- MASTER -------------------------------- */
189

Callers 5

rdbRemoveTempFileFunction · 0.85
readSyncBulkPayloadRdbFunction · 0.85
aofRemoveTempFileFunction · 0.85

Calls 1

bioCreateCloseJobFunction · 0.85

Tested by

no test coverage detected