Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
baaf869f
Commit
baaf869f
authored
Mar 04, 2020
by
antirez
Browse files
Introduce bg_unlink().
parent
be4bc1a5
Changes
1
Show whitespace changes
Inline
Side-by-side
src/replication.c
View file @
baaf869f
...
@@ -79,6 +79,34 @@ char *replicationGetSlaveName(client *c) {
...
@@ -79,6 +79,34 @@ char *replicationGetSlaveName(client *c) {
return buf;
return buf;
}
}
/* 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 not really do anything, and deleting the
* file will only happen once the last reference is lost. */
int bg_unlink(const char *filename) {
int fd = open(filename,O_RDONLY|O_NONBLOCK);
if (fd == -1) {
/* Can't open the file? Fall back to unlinking in the main thread. */
return unlink(filename);
} else {
/* The following unlink() will not do anything since file
* is still open. */
int retval = unlink(filename);
if (retval == -1) {
/* If we got an unlink error, we just return it, closing the
* new reference we have to the file. */
int old_errno = errno;
close(fd); /* This would overwrite our errno. So we saved it. */
errno = old_errno;
return -1;
}
bioCreateBackgroundJob(BIO_CLOSE_FILE,(void*)(long)fd,NULL,NULL);
return 0; /* Success. */
}
}
/* ---------------------------------- MASTER -------------------------------- */
/* ---------------------------------- MASTER -------------------------------- */
void createReplicationBacklog(void) {
void createReplicationBacklog(void) {
...
@@ -917,7 +945,7 @@ void removeRDBUsedToSyncReplicas(void) {
...
@@ -917,7 +945,7 @@ void removeRDBUsedToSyncReplicas(void) {
}
}
if (delrdb) {
if (delrdb) {
RDBGeneratedByReplication = 0;
RDBGeneratedByReplication = 0;
unlink
(
server
.
rdb_filename
);
bg_
unlink(server.rdb_filename);
}
}
}
}
}
}
...
@@ -1679,14 +1707,14 @@ void readSyncBulkPayload(connection *conn) {
...
@@ -1679,14 +1707,14 @@ void readSyncBulkPayload(connection *conn) {
"Failed trying to load the MASTER synchronization "
"Failed trying to load the MASTER synchronization "
"DB from disk");
"DB from disk");
cancelReplicationHandshake();
cancelReplicationHandshake();
if
(
allPersistenceDisabled
())
unlink
(
server
.
rdb_filename
);
if (allPersistenceDisabled())
bg_
unlink(server.rdb_filename);
/* Note that there's no point in restarting the AOF on sync failure,
/* Note that there's no point in restarting the AOF on sync failure,
it'll be restarted when sync succeeds or replica promoted. */
it'll be restarted when sync succeeds or replica promoted. */
return;
return;
}
}
/* Cleanup. */
/* Cleanup. */
if
(
allPersistenceDisabled
())
unlink
(
server
.
rdb_filename
);
if (allPersistenceDisabled())
bg_
unlink(server.rdb_filename);
zfree(server.repl_transfer_tmpfile);
zfree(server.repl_transfer_tmpfile);
close(server.repl_transfer_fd);
close(server.repl_transfer_fd);
server.repl_transfer_fd = -1;
server.repl_transfer_fd = -1;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment