From 09d4e13d1e413b44cb89b7a6d86d55cc67496250 Mon Sep 17 00:00:00 2001
From: Konstantin Shulgin <konstantin.shulgin@gmail.com>
Date: Wed, 6 Jul 2011 15:26:07 +0400
Subject: [PATCH] Implement blueprint: 'feature-feeder-in-core'.

Missed inotify even in the replicaor handler process was foxed.
replicaor_init was splited on two function:
  - replicaor_prefork -- create replicaor spawner process;
  - replicaor_init -- initialize replicaor fibers in the main tarantool
	                  process.

Test and test configuration files in box_replication soute was
clenupped and updated.
---
 core/replicator.m                             |  45 +-
 core/tarantool.m                              |   4 +-
 include/replicator.h                          |   8 +-
 test/box_replication/cfg/hot_standby.cfg      |   4 +-
 test/box_replication/cfg/master.cfg           |   4 +-
 .../box_replication/cfg/master_to_replica.cfg |   3 +-
 test/box_replication/cfg/replica.cfg          |   3 +-
 .../box_replication/cfg/replica_to_master.cfg |   3 +-
 test/box_replication/hot_standby.test         |   4 +-
 test/box_replication/swap.result              | 400 +++++++++---------
 test/box_replication/swap.test                |  21 +-
 test/lib/tarantool_box_server.py              |   3 +-
 12 files changed, 259 insertions(+), 243 deletions(-)

diff --git a/core/replicator.m b/core/replicator.m
index 9cedcb2fa3..4a661ff885 100644
--- a/core/replicator.m
+++ b/core/replicator.m
@@ -52,17 +52,12 @@ struct replicator_process {
 	u32 child_count;
 };
 
+static int replicator_socks[2];
 
 /*-----------------------------------------------------------------------------*/
 /* replication accept/sender fibers                                            */
 /*-----------------------------------------------------------------------------*/
 
-/**
- * Initialize replication fibers.
- */
-static void
-fibers_init(int sock);
-
 /**
  * Replication acceptor fiber handler.
  */
@@ -201,13 +196,10 @@ void
 replicator_reload_config(struct tarantool_cfg *config __attribute__((unused)))
 {}
 
-/** Intialize tarantool's replicator module. */
+/** Pre-fork replicator spawner process. */
 void
-replicator_init(void)
+replicator_prefork()
 {
-	int socks[2];
-	pid_t pid = -1;
-
 	if (cfg.replication_port == 0) {
 		/* replicator not needed, leave init function */
 		return;
@@ -218,35 +210,29 @@ replicator_init(void)
 	}
 
 	/* create communication sockes between tarantool and replicator processes via UNIX sockets*/
-	if (socketpair(PF_LOCAL, SOCK_STREAM, 0, socks) != 0) {
+	if (socketpair(PF_LOCAL, SOCK_STREAM, 0, replicator_socks) != 0) {
 		panic_syserror("socketpair");
 	}
 
 	/* create replicator process */
-	pid = fork();
+	pid_t pid = fork();
 	if (pid == -1) {
-		panic("fork");
+		panic_syserror("fork");
 	}
 
 	if (pid != 0) {
 		/* parent process: tarantool */
-		close(socks[1]);
-		fibers_init(socks[0]);
+		close(replicator_socks[1]);
 	} else {
 		/* child process: replicator */
-		close(socks[0]);
-		spawner_init(socks[1]);
+		close(replicator_socks[0]);
+		spawner_init(replicator_socks[1]);
 	}
 }
 
-
-/*-----------------------------------------------------------------------------*/
-/* replication accept/sender fibers                                            */
-/*-----------------------------------------------------------------------------*/
-
-/** Initialize replication fibers. */
-static void
-fibers_init(int sock)
+/** Intialize tarantool's replicator module. */
+void
+replicator_init()
 {
 	char fiber_name[FIBER_NAME_MAXLEN];
 	const size_t sender_inbox_size = 16 * sizeof(int);
@@ -258,7 +244,7 @@ fibers_init(int sock)
 		panic("snprintf fail");
 	}
 
-	sender = fiber_create(fiber_name, sock, sender_inbox_size, sender_handler, NULL);
+	sender = fiber_create(fiber_name, replicator_socks[0], sender_inbox_size, sender_handler, NULL);
 	if (sender == NULL) {
 		panic("create fiber fail");
 	}
@@ -277,6 +263,11 @@ fibers_init(int sock)
 	fiber_call(sender);
 }
 
+
+/*-----------------------------------------------------------------------------*/
+/* replication accept/sender fibers                                            */
+/*-----------------------------------------------------------------------------*/
+
 /** Replication acceptor fiber handler. */
 static void
 acceptor_handler(void *data)
diff --git a/core/tarantool.m b/core/tarantool.m
index ad80f96cc3..900ebb8a86 100644
--- a/core/tarantool.m
+++ b/core/tarantool.m
@@ -539,6 +539,9 @@ main(int argc, char **argv)
 	say_logger_init(cfg.logger_nonblock);
 	booting = false;
 
+	initialize(cfg.slab_alloc_arena, cfg.slab_alloc_minimal, cfg.slab_alloc_factor);
+	replicator_prefork();
+
 	ev_default_loop(EVFLAG_AUTO);
 
 	ev_signal *ev_sig;
