Tarantool development patches archive
 help / color / mirror / Atom feed
* [PATCH] vinyl: fix tx memory accounting when read intervals are merged
@ 2019-03-23 20:42 Vladimir Davydov
  2019-03-28 12:26 ` [tarantool-patches] " Konstantin Osipov
  0 siblings, 1 reply; 3+ messages in thread
From: Vladimir Davydov @ 2019-03-23 20:42 UTC (permalink / raw)
  To: tarantool-patches

When a few read intervals are merged, we must fix up tx memory stats.

Closes #4071
---
https://github.com/tarantool/tarantool/issues/4071
https://github.com/tarantool/tarantool/commits/dv/gh-4071-vy-fix-tx-memory-accounting

 src/box/vy_tx.c                 | 34 ++++++++++++++++++++++++++++------
 test/vinyl/tx_gap_lock.result   | 27 +++++++++++++++++++++++++++
 test/vinyl/tx_gap_lock.test.lua | 10 ++++++++++
 3 files changed, 65 insertions(+), 6 deletions(-)

diff --git a/src/box/vy_tx.c b/src/box/vy_tx.c
index c4445505..33d153a4 100644
--- a/src/box/vy_tx.c
+++ b/src/box/vy_tx.c
@@ -248,6 +248,30 @@ txv_delete(struct txv *v)
 	mempool_free(&xm->txv_mempool, v);
 }
 
+/**
+ * Account a read interval in transaction manager stats.
+ */
+static void
+vy_read_interval_acct(struct vy_read_interval *interval)
+{
+	struct tx_manager *xm = interval->tx->xm;
+	xm->read_set_size += tuple_size(interval->left);
+	if (interval->left != interval->right)
+		xm->read_set_size += tuple_size(interval->right);
+}
+
+/**
+ * Unaccount a read interval in transaction manager stats.
+ */
+static void
+vy_read_interval_unacct(struct vy_read_interval *interval)
+{
+	struct tx_manager *xm = interval->tx->xm;
+	xm->read_set_size -= tuple_size(interval->left);
+	if (interval->left != interval->right)
+		xm->read_set_size -= tuple_size(interval->right);
+}
+
 static struct vy_read_interval *
 vy_read_interval_new(struct vy_tx *tx, struct vy_lsm *lsm,
 		     struct tuple *left, bool left_belongs,
@@ -271,9 +295,7 @@ vy_read_interval_new(struct vy_tx *tx, struct vy_lsm *lsm,
 	interval->right = right;
 	interval->right_belongs = right_belongs;
 	interval->subtree_last = NULL;
-	xm->read_set_size += tuple_size(left);
-	if (left != right)
-		xm->read_set_size += tuple_size(right);
+	vy_read_interval_acct(interval);
 	return interval;
 }
 
@@ -281,9 +303,7 @@ static void
 vy_read_interval_delete(struct vy_read_interval *interval)
 {
 	struct tx_manager *xm = interval->tx->xm;
-	xm->read_set_size -= tuple_size(interval->left);
-	if (interval->left != interval->right)
-		xm->read_set_size -= tuple_size(interval->right);
+	vy_read_interval_unacct(interval);
 	vy_lsm_unref(interval->lsm);
 	tuple_unref(interval->left);
 	tuple_unref(interval->right);
@@ -926,6 +946,7 @@ vy_tx_track(struct vy_tx *tx, struct vy_lsm *lsm,
 	 * remove them from the transaction and LSM tree read sets.
 	 */
 	if (!stailq_empty(&merge)) {
+		vy_read_interval_unacct(new_interval);
 		interval = stailq_first_entry(&merge, struct vy_read_interval,
 					      in_merge);
 		if (vy_read_interval_cmpl(new_interval, interval) > 0) {
@@ -949,6 +970,7 @@ vy_tx_track(struct vy_tx *tx, struct vy_lsm *lsm,
 			vy_lsm_read_set_remove(&lsm->read_set, interval);
 			vy_read_interval_delete(interval);
 		}
+		vy_read_interval_acct(new_interval);
 	}
 
 	vy_tx_read_set_insert(&tx->read_set, new_interval);
diff --git a/test/vinyl/tx_gap_lock.result b/test/vinyl/tx_gap_lock.result
index a456c017..6270f429 100644
--- a/test/vinyl/tx_gap_lock.result
+++ b/test/vinyl/tx_gap_lock.result
@@ -1416,6 +1416,33 @@ test_run:cmd("setopt delimiter ''");
 - true
 ...
 ----------------------------------------------------------------
+-- Check vinyl stats after all transactions have completed.
+-- Should be all zeros. See gh-4071.
+----------------------------------------------------------------
+stat = box.stat.vinyl()
+---
+...
+stat.memory.tx
+---
+- 0
+...
+stat.tx.statements
+---
+- 0
+...
+stat.tx.transactions
+---
+- 0
+...
+stat.tx.gap_locks
+---
+- 0
+...
+stat.tx.read_views
+---
+- 0
+...
+----------------------------------------------------------------
 c = nil
 ---
 ...
diff --git a/test/vinyl/tx_gap_lock.test.lua b/test/vinyl/tx_gap_lock.test.lua
index 4ad55860..ddc5bce4 100644
--- a/test/vinyl/tx_gap_lock.test.lua
+++ b/test/vinyl/tx_gap_lock.test.lua
@@ -526,6 +526,16 @@ s:drop();
 
 test_run:cmd("setopt delimiter ''");
 ----------------------------------------------------------------
+-- Check vinyl stats after all transactions have completed.
+-- Should be all zeros. See gh-4071.
+----------------------------------------------------------------
+stat = box.stat.vinyl()
+stat.memory.tx
+stat.tx.statements
+stat.tx.transactions
+stat.tx.gap_locks
+stat.tx.read_views
+----------------------------------------------------------------
 
 c = nil
 c1 = nil
-- 
2.11.0

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [tarantool-patches] Re: [PATCH] vinyl: fix tx memory accounting when read intervals are merged
  2019-03-23 20:42 [PATCH] vinyl: fix tx memory accounting when read intervals are merged Vladimir Davydov
@ 2019-03-28 12:26 ` Konstantin Osipov
  2019-03-28 14:43   ` Vladimir Davydov
  0 siblings, 1 reply; 3+ messages in thread
From: Konstantin Osipov @ 2019-03-28 12:26 UTC (permalink / raw)
  To: tarantool-patches

* Vladimir Davydov <vdavydov.dev@gmail.com> [19/03/23 23:44]:
> When a few read intervals are merged, we must fix up tx memory stats.

OK to push.


-- 
Konstantin Osipov, Moscow, Russia, +7 903 626 22 32
http://tarantool.io - www.twitter.com/kostja_osipov

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [tarantool-patches] Re: [PATCH] vinyl: fix tx memory accounting when read intervals are merged
  2019-03-28 12:26 ` [tarantool-patches] " Konstantin Osipov
@ 2019-03-28 14:43   ` Vladimir Davydov
  0 siblings, 0 replies; 3+ messages in thread
From: Vladimir Davydov @ 2019-03-28 14:43 UTC (permalink / raw)
  To: Konstantin Osipov; +Cc: tarantool-patches

On Thu, Mar 28, 2019 at 03:26:24PM +0300, Konstantin Osipov wrote:
> * Vladimir Davydov <vdavydov.dev@gmail.com> [19/03/23 23:44]:
> > When a few read intervals are merged, we must fix up tx memory stats.
> 
> OK to push.

Pushed to master, 2.1, and 1.10.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-03-28 14:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-23 20:42 [PATCH] vinyl: fix tx memory accounting when read intervals are merged Vladimir Davydov
2019-03-28 12:26 ` [tarantool-patches] " Konstantin Osipov
2019-03-28 14:43   ` Vladimir Davydov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox