[PATCH 8/8] box: introduce promotion GC

Vladislav Shpilevoy v.shpilevoy at tarantool.org
Wed Aug 8 01:03:51 MSK 2018


In the previous commit a promotion protocol was introduced. Each
promotion round produces messages stored in the _promotion space.
After a number of promotions the space can become too big. But it
is not necessary to store those promotion rounds after which
another successfull promotion was executed.

This patch introduces garbage collecting, so after each
successfull promotion old rounds are purged.

Follow up #3055
---
 src/box/promote.c           | 15 +++++++++++++--
 test/promote/basic.result   | 23 +++++++++++++++++++++++
 test/promote/basic.test.lua | 11 +++++++++++
 3 files changed, 47 insertions(+), 2 deletions(-)

diff --git a/src/box/promote.c b/src/box/promote.c
index dcc39b5bd..eab348f70 100644
--- a/src/box/promote.c
+++ b/src/box/promote.c
@@ -695,7 +695,7 @@ rollback:
 }
 
 int
-box_ctl_promote_reset(void)
+promote_reset_until(uint32_t until)
 {
 	uint32_t id, next_id = 0;
 	struct index *pk = space_index(space_by_id(BOX_PROMOTION_ID), 0);
@@ -703,7 +703,15 @@ box_ctl_promote_reset(void)
 		id = next_id;
 		if (promote_clean_round(id, &next_id, pk) != 0)
 			return -1;
-	} while (id != next_id);
+	} while (id != next_id && next_id < until);
+	return 0;
+}
+
+int
+box_ctl_promote_reset(void)
+{
+	if (promote_reset_until(UINT32_MAX) != 0)
+		return -1;
 	promote_state.phase = PROMOTE_PHASE_NON_ACTIVE;
 	promote_state.is_role_committed = false;
 	return 0;
@@ -739,6 +747,9 @@ stop:
 	say_info("promotion timer is stopped");
 	assert(fiber() == promote_state.timer);
 	promote_state.timer = NULL;
+	if (promote_state.role == PROMOTE_ROLE_INITIATOR &&
+	    promote_state.phase == PROMOTE_PHASE_SUCCESS)
+		promote_reset_until(promote_state.round_id);
 	return 0;
 }
 
diff --git a/test/promote/basic.result b/test/promote/basic.result
index f70659963..47c92e257 100644
--- a/test/promote/basic.result
+++ b/test/promote/basic.result
@@ -464,6 +464,29 @@ promotion_history()
 ---
 - []
 ...
+--
+-- Test promotion GC.
+--
+_ = test_run:switch('box2')
+---
+...
+box.ctl.promote()
+---
+- true
+...
+_ = test_run:switch('box1')
+---
+...
+box.ctl.promote()
+---
+- true
+...
+-- Each successfull round for 4 instance cluster produces 9
+-- records.
+#promotion_history() < 10
+---
+- true
+...
 _ = test_run:switch('default')
 ---
 ...
diff --git a/test/promote/basic.test.lua b/test/promote/basic.test.lua
index 4138745b5..835208f06 100644
--- a/test/promote/basic.test.lua
+++ b/test/promote/basic.test.lua
@@ -156,5 +156,16 @@ promote_info()
 box.ctl.promote_reset()
 promotion_history()
 
+--
+-- Test promotion GC.
+--
+_ = test_run:switch('box2')
+box.ctl.promote()
+_ = test_run:switch('box1')
+box.ctl.promote()
+-- Each successfull round for 4 instance cluster produces 9
+-- records.
+#promotion_history() < 10
+
 _ = test_run:switch('default')
 test_run:drop_cluster(CLUSTER)
-- 
2.15.2 (Apple Git-101.1)




More information about the Tarantool-patches mailing list