@@ -546,7 +549,6 @@ main(int argc, char **argv)
 	ev_signal_init(ev_sig, (void *)snapshot, SIGUSR1);
 	ev_signal_start(ev_sig);
 
-	initialize(cfg.slab_alloc_arena, cfg.slab_alloc_minimal, cfg.slab_alloc_factor);
 	signal_init();
 
 	replicator_init();
diff --git a/include/replicator.h b/include/replicator.h
index f63386ac32..191a7a1101 100644
--- a/include/replicator.h
+++ b/include/replicator.h
@@ -46,13 +46,19 @@ replicator_check_config(struct tarantool_cfg *config);
 void
 replicator_reload_config(struct tarantool_cfg *config);
 
+/**
+ * Pre-fork replicator spawner process.
+ */
+void
+replicator_prefork();
+
 /**
  * Intialize tarantool's replicator module.
  *
  * @return On success, a zero is returned. On error, -1 is returned.
  */
 void
-replicator_init(void);
+replicator_init();
 
 #endif // !defined(REPLICATOR_H_INCLUDED)
 
diff --git a/test/box_replication/cfg/hot_standby.cfg b/test/box_replication/cfg/hot_standby.cfg
index 62cdda8f96..e96b873050 100644
--- a/test/box_replication/cfg/hot_standby.cfg
+++ b/test/box_replication/cfg/hot_standby.cfg
@@ -1,5 +1,7 @@
 pid_file = "tarantool.pid"
-logger="tee -a tarantool.log"
+logger="cat - >> tarantool.log"
+logger_nonblock=0
+log_level = 5
 
 bind_ipaddr="INADDR_ANY"
 
diff --git a/test/box_replication/cfg/master.cfg b/test/box_replication/cfg/master.cfg
index 72636b6b0c..204d6236ad 100644
--- a/test/box_replication/cfg/master.cfg
+++ b/test/box_replication/cfg/master.cfg
@@ -1,5 +1,6 @@
 pid_file = "tarantool.pid"
-logger="tee -a tarantool.log"
+logger="cat - >> tarantool.log"
+logger_nonblock=0
 log_level = 5
 
 bind_ipaddr="INADDR_ANY"
@@ -16,3 +17,4 @@ namespace[0].index[0].type = "HASH"
 namespace[0].index[0].unique = 1
 namespace[0].index[0].key_field[0].fieldno = 0
 namespace[0].index[0].key_field[0].type = "NUM"
+
diff --git a/test/box_replication/cfg/master_to_replica.cfg b/test/box_replication/cfg/master_to_replica.cfg
index 9efc6f223a..70070fae32 100644
--- a/test/box_replication/cfg/master_to_replica.cfg
+++ b/test/box_replication/cfg/master_to_replica.cfg
@@ -1,5 +1,6 @@
 pid_file = "tarantool.pid"
-logger="tee -a tarantool.log"
+logger="cat - >> tarantool.log"
+logger_nonblock=0
 log_level = 5
 
 bind_ipaddr="INADDR_ANY"
diff --git a/test/box_replication/cfg/replica.cfg b/test/box_replication/cfg/replica.cfg
index 37877b2f06..a6c522a572 100644
--- a/test/box_replication/cfg/replica.cfg
+++ b/test/box_replication/cfg/replica.cfg
@@ -1,5 +1,6 @@
 pid_file = "tarantool.pid"
-logger="tee -a tarantool.log"
+logger="cat - >> tarantool.log"
+logger_nonblock=0
 log_level = 5
 
 bind_ipaddr="INADDR_ANY"
diff --git a/test/box_replication/cfg/replica_to_master.cfg b/test/box_replication/cfg/replica_to_master.cfg
index 6581868639..1e1b32f787 100644
--- a/test/box_replication/cfg/replica_to_master.cfg
+++ b/test/box_replication/cfg/replica_to_master.cfg
@@ -1,5 +1,6 @@
 pid_file = "tarantool.pid"
-logger="tee -a tarantool.log"
+logger="cat - >> tarantool.log"
+logger_nonblock=0
 log_level = 5
 
 bind_ipaddr="INADDR_ANY"
diff --git a/test/box_replication/hot_standby.test b/test/box_replication/hot_standby.test
index 3e531a5f6a..b1053fb5d8 100644
--- a/test/box_replication/hot_standby.test
+++ b/test/box_replication/hot_standby.test
@@ -38,7 +38,7 @@ for i in range(id, id + 10):
 print """
 # Select 10 tuples from replica
 """
-replica.wait_lsn(10)
+replica.wait_lsn(11)
 for i in range(id, id + 10):
     replica.sql.execute("select * from t0 where k0 = %d" % i, silent=False)
 
@@ -70,7 +70,7 @@ for i in range(id, id + 10):
 print """
 # Select 10 tuples from replica
 """
-replica.wait_lsn(20)
+replica.wait_lsn(21)
 for i in range(id, id + 10):
     replica.sql.execute("select * from t0 where k0 = %d" % i, silent=False)
 
