Don't send more than 1 newline/sec while loading RDB.

This commit is contained in:
antirez 2013-12-10 17:49:45 +01:00
parent 27db38d069
commit 7c531eb5ad

View File

@ -1066,13 +1066,17 @@ void rdbLoadProgressCallback(rio *r, const void *buf, size_t len) {
(r->processed_bytes + len)/server.loading_process_events_interval_bytes > r->processed_bytes/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) { 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 /* Avoid the master to detect the slave is timing out while
* loading the RDB file in initial synchronization. We send * loading the RDB file in initial synchronization. We send
* a single newline character that is valid protocol but is * a single newline character that is valid protocol but is
* guaranteed to either be sent entierly or not, since the byte * guaranteed to either be sent entierly or not, since the byte
* is indivisible. */ * is indivisible. */
if (write(server.repl_transfer_s,"\n",1) == -1) { if (time(NULL) != newline_sent) {
/* Pinging back in this stage is best-effort. */ newline_sent = time(NULL);
if (write(server.repl_transfer_s,"\n",1) == -1) {
/* Pinging back in this stage is best-effort. */
}
} }
} }
loadingProgress(r->processed_bytes); loadingProgress(r->processed_bytes);