From 45e93245e4aa4db57679c9e2b95322c1744a4787 Mon Sep 17 00:00:00 2001
From: Yuriy Nevinitsin <nevinitsin@corp.mail.ru>
Date: Fri, 20 Sep 2013 19:40:35 +0300
Subject: [PATCH] fix snap_io_rate_limit handling

---
 src/recovery.cc  |  5 ++--
 src/tarantool.cc | 70 ++++++++++++++++++++++++++----------------------
 2 files changed, 41 insertions(+), 34 deletions(-)

diff --git a/src/recovery.cc b/src/recovery.cc
index 4e85b95ddc..79de90bf8b 100644
--- a/src/recovery.cc
+++ b/src/recovery.cc
@@ -1154,6 +1154,7 @@ snap_write_batch(struct fio_batch *batch, int fd)
 			  rows_written, batch->rows);
 		panic_syserror("fio_batch_write");
 	}
+    fdatasync(fd);
 }
 
 void
@@ -1179,7 +1180,8 @@ snapshot_write_row(struct log_io *l, struct fio_batch *batch,
 	if (++rows % 100000 == 0)
 		say_crit("%.1fM rows written", rows / 1000000.);
 
-	if (fio_batch_is_full(batch)) {
+    bytes += row_v11_size(row);
+	if (fio_batch_is_full(batch) || (recovery_state->snap_io_rate_limit > 0 && bytes >= recovery_state->snap_io_rate_limit)) {
 		snap_write_batch(batch, fileno(l->f));
 		fio_batch_start(batch, INT_MAX);
 		prelease_after(fiber->gc_pool, 128 * 1024);
@@ -1190,7 +1192,6 @@ snapshot_write_row(struct log_io *l, struct fio_batch *batch,
 			ev_now_update();
 			last = ev_now();
 		}
-		bytes += row_v11_size(row);
 		while (bytes >= recovery_state->snap_io_rate_limit) {
 
 			ev_now_update();
diff --git a/src/tarantool.cc b/src/tarantool.cc
index f467159a42..236c314aef 100644
--- a/src/tarantool.cc
+++ b/src/tarantool.cc
@@ -174,38 +174,44 @@ static int
 core_reload_config(const struct tarantool_cfg *old_conf,
 		   const struct tarantool_cfg *new_conf)
 {
-	if (strcasecmp(old_conf->wal_mode, new_conf->wal_mode) == 0 &&
-	    old_conf->wal_fsync_delay == new_conf->wal_fsync_delay)
-		return 0;
-
-	double new_delay = new_conf->wal_fsync_delay;
-
-	/* Mode has changed: */
-	if (strcasecmp(old_conf->wal_mode, new_conf->wal_mode)) {
-		if (strcasecmp(old_conf->wal_mode, "fsync") == 0 ||
-		    strcasecmp(new_conf->wal_mode, "fsync") == 0) {
-			out_warning(CNF_OK, "wal_mode cannot switch to/from fsync");
-			return -1;
-		}
-		say_debug("%s: wal_mode [%s] -> [%s]",
-			__func__, old_conf->wal_mode, new_conf->wal_mode);
-	}
-
-	/*
-	 * Unless wal_mode=fsync_delay, wal_fsync_delay is irrelevant and must be 0.
-	 */
-	if (strcasecmp(new_conf->wal_mode, "fsync_delay") != 0)
-		new_delay = 0.0;
-
-	if (old_conf->wal_fsync_delay != new_delay)
-		say_debug("%s: wal_fsync_delay [%f] -> [%f]",
-			__func__, old_conf->wal_fsync_delay, new_delay);
-
-	recovery_update_mode(recovery_state, new_conf->wal_mode, new_delay);
-
-	recovery_update_io_rate_limit(recovery_state, new_conf->snap_io_rate_limit);
-
-	ev_set_io_collect_interval(new_conf->io_collect_interval);
+	if (strcasecmp(old_conf->wal_mode, new_conf->wal_mode) != 0 ||
+	    old_conf->wal_fsync_delay != new_conf->wal_fsync_delay) {
+
+        double new_delay = new_conf->wal_fsync_delay;
+
+        /* Mode has changed: */
+        if (strcasecmp(old_conf->wal_mode, new_conf->wal_mode)) {
+            if (strcasecmp(old_conf->wal_mode, "fsync") == 0 ||
+                strcasecmp(new_conf->wal_mode, "fsync") == 0) {
+                out_warning(CNF_OK, "wal_mode cannot switch to/from fsync");
+                return -1;
+            }
+            say_debug("%s: wal_mode [%s] -> [%s]",
+                      __func__, old_conf->wal_mode, new_conf->wal_mode);
+        }
+
+        /*
+         * Unless wal_mode=fsync_delay, wal_fsync_delay is irrelevant and must be 0.
+         */
+        if (strcasecmp(new_conf->wal_mode, "fsync_delay") != 0)
+            new_delay = 0.0;
+
+        if (old_conf->wal_fsync_delay != new_delay)
+            say_debug("%s: wal_fsync_delay [%f] -> [%f]",
+                      __func__, old_conf->wal_fsync_delay, new_delay);
+
+        recovery_update_mode(recovery_state, new_conf->wal_mode, new_delay);
+    }
+
+    if(old_conf->snap_io_rate_limit != new_conf->snap_io_rate_limit) {
+        say_warn("snap_io_rate_limit changed: %f => %f", old_conf->snap_io_rate_limit, new_conf->snap_io_rate_limit);
+        recovery_update_io_rate_limit(recovery_state, new_conf->snap_io_rate_limit);
+    }
+
+    if(old_conf->io_collect_interval != new_conf->io_collect_interval) {
+        say_warn("io_collect_interval: %f => %f", old_conf->snap_io_rate_limit, new_conf->snap_io_rate_limit);
+        ev_set_io_collect_interval(new_conf->io_collect_interval);
+    }
 
 	return 0;
 }
-- 
GitLab