diff --git a/test/box_replication/swap.result b/test/box_replication/swap.result
index 87c37d5de6..69e9d640ff 100644
--- a/test/box_replication/swap.result
+++ b/test/box_replication/swap.result
@@ -9,16 +9,6 @@ insert into t0 values (3, 'tuple 3')
 Insert OK, 1 row affected
 insert into t0 values (4, 'tuple 4')
 Insert OK, 1 row affected
-insert into t0 values (5, 'tuple 5')
-Insert OK, 1 row affected
-insert into t0 values (6, 'tuple 6')
-Insert OK, 1 row affected
-insert into t0 values (7, 'tuple 7')
-Insert OK, 1 row affected
-insert into t0 values (8, 'tuple 8')
-Insert OK, 1 row affected
-insert into t0 values (9, 'tuple 9')
-Insert OK, 1 row affected
 select * from t0 where k0 = 0
 Found 1 tuple:
 [0, 'tuple 0']
@@ -34,6 +24,16 @@ Found 1 tuple:
 select * from t0 where k0 = 4
 Found 1 tuple:
 [4, 'tuple 4']
+insert into t0 values (5, 'tuple 5')
+Insert OK, 1 row affected
+insert into t0 values (6, 'tuple 6')
+Insert OK, 1 row affected
+insert into t0 values (7, 'tuple 7')
+Insert OK, 1 row affected
+insert into t0 values (8, 'tuple 8')
+Insert OK, 1 row affected
+insert into t0 values (9, 'tuple 9')
+Insert OK, 1 row affected
 select * from t0 where k0 = 5
 Found 1 tuple:
 [5, 'tuple 5']
@@ -68,16 +68,6 @@ insert into t0 values (13, 'tuple 13')
 Insert OK, 1 row affected
 insert into t0 values (14, 'tuple 14')
 Insert OK, 1 row affected
-insert into t0 values (15, 'tuple 15')
-Insert OK, 1 row affected
-insert into t0 values (16, 'tuple 16')
-Insert OK, 1 row affected
-insert into t0 values (17, 'tuple 17')
-Insert OK, 1 row affected
-insert into t0 values (18, 'tuple 18')
-Insert OK, 1 row affected
-insert into t0 values (19, 'tuple 19')
-Insert OK, 1 row affected
 select * from t0 where k0 = 10
 Found 1 tuple:
 [10, 'tuple 10']
@@ -93,6 +83,16 @@ Found 1 tuple:
 select * from t0 where k0 = 14
 Found 1 tuple:
 [14, 'tuple 14']
+insert into t0 values (15, 'tuple 15')
+Insert OK, 1 row affected
+insert into t0 values (16, 'tuple 16')
+Insert OK, 1 row affected
+insert into t0 values (17, 'tuple 17')
+Insert OK, 1 row affected
+insert into t0 values (18, 'tuple 18')
+Insert OK, 1 row affected
+insert into t0 values (19, 'tuple 19')
+Insert OK, 1 row affected
 select * from t0 where k0 = 15
 Found 1 tuple:
 [15, 'tuple 15']
@@ -128,16 +128,6 @@ insert into t0 values (23, 'tuple 23')
 Insert OK, 1 row affected
 insert into t0 values (24, 'tuple 24')
 Insert OK, 1 row affected
-insert into t0 values (25, 'tuple 25')
-Insert OK, 1 row affected
-insert into t0 values (26, 'tuple 26')
-Insert OK, 1 row affected
-insert into t0 values (27, 'tuple 27')
-Insert OK, 1 row affected
-insert into t0 values (28, 'tuple 28')
-Insert OK, 1 row affected
-insert into t0 values (29, 'tuple 29')
-Insert OK, 1 row affected
 select * from t0 where k0 = 20
 Found 1 tuple:
 [20, 'tuple 20']
@@ -153,6 +143,16 @@ Found 1 tuple:
 select * from t0 where k0 = 24
 Found 1 tuple:
 [24, 'tuple 24']
+insert into t0 values (25, 'tuple 25')
+Insert OK, 1 row affected
+insert into t0 values (26, 'tuple 26')
+Insert OK, 1 row affected
+insert into t0 values (27, 'tuple 27')
+Insert OK, 1 row affected
+insert into t0 values (28, 'tuple 28')
+Insert OK, 1 row affected
+insert into t0 values (29, 'tuple 29')
+Insert OK, 1 row affected
 select * from t0 where k0 = 25
 Found 1 tuple:
 [25, 'tuple 25']
@@ -187,16 +187,6 @@ insert into t0 values (33, 'tuple 33')
 Insert OK, 1 row affected
 insert into t0 values (34, 'tuple 34')
 Insert OK, 1 row affected
-insert into t0 values (35, 'tuple 35')
-Insert OK, 1 row affected
-insert into t0 values (36, 'tuple 36')
-Insert OK, 1 row affected
-insert into t0 values (37, 'tuple 37')
-Insert OK, 1 row affected
-insert into t0 values (38, 'tuple 38')
-Insert OK, 1 row affected
-insert into t0 values (39, 'tuple 39')
-Insert OK, 1 row affected
 select * from t0 where k0 = 30
 Found 1 tuple:
 [30, 'tuple 30']
@@ -212,6 +202,16 @@ Found 1 tuple:
 select * from t0 where k0 = 34
 Found 1 tuple:
 [34, 'tuple 34']
