Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladimir Davydov <vdavydov.dev@gmail.com>
To: tarantool-patches@freelists.org
Subject: [PATCH] vinyl: fix tx memory accounting when read intervals are merged
Date: Sat, 23 Mar 2019 23:42:40 +0300	[thread overview]
Message-ID: <e233f1e7898aeb340b812f6031edeb0e3a84c5ea.1553358406.git.vdavydov.dev@gmail.com> (raw)

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

             reply	other threads:[~2019-03-23 20:42 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-23 20:42 Vladimir Davydov [this message]
2019-03-28 12:26 ` [tarantool-patches] " Konstantin Osipov
2019-03-28 14:43   ` Vladimir Davydov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e233f1e7898aeb340b812f6031edeb0e3a84c5ea.1553358406.git.vdavydov.dev@gmail.com \
    --to=vdavydov.dev@gmail.com \
    --cc=tarantool-patches@freelists.org \
    --subject='Re: [PATCH] vinyl: fix tx memory accounting when read intervals are merged' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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