From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: From: Vladimir Davydov Subject: [PATCH] vinyl: fix tx memory accounting when read intervals are merged Date: Sat, 23 Mar 2019 23:42:40 +0300 Message-Id: To: tarantool-patches@freelists.org List-ID: 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