+insert into t0 values (35, 'tuple 35')
+Insert OK, 1 row affected
+insert into t0 values (36, 'tuple 36')
+Insert OK, 1 row affected
+insert into t0 values (37, 'tuple 37')
+Insert OK, 1 row affected
+insert into t0 values (38, 'tuple 38')
+Insert OK, 1 row affected
+insert into t0 values (39, 'tuple 39')
+Insert OK, 1 row affected
 select * from t0 where k0 = 35
 Found 1 tuple:
 [35, 'tuple 35']
@@ -247,16 +247,6 @@ insert into t0 values (43, 'tuple 43')
 Insert OK, 1 row affected
 insert into t0 values (44, 'tuple 44')
 Insert OK, 1 row affected
-insert into t0 values (45, 'tuple 45')
-Insert OK, 1 row affected
-insert into t0 values (46, 'tuple 46')
-Insert OK, 1 row affected
-insert into t0 values (47, 'tuple 47')
-Insert OK, 1 row affected
-insert into t0 values (48, 'tuple 48')
-Insert OK, 1 row affected
-insert into t0 values (49, 'tuple 49')
-Insert OK, 1 row affected
 select * from t0 where k0 = 40
 Found 1 tuple:
 [40, 'tuple 40']
@@ -272,6 +262,16 @@ Found 1 tuple:
 select * from t0 where k0 = 44
 Found 1 tuple:
 [44, 'tuple 44']
+insert into t0 values (45, 'tuple 45')
+Insert OK, 1 row affected
+insert into t0 values (46, 'tuple 46')
+Insert OK, 1 row affected
+insert into t0 values (47, 'tuple 47')
+Insert OK, 1 row affected
+insert into t0 values (48, 'tuple 48')
+Insert OK, 1 row affected
+insert into t0 values (49, 'tuple 49')
+Insert OK, 1 row affected
 select * from t0 where k0 = 45
 Found 1 tuple:
 [45, 'tuple 45']
@@ -306,16 +306,6 @@ insert into t0 values (53, 'tuple 53')
 Insert OK, 1 row affected
 insert into t0 values (54, 'tuple 54')
 Insert OK, 1 row affected
-insert into t0 values (55, 'tuple 55')
-Insert OK, 1 row affected
-insert into t0 values (56, 'tuple 56')
-Insert OK, 1 row affected
-insert into t0 values (57, 'tuple 57')
-Insert OK, 1 row affected
-insert into t0 values (58, 'tuple 58')
-Insert OK, 1 row affected
-insert into t0 values (59, 'tuple 59')
-Insert OK, 1 row affected
 select * from t0 where k0 = 50
 Found 1 tuple:
 [50, 'tuple 50']
@@ -331,6 +321,16 @@ Found 1 tuple:
 select * from t0 where k0 = 54
 Found 1 tuple:
 [54, 'tuple 54']
+insert into t0 values (55, 'tuple 55')
+Insert OK, 1 row affected
+insert into t0 values (56, 'tuple 56')
+Insert OK, 1 row affected
+insert into t0 values (57, 'tuple 57')
+Insert OK, 1 row affected
+insert into t0 values (58, 'tuple 58')
+Insert OK, 1 row affected
+insert into t0 values (59, 'tuple 59')
+Insert OK, 1 row affected
 select * from t0 where k0 = 55
 Found 1 tuple:
 [55, 'tuple 55']
@@ -366,16 +366,6 @@ insert into t0 values (63, 'tuple 63')
 Insert OK, 1 row affected
 insert into t0 values (64, 'tuple 64')
 Insert OK, 1 row affected
-insert into t0 values (65, 'tuple 65')
-Insert OK, 1 row affected
-insert into t0 values (66, 'tuple 66')
-Insert OK, 1 row affected
-insert into t0 values (67, 'tuple 67')
-Insert OK, 1 row affected
-insert into t0 values (68, 'tuple 68')
-Insert OK, 1 row affected
-insert into t0 values (69, 'tuple 69')
-Insert OK, 1 row affected
 select * from t0 where k0 = 60
 Found 1 tuple:
 [60, 'tuple 60']
@@ -391,6 +381,16 @@ Found 1 tuple:
 select * from t0 where k0 = 64
 Found 1 tuple:
 [64, 'tuple 64']
+insert into t0 values (65, 'tuple 65')
+Insert OK, 1 row affected
+insert into t0 values (66, 'tuple 66')
+Insert OK, 1 row affected
+insert into t0 values (67, 'tuple 67')
+Insert OK, 1 row affected
+insert into t0 values (68, 'tuple 68')
+Insert OK, 1 row affected
+insert into t0 values (69, 'tuple 69')
+Insert OK, 1 row affected
 select * from t0 where k0 = 65
 Found 1 tuple:
 [65, 'tuple 65']
@@ -425,16 +425,6 @@ insert into t0 values (73, 'tuple 73')
 Insert OK, 1 row affected
 insert into t0 values (74, 'tuple 74')
 Insert OK, 1 row affected
