Slaves heartbeats during sync improved.

The previous fix for false positive timeout detected by master was not
complete. There is another blocking stage while loading data for the
first synchronization with the master, that is, flushing away the
current data from the DB memory.

This commit uses the newly introduced dict.c callback in order to make
some incremental work (to send "\n" heartbeats to the master) while
flushing the old data from memory.

It is hard to write a regression test for this issue unfortunately. More
support for debugging in the Redis core would be needed in terms of
functionalities to simulate a slow DB loading / deletion.
This commit is contained in:
antirez
2013-12-10 18:38:26 +01:00
parent 2eb781b35b
commit 11120689c4
3 changed files with 29 additions and 15 deletions

View File

@ -1065,20 +1065,8 @@ void rdbLoadProgressCallback(rio *r, const void *buf, size_t len) {
if (server.loading_process_events_interval_bytes &&
(r->processed_bytes + len)/server.loading_process_events_interval_bytes > r->processed_bytes/server.loading_process_events_interval_bytes)
{
if (server.masterhost && server.repl_state == REDIS_REPL_TRANSFER) {
static time_t newline_sent;
/* Avoid the master to detect the slave is timing out while
* loading the RDB file in initial synchronization. We send
* a single newline character that is valid protocol but is
* guaranteed to either be sent entierly or not, since the byte
* is indivisible. */
if (time(NULL) != newline_sent) {
newline_sent = time(NULL);
if (write(server.repl_transfer_s,"\n",1) == -1) {
/* Pinging back in this stage is best-effort. */
}
}
}
if (server.masterhost && server.repl_state == REDIS_REPL_TRANSFER)
replicationSendNewlineToMaster();
loadingProgress(r->processed_bytes);
aeProcessEvents(server.el, AE_FILE_EVENTS|AE_DONT_WAIT);
}