[tarantool-patches] [PATCH v2] recovery: build secondary index in hot standby mode

Ilya Kosarev i.kosarev at tarantool.org
Fri Oct 4 13:25:11 MSK 2019


End recovery (which means building secondary indexes) just after
last known log file was read. This allows fast switch to hot standby
instance without any delay for secondary index to be built.
Due to engine_end_recovery carryover, xdir_collect_inprogress,
previously being called from it, is now moved to garbage collector.

Closes #4135
---
https://github.com/tarantool/tarantool/tree/i.kosarev/gh-4135-secondary-index-for-hot-standby
https://github.com/tarantool/tarantool/issues/4135

Changes in v7:
- moved xdir_collect_inprogress to garbage collector

 src/box/box.cc                        |  3 +--
 src/box/gc.c                          |  1 +
 src/box/memtx_engine.c                |  2 +-
 test/box/errinj.result                | 12 ------------
 test/box/errinj.test.lua              |  4 ----
 test/replication/hot_standby.result   | 16 ++++++++++++++++
 test/replication/hot_standby.test.lua |  2 ++
 7 files changed, 21 insertions(+), 19 deletions(-)

diff --git a/src/box/box.cc b/src/box/box.cc
index 40920e649..0f5f4a6f3 100644
--- a/src/box/box.cc
+++ b/src/box/box.cc
@@ -1968,6 +1968,7 @@ local_recovery(const struct tt_uuid *instance_uuid,
 
 	engine_begin_final_recovery_xc();
 	recover_remaining_wals(recovery, &wal_stream.base, NULL, false);
+	engine_end_recovery_xc();
 	/*
 	 * Leave hot standby mode, if any, only after
 	 * acquiring the lock.
@@ -2005,8 +2006,6 @@ local_recovery(const struct tt_uuid *instance_uuid,
 	if (wal_enable() != 0)
 		diag_raise();
 
-	engine_end_recovery_xc();
-
 	/* Check replica set UUID. */
 	if (!tt_uuid_is_nil(replicaset_uuid) &&
 	    !tt_uuid_is_equal(replicaset_uuid, &REPLICASET_UUID)) {
diff --git a/src/box/gc.c b/src/box/gc.c
index e0df92473..f5c387f9d 100644
--- a/src/box/gc.c
+++ b/src/box/gc.c
@@ -113,6 +113,7 @@ gc_init(void)
 	gc_tree_new(&gc.consumers);
 	fiber_cond_create(&gc.cleanup_cond);
 	checkpoint_schedule_cfg(&gc.checkpoint_schedule, 0, 0);
+	engine_collect_garbage(&gc.vclock);
 
 	gc.cleanup_fiber = fiber_new("gc", gc_cleanup_fiber_f);
 	if (gc.cleanup_fiber == NULL)
diff --git a/src/box/memtx_engine.c b/src/box/memtx_engine.c
index eb11346c1..ecce3b1b6 100644
--- a/src/box/memtx_engine.c
+++ b/src/box/memtx_engine.c
@@ -315,7 +315,6 @@ memtx_engine_end_recovery(struct engine *engine)
 		if (space_foreach(memtx_build_secondary_keys, memtx) != 0)
 			return -1;
 	}
-	xdir_collect_inprogress(&memtx->snap_dir);
 	return 0;
 }
 
@@ -722,6 +721,7 @@ memtx_engine_collect_garbage(struct engine *engine, const struct vclock *vclock)
 	struct memtx_engine *memtx = (struct memtx_engine *)engine;
 	xdir_collect_garbage(&memtx->snap_dir, vclock_sum(vclock),
 			     XDIR_GC_ASYNC);
+	xdir_collect_inprogress(&memtx->snap_dir);
 }
 
 static int
diff --git a/test/box/errinj.result b/test/box/errinj.result
index 5a04e1fb2..a148346e8 100644
--- a/test/box/errinj.result
+++ b/test/box/errinj.result
@@ -1668,18 +1668,6 @@ errinj.set('ERRINJ_VY_GC', false)
 ---
 - ok
 ...