-insert into t0 values (75, 'tuple 75')
-Insert OK, 1 row affected
-insert into t0 values (76, 'tuple 76')
-Insert OK, 1 row affected
-insert into t0 values (77, 'tuple 77')
-Insert OK, 1 row affected
-insert into t0 values (78, 'tuple 78')
-Insert OK, 1 row affected
-insert into t0 values (79, 'tuple 79')
-Insert OK, 1 row affected
 select * from t0 where k0 = 70
 Found 1 tuple:
 [70, 'tuple 70']
@@ -450,6 +440,16 @@ Found 1 tuple:
 select * from t0 where k0 = 74
 Found 1 tuple:
 [74, 'tuple 74']
+insert into t0 values (75, 'tuple 75')
+Insert OK, 1 row affected
+insert into t0 values (76, 'tuple 76')
+Insert OK, 1 row affected
+insert into t0 values (77, 'tuple 77')
+Insert OK, 1 row affected
+insert into t0 values (78, 'tuple 78')
+Insert OK, 1 row affected
+insert into t0 values (79, 'tuple 79')
+Insert OK, 1 row affected
 select * from t0 where k0 = 75
 Found 1 tuple:
 [75, 'tuple 75']
@@ -485,16 +485,6 @@ insert into t0 values (83, 'tuple 83')
 Insert OK, 1 row affected
 insert into t0 values (84, 'tuple 84')
 Insert OK, 1 row affected
-insert into t0 values (85, 'tuple 85')
-Insert OK, 1 row affected
-insert into t0 values (86, 'tuple 86')
-Insert OK, 1 row affected
-insert into t0 values (87, 'tuple 87')
-Insert OK, 1 row affected
-insert into t0 values (88, 'tuple 88')
-Insert OK, 1 row affected
-insert into t0 values (89, 'tuple 89')
-Insert OK, 1 row affected
 select * from t0 where k0 = 80
 Found 1 tuple:
 [80, 'tuple 80']
@@ -510,6 +500,16 @@ Found 1 tuple:
 select * from t0 where k0 = 84
 Found 1 tuple:
 [84, 'tuple 84']
+insert into t0 values (85, 'tuple 85')
+Insert OK, 1 row affected
+insert into t0 values (86, 'tuple 86')
+Insert OK, 1 row affected
+insert into t0 values (87, 'tuple 87')
+Insert OK, 1 row affected
+insert into t0 values (88, 'tuple 88')
+Insert OK, 1 row affected
+insert into t0 values (89, 'tuple 89')
+Insert OK, 1 row affected
 select * from t0 where k0 = 85
 Found 1 tuple:
 [85, 'tuple 85']
@@ -544,16 +544,6 @@ insert into t0 values (93, 'tuple 93')
 Insert OK, 1 row affected
 insert into t0 values (94, 'tuple 94')
 Insert OK, 1 row affected
-insert into t0 values (95, 'tuple 95')
-Insert OK, 1 row affected
-insert into t0 values (96, 'tuple 96')
-Insert OK, 1 row affected
-insert into t0 values (97, 'tuple 97')
-Insert OK, 1 row affected
-insert into t0 values (98, 'tuple 98')
-Insert OK, 1 row affected
-insert into t0 values (99, 'tuple 99')
-Insert OK, 1 row affected
 select * from t0 where k0 = 90
 Found 1 tuple:
 [90, 'tuple 90']
@@ -569,6 +559,16 @@ Found 1 tuple:
 select * from t0 where k0 = 94
 Found 1 tuple:
 [94, 'tuple 94']
+insert into t0 values (95, 'tuple 95')
+Insert OK, 1 row affected
+insert into t0 values (96, 'tuple 96')
+Insert OK, 1 row affected
+insert into t0 values (97, 'tuple 97')
+Insert OK, 1 row affected
+insert into t0 values (98, 'tuple 98')
+Insert OK, 1 row affected
+insert into t0 values (99, 'tuple 99')
+Insert OK, 1 row affected
 select * from t0 where k0 = 95
 Found 1 tuple:
 [95, 'tuple 95']
@@ -604,16 +604,6 @@ insert into t0 values (103, 'tuple 103')
 Insert OK, 1 row affected
 insert into t0 values (104, 'tuple 104')
 Insert OK, 1 row affected
-insert into t0 values (105, 'tuple 105')
-Insert OK, 1 row affected
-insert into t0 values (106, 'tuple 106')
-Insert OK, 1 row affected
-insert into t0 values (107, 'tuple 107')
-Insert OK, 1 row affected
-insert into t0 values (108, 'tuple 108')
-Insert OK, 1 row affected
-insert into t0 values (109, 'tuple 109')
-Insert OK, 1 row affected
 select * from t0 where k0 = 100
 Found 1 tuple:
 [100, 'tuple 100']
@@ -629,6 +619,16 @@ Found 1 tuple:
 select * from t0 where k0 = 104
 Found 1 tuple:
 [104, 'tuple 104']
+insert into t0 values (105, 'tuple 105')
+Insert OK, 1 row affected
+insert into t0 values (106, 'tuple 106')
+Insert OK, 1 row affected
+insert into t0 values (107, 'tuple 107')
+Insert OK, 1 row affected
+insert into t0 values (108, 'tuple 108')
+Insert OK, 1 row affected
+insert into t0 values (109, 'tuple 109')
+Insert OK, 1 row affected
 select * from t0 where k0 = 105
 Found 1 tuple:
 [105, 'tuple 105']
