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
ca4ca507
Commit
ca4ca507
authored
Dec 16, 2016
by
Salvatore Sanfilippo
Committed by
GitHub
Dec 16, 2016
Browse files
Merge pull request #3616 from oranagra/stop_aofrw_before_rdbload
CoW improvement, stop AOFRW before flushing and parsing slave RDB
parents
151af731
e3a61950
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/replication.c
View file @
ca4ca507
...
...
@@ -1087,6 +1087,18 @@ void replicationCreateMasterClient(int fd, int dbid) {
if (dbid != -1) selectDb(server.master,dbid);
}
void restartAOF() {
int retry = 10;
while (retry-- && startAppendOnly() == C_ERR) {
serverLog(LL_WARNING,"Failed enabling the AOF after successful master synchronization! Trying it again in one second.");
sleep(1);
}
if (!retry) {
serverLog(LL_WARNING,"FATAL: this slave instance finished the synchronization with its master, but the AOF can't be turned on. Exiting now.");
exit(1);
}
}
/* Asynchronously read the SYNC payload we receive from a master */
#define REPL_MAX_WRITTEN_BEFORE_FSYNC (1024*1024*8) /* 8 MB */
void readSyncBulkPayload(aeEventLoop *el, int fd, void *privdata, int mask) {
...
...
@@ -1228,12 +1240,15 @@ void readSyncBulkPayload(aeEventLoop *el, int fd, void *privdata, int mask) {
}
if (eof_reached) {
int aof_is_enabled = server.aof_state != AOF_OFF;
if (rename(server.repl_transfer_tmpfile,server.rdb_filename) == -1) {
serverLog(LL_WARNING,"Failed trying to rename the temp DB into dump.rdb in MASTER <-> SLAVE synchronization: %s", strerror(errno));
cancelReplicationHandshake();
return;
}
serverLog(LL_NOTICE, "MASTER <-> SLAVE sync: Flushing old data");
if(aof_is_enabled) /* we need to stop any AOFRW fork before flusing and parsing RDB, otherwise we'll create a CoW disaster */
stopAppendOnly();
signalFlushedDb(-1);
emptyDb(
-1,
...
...
@@ -1249,6 +1264,8 @@ void readSyncBulkPayload(aeEventLoop *el, int fd, void *privdata, int mask) {
if (rdbLoad(server.rdb_filename,&rsi) != C_OK) {
serverLog(LL_WARNING,"Failed trying to load the MASTER synchronization DB from disk");
cancelReplicationHandshake();
if (aof_is_enabled) /* re-enable so that on the next attempt, we can detect that AOF was enabled */
restartAOF();
return;
}
/* Final setup of the connected slave <- master link */
...
...
@@ -1272,19 +1289,8 @@ void readSyncBulkPayload(aeEventLoop *el, int fd, void *privdata, int mask) {
/* Restart the AOF subsystem now that we finished the sync. This
* will trigger an AOF rewrite, and when done will start appending
* to the new file. */
if
(
server
.
aof_state
!=
AOF_OFF
)
{
int
retry
=
10
;
stopAppendOnly
();
while
(
retry
--
&&
startAppendOnly
()
==
C_ERR
)
{
serverLog
(
LL_WARNING
,
"Failed enabling the AOF after successful master synchronization! Trying it again in one second."
);
sleep
(
1
);
}
if
(
!
retry
)
{
serverLog
(
LL_WARNING
,
"FATAL: this slave instance finished the synchronization with its master, but the AOF can't be turned on. Exiting now."
);
exit
(
1
);
}
}
if (aof_is_enabled)
restartAOF();
}
return;
...
...
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