-#fio.glob(fio.pathjoin(box.cfg.vinyl_dir, '*.vylog.inprogress')) > 0
----
-- true
-...
-#fio.glob(fio.pathjoin(box.cfg.vinyl_dir, box.space.test.id, 0, '*.run.inprogress')) > 0
----
-- true
-...
-#fio.glob(fio.pathjoin(box.cfg.vinyl_dir, box.space.test.id, 0, '*.index.inprogress')) > 0
----
-- true
-...
 test_run:cmd('restart server default')
 fio = require('fio')
 ---
diff --git a/test/box/errinj.test.lua b/test/box/errinj.test.lua
index db26d2e10..31dd9665b 100644
--- a/test/box/errinj.test.lua
+++ b/test/box/errinj.test.lua
@@ -580,10 +580,6 @@ errinj.set('ERRINJ_VY_INDEX_FILE_RENAME', false)
 errinj.set('ERRINJ_VY_SCHED_TIMEOUT', 0)
 errinj.set('ERRINJ_VY_GC', false)
 
-#fio.glob(fio.pathjoin(box.cfg.vinyl_dir, '*.vylog.inprogress')) > 0
-#fio.glob(fio.pathjoin(box.cfg.vinyl_dir, box.space.test.id, 0, '*.run.inprogress')) > 0
-#fio.glob(fio.pathjoin(box.cfg.vinyl_dir, box.space.test.id, 0, '*.index.inprogress')) > 0
-
 test_run:cmd('restart server default')
 
 fio = require('fio')
diff --git a/test/replication/hot_standby.result b/test/replication/hot_standby.result
index b140887df..5dc12a462 100644
--- a/test/replication/hot_standby.result
+++ b/test/replication/hot_standby.result
@@ -130,6 +130,9 @@ space = box.schema.space.create('tweedledum', {engine = engine})
 index = space:create_index('primary', {type = 'tree'})
 ---
 ...
+index = space:create_index('secondary', {type = 'tree'})
+---
+...
 -- set begin lsn on master, replica and hot_standby.
 test_run:cmd("set variable replica_port to 'replica.listen'")
 ---
@@ -203,6 +206,19 @@ test_run:cmd("switch hot_standby")
 _wait_lsn(10)
 ---
 ...
+box.space.tweedledum.index[1]:select()
+---
+- - [1, 'the tuple 1']
+  - [2, 'the tuple 2']
+  - [3, 'the tuple 3']
+  - [4, 'the tuple 4']
+  - [5, 'the tuple 5']
+  - [6, 'the tuple 6']
+  - [7, 'the tuple 7']
+  - [8, 'the tuple 8']
+  - [9, 'the tuple 9']
+  - [10, 'the tuple 10']
+...
 test_run:cmd("switch replica")
 ---
 - true
diff --git a/test/replication/hot_standby.test.lua b/test/replication/hot_standby.test.lua
index f43982f15..73a5329a7 100644
--- a/test/replication/hot_standby.test.lua
+++ b/test/replication/hot_standby.test.lua
@@ -71,6 +71,7 @@ box.info.status
 
 space = box.schema.space.create('tweedledum', {engine = engine})
 index = space:create_index('primary', {type = 'tree'})
+index = space:create_index('secondary', {type = 'tree'})
 
 -- set begin lsn on master, replica and hot_standby.
 test_run:cmd("set variable replica_port to 'replica.listen'")
@@ -92,6 +93,7 @@ _select(1, 10)
 -- Check box.info.vclock is updated during hot standby.
 test_run:cmd("switch hot_standby")
 _wait_lsn(10)
+box.space.tweedledum.index[1]:select()
 
 test_run:cmd("switch replica")
 _wait_lsn(10)
-- 
2.17.1





More information about the Tarantool-patches mailing list