@@ -663,16 +663,6 @@ insert into t0 values (113, 'tuple 113')
 Insert OK, 1 row affected
 insert into t0 values (114, 'tuple 114')
 Insert OK, 1 row affected
-insert into t0 values (115, 'tuple 115')
-Insert OK, 1 row affected
-insert into t0 values (116, 'tuple 116')
-Insert OK, 1 row affected
-insert into t0 values (117, 'tuple 117')
-Insert OK, 1 row affected
-insert into t0 values (118, 'tuple 118')
-Insert OK, 1 row affected
-insert into t0 values (119, 'tuple 119')
-Insert OK, 1 row affected
 select * from t0 where k0 = 110
 Found 1 tuple:
 [110, 'tuple 110']
@@ -688,6 +678,16 @@ Found 1 tuple:
 select * from t0 where k0 = 114
 Found 1 tuple:
 [114, 'tuple 114']
+insert into t0 values (115, 'tuple 115')
+Insert OK, 1 row affected
+insert into t0 values (116, 'tuple 116')
+Insert OK, 1 row affected
+insert into t0 values (117, 'tuple 117')
+Insert OK, 1 row affected
+insert into t0 values (118, 'tuple 118')
+Insert OK, 1 row affected
+insert into t0 values (119, 'tuple 119')
+Insert OK, 1 row affected
 select * from t0 where k0 = 115
 Found 1 tuple:
 [115, 'tuple 115']
@@ -723,16 +723,6 @@ insert into t0 values (123, 'tuple 123')
 Insert OK, 1 row affected
 insert into t0 values (124, 'tuple 124')
 Insert OK, 1 row affected
-insert into t0 values (125, 'tuple 125')
-Insert OK, 1 row affected
-insert into t0 values (126, 'tuple 126')
-Insert OK, 1 row affected
-insert into t0 values (127, 'tuple 127')
-Insert OK, 1 row affected
-insert into t0 values (128, 'tuple 128')
-Insert OK, 1 row affected
-insert into t0 values (129, 'tuple 129')
-Insert OK, 1 row affected
 select * from t0 where k0 = 120
 Found 1 tuple:
 [120, 'tuple 120']
@@ -748,6 +738,16 @@ Found 1 tuple:
 select * from t0 where k0 = 124
 Found 1 tuple:
 [124, 'tuple 124']
+insert into t0 values (125, 'tuple 125')
+Insert OK, 1 row affected
+insert into t0 values (126, 'tuple 126')
+Insert OK, 1 row affected
+insert into t0 values (127, 'tuple 127')
+Insert OK, 1 row affected
+insert into t0 values (128, 'tuple 128')
+Insert OK, 1 row affected
+insert into t0 values (129, 'tuple 129')
+Insert OK, 1 row affected
 select * from t0 where k0 = 125
 Found 1 tuple:
 [125, 'tuple 125']
@@ -782,16 +782,6 @@ insert into t0 values (133, 'tuple 133')
 Insert OK, 1 row affected
 insert into t0 values (134, 'tuple 134')
 Insert OK, 1 row affected
-insert into t0 values (135, 'tuple 135')
-Insert OK, 1 row affected
-insert into t0 values (136, 'tuple 136')
-Insert OK, 1 row affected
-insert into t0 values (137, 'tuple 137')
-Insert OK, 1 row affected
-insert into t0 values (138, 'tuple 138')
-Insert OK, 1 row affected
-insert into t0 values (139, 'tuple 139')
-Insert OK, 1 row affected
 select * from t0 where k0 = 130
 Found 1 tuple:
 [130, 'tuple 130']
@@ -807,6 +797,16 @@ Found 1 tuple:
 select * from t0 where k0 = 134
 Found 1 tuple:
 [134, 'tuple 134']
+insert into t0 values (135, 'tuple 135')
+Insert OK, 1 row affected
+insert into t0 values (136, 'tuple 136')
+Insert OK, 1 row affected
+insert into t0 values (137, 'tuple 137')
+Insert OK, 1 row affected
+insert into t0 values (138, 'tuple 138')
+Insert OK, 1 row affected
+insert into t0 values (139, 'tuple 139')
+Insert OK, 1 row affected
 select * from t0 where k0 = 135
 Found 1 tuple:
 [135, 'tuple 135']
@@ -842,16 +842,6 @@ insert into t0 values (143, 'tuple 143')
 Insert OK, 1 row affected
 insert into t0 values (144, 'tuple 144')
 Insert OK, 1 row affected
-insert into t0 values (145, 'tuple 145')
-Insert OK, 1 row affected
-insert into t0 values (146, 'tuple 146')
-Insert OK, 1 row affected
-insert into t0 values (147, 'tuple 147')
-Insert OK, 1 row affected
-insert into t0 values (148, 'tuple 148')
-Insert OK, 1 row affected
-insert into t0 values (149, 'tuple 149')
-Insert OK, 1 row affected
 select * from t0 where k0 = 140
 Found 1 tuple:
 [140, 'tuple 140']
@@ -867,6 +857,16 @@ Found 1 tuple:
 select * from t0 where k0 = 144
 Found 1 tuple:
 [144, 'tuple 144']
+insert into t0 values (145, 'tuple 145')
+Insert OK, 1 row affected
+insert into t0 values (146, 'tuple 146')
+Insert OK, 1 row affected
+insert into t0 values (147, 'tuple 147')
+Insert OK, 1 row affected
+insert into t0 values (148, 'tuple 148')
+Insert OK, 1 row affected
+insert into t0 values (149, 'tuple 149')
+Insert OK, 1 row affected
 select * from t0 where k0 = 145
 Found 1 tuple:
 [145, 'tuple 145']
@@ -901,16 +901,6 @@ insert into t0 values (153, 'tuple 153')
 Insert OK, 1 row affected
 insert into t0 values (154, 'tuple 154')
 Insert OK, 1 row affected
-insert into t0 values (155, 'tuple 155')
-Insert OK, 1 row affected
-insert into t0 values (156, 'tuple 156')
-Insert OK, 1 row affected
-insert into t0 values (157, 'tuple 157')
-Insert OK, 1 row affected
-insert into t0 values (158, 'tuple 158')
-Insert OK, 1 row affected
-insert into t0 values (159, 'tuple 159')
-Insert OK, 1 row affected
 select * from t0 where k0 = 150
 Found 1 tuple:
 [150, 'tuple 150']
@@ -926,6 +916,16 @@ Found 1 tuple:
 select * from t0 where k0 = 154
 Found 1 tuple:
 [154, 'tuple 154']
+insert into t0 values (155, 'tuple 155')
+Insert OK, 1 row affected
+insert into t0 values (156, 'tuple 156')
+Insert OK, 1 row affected
+insert into t0 values (157, 'tuple 157')
+Insert OK, 1 row affected
+insert into t0 values (158, 'tuple 158')
+Insert OK, 1 row affected
+insert into t0 values (159, 'tuple 159')
+Insert OK, 1 row affected
 select * from t0 where k0 = 155
 Found 1 tuple:
 [155, 'tuple 155']
@@ -961,16 +961,6 @@ insert into t0 values (163, 'tuple 163')
 Insert OK, 1 row affected
 insert into t0 values (164, 'tuple 164')
 Insert OK, 1 row affected
-insert into t0 values (165, 'tuple 165')
-Insert OK, 1 row affected
-insert into t0 values (166, 'tuple 166')
-Insert OK, 1 row affected
-insert into t0 values (167, 'tuple 167')
-Insert OK, 1 row affected
-insert into t0 values (168, 'tuple 168')
-Insert OK, 1 row affected
-insert into t0 values (169, 'tuple 169')
-Insert OK, 1 row affected
 select * from t0 where k0 = 160
 Found 1 tuple:
 [160, 'tuple 160']
@@ -986,6 +976,16 @@ Found 1 tuple:
 select * from t0 where k0 = 164
 Found 1 tuple:
 [164, 'tuple 164']
+insert into t0 values (165, 'tuple 165')
+Insert OK, 1 row affected
+insert into t0 values (166, 'tuple 166')
+Insert OK, 1 row affected
+insert into t0 values (167, 'tuple 167')
+Insert OK, 1 row affected
+insert into t0 values (168, 'tuple 168')
+Insert OK, 1 row affected
+insert into t0 values (169, 'tuple 169')
+Insert OK, 1 row affected
 select * from t0 where k0 = 165
 Found 1 tuple:
 [165, 'tuple 165']
@@ -1020,16 +1020,6 @@ insert into t0 values (173, 'tuple 173')
 Insert OK, 1 row affected
 insert into t0 values (174, 'tuple 174')
 Insert OK, 1 row affected
-insert into t0 values (175, 'tuple 175')
-Insert OK, 1 row affected
-insert into t0 values (176, 'tuple 176')
-Insert OK, 1 row affected
-insert into t0 values (177, 'tuple 177')
-Insert OK, 1 row affected
-insert into t0 values (178, 'tuple 178')
-Insert OK, 1 row affected
-insert into t0 values (179, 'tuple 179')
-Insert OK, 1 row affected
 select * from t0 where k0 = 170
 Found 1 tuple:
 [170, 'tuple 170']
@@ -1045,6 +1035,16 @@ Found 1 tuple:
 select * from t0 where k0 = 174
 Found 1 tuple:
 [174, 'tuple 174']
+insert into t0 values (175, 'tuple 175')
+Insert OK, 1 row affected
+insert into t0 values (176, 'tuple 176')
+Insert OK, 1 row affected
+insert into t0 values (177, 'tuple 177')
+Insert OK, 1 row affected
+insert into t0 values (178, 'tuple 178')
+Insert OK, 1 row affected
+insert into t0 values (179, 'tuple 179')
+Insert OK, 1 row affected
 select * from t0 where k0 = 175
 Found 1 tuple:
 [175, 'tuple 175']
@@ -1080,16 +1080,6 @@ insert into t0 values (183, 'tuple 183')
 Insert OK, 1 row affected
 insert into t0 values (184, 'tuple 184')
 Insert OK, 1 row affected
-insert into t0 values (185, 'tuple 185')
-Insert OK, 1 row affected
-insert into t0 values (186, 'tuple 186')
-Insert OK, 1 row affected
-insert into t0 values (187, 'tuple 187')
-Insert OK, 1 row affected
-insert into t0 values (188, 'tuple 188')
-Insert OK, 1 row affected
-insert into t0 values (189, 'tuple 189')
-Insert OK, 1 row affected
 select * from t0 where k0 = 180
 Found 1 tuple:
 [180, 'tuple 180']
@@ -1105,6 +1095,16 @@ Found 1 tuple:
 select * from t0 where k0 = 184
 Found 1 tuple:
 [184, 'tuple 184']
+insert into t0 values (185, 'tuple 185')
+Insert OK, 1 row affected
+insert into t0 values (186, 'tuple 186')
+Insert OK, 1 row affected
+insert into t0 values (187, 'tuple 187')
+Insert OK, 1 row affected
+insert into t0 values (188, 'tuple 188')
+Insert OK, 1 row affected
+insert into t0 values (189, 'tuple 189')
+Insert OK, 1 row affected
 select * from t0 where k0 = 185
 Found 1 tuple:
 [185, 'tuple 185']
@@ -1139,16 +1139,6 @@ insert into t0 values (193, 'tuple 193')
 Insert OK, 1 row affected
 insert into t0 values (194, 'tuple 194')
 Insert OK, 1 row affected
-insert into t0 values (195, 'tuple 195')
-Insert OK, 1 row affected
-insert into t0 values (196, 'tuple 196')
-Insert OK, 1 row affected
-insert into t0 values (197, 'tuple 197')
-Insert OK, 1 row affected
-insert into t0 values (198, 'tuple 198')
-Insert OK, 1 row affected
-insert into t0 values (199, 'tuple 199')
-Insert OK, 1 row affected
 select * from t0 where k0 = 190
 Found 1 tuple:
 [190, 'tuple 190']
@@ -1164,6 +1154,16 @@ Found 1 tuple:
 select * from t0 where k0 = 194
 Found 1 tuple:
 [194, 'tuple 194']
+insert into t0 values (195, 'tuple 195')
+Insert OK, 1 row affected
+insert into t0 values (196, 'tuple 196')
+Insert OK, 1 row affected
+insert into t0 values (197, 'tuple 197')
+Insert OK, 1 row affected
+insert into t0 values (198, 'tuple 198')
+Insert OK, 1 row affected
+insert into t0 values (199, 'tuple 199')
+Insert OK, 1 row affected
 select * from t0 where k0 = 195
 Found 1 tuple:
 [195, 'tuple 195']
diff --git a/test/box_replication/swap.test b/test/box_replication/swap.test
index b9c1346eb0..d5fe55981c 100644
--- a/test/box_replication/swap.test
+++ b/test/box_replication/swap.test
@@ -1,10 +1,11 @@
 # encoding: tarantool
 import os
+import time
 from lib.tarantool_box_server import TarantoolBoxServer
 
 REPEAT = 10
 ID_BEGIN = 0
-ID_STEP = 10
+ID_STEP = 5
 
 def insert_tuples(server, begin, end, msg = "tuple"):
     for i in range(begin, end):
@@ -27,7 +28,6 @@ replica.deploy("box_replication/cfg/replica.cfg",
 
 id = ID_BEGIN
 for i in range(REPEAT):
-    summary = 0.0
     print "test %d iteration" % i
 
     # insert to master
@@ -36,24 +36,35 @@ for i in range(REPEAT):
     select_tuples(replica, id, id + ID_STEP)
     id += ID_STEP
 
+    # insert to master
+    insert_tuples(master, id, id + ID_STEP)
+    # select from replica
+    select_tuples(replica, id, id + ID_STEP)
+    id += ID_STEP
+
     print "swap servers"
     # reconfigure replica to master
     replica.reconfigure("box_replication/cfg/replica_to_master.cfg", silent = False)
     # reconfigure master to replica
     master.reconfigure("box_replication/cfg/master_to_replica.cfg", silent = False)
 
+    # insert to replica
+    insert_tuples(replica, id, id + ID_STEP)
+    # select from master
+    select_tuples(master, id, id + ID_STEP)
+    id += ID_STEP
 
-    # insert to master
+    # insert to replica
     insert_tuples(replica, id, id + ID_STEP)
-    # select from replica
+    # select from master
     select_tuples(master, id, id + ID_STEP)
+    id += ID_STEP
 
     print "rollback servers configuration"
     # reconfigure replica to master
     master.reconfigure("box_replication/cfg/master.cfg", silent = False)
     # reconfigure master to replica
     replica.reconfigure("box_replication/cfg/replica.cfg", silent = False)
-    id += ID_STEP
 
 
 # Cleanup.
diff --git a/test/lib/tarantool_box_server.py b/test/lib/tarantool_box_server.py
index b541c7a319..883b76fbaa 100644
--- a/test/lib/tarantool_box_server.py
+++ b/test/lib/tarantool_box_server.py
@@ -41,10 +41,9 @@ class TarantoolBoxServer(TarantoolServer):
     return info[param]
 
   def wait_lsn(self, lsn):
-    try_count = 0
     while True:
       curr_lsn = int(self.get_param("lsn"))
       if (curr_lsn >= lsn):
         break
-      try_count += 1
       time.sleep(0.01)
+
-- 
GitLab