Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladimir Davydov <vdavydov.dev@gmail.com>
To: kostja.osipov@gmail.com
Cc: tarantool-patches@freelists.org
Subject: [PATCH 12/13] vinyl: forward tuple comparison hints to tx read set
Date: Tue,  2 Apr 2019 20:33:49 +0300	[thread overview]
Message-ID: <fdafe8c7c59de7dd1719557892e54f9cd123b1cc.1554225074.git.vdavydov.dev@gmail.com> (raw)
In-Reply-To: <cover.1554225074.git.vdavydov.dev@gmail.com>
In-Reply-To: <cover.1554225074.git.vdavydov.dev@gmail.com>

Instead of computing a statement comparison hint in vy_tx_track,
forward it from the upper level, which already has it computed.

Apart from eliminating extra calls to vy_stmt_hint, this is also a
prerequisite for multikey indexes, which will reuse hints to store
offsets of indexed array entries and thus make hints impossible to be
computed in an arbitrary place in code.
---
 src/box/vinyl.c            |  5 +++--
 src/box/vy_read_iterator.c | 25 ++++++++++++++++---------
 src/box/vy_tx.c            | 13 +++++--------
 src/box/vy_tx.h            | 10 +++++++---
 4 files changed, 31 insertions(+), 22 deletions(-)

diff --git a/src/box/vinyl.c b/src/box/vinyl.c
index edf8b8b3..fc90b372 100644
--- a/src/box/vinyl.c
+++ b/src/box/vinyl.c
@@ -1385,7 +1385,8 @@ vy_get_by_secondary_tuple(struct vy_lsm *lsm, struct vy_tx *tx,
 	 * the DELETE statement is not written to secondary indexes
 	 * immediately.
 	 */
-	if (tx != NULL && vy_tx_track_point(tx, lsm->pk, *result) != 0) {
+	if (tx != NULL && vy_tx_track_point(tx, lsm->pk, *result,
+					    primary_hint) != 0) {
 		tuple_unref(*result);
 		rc = -1;
 		goto out;
@@ -1431,7 +1432,7 @@ vy_get(struct vy_lsm *lsm, struct vy_tx *tx,
 		/*
 		 * Use point lookup for a full key.
 		 */
-		if (tx != NULL && vy_tx_track_point(tx, lsm, key) != 0)
+		if (tx != NULL && vy_tx_track_point(tx, lsm, key, hint) != 0)
 			return -1;
 		if (vy_point_lookup(lsm, tx, rv, key, hint, &tuple, &hint) != 0)
 			return -1;
diff --git a/src/box/vy_read_iterator.c b/src/box/vy_read_iterator.c
index 69fea0cf..ba280f25 100644
--- a/src/box/vy_read_iterator.c
+++ b/src/box/vy_read_iterator.c
@@ -871,25 +871,32 @@ vy_read_iterator_apply_history(struct vy_read_iterator *itr,
  * Track a read in the conflict manager.
  */
 static int
-vy_read_iterator_track_read(struct vy_read_iterator *itr, struct tuple *stmt)
+vy_read_iterator_track_read(struct vy_read_iterator *itr,
+			    struct tuple *stmt, hint_t hint)
 {
 	if (itr->tx == NULL)
 		return 0;
 
 	if (stmt == NULL) {
-		stmt = (itr->iterator_type == ITER_EQ ||
-			itr->iterator_type == ITER_REQ ?
-			itr->key : itr->lsm->env->empty_key);
+		if (itr->iterator_type == ITER_EQ ||
+		    itr->iterator_type == ITER_REQ) {
+			stmt = itr->key;
+			hint = itr->hint;
+		} else {
+			stmt = itr->lsm->env->empty_key;
+			hint = HINT_NONE;
+		}
 	}
 
 	int rc;
 	if (iterator_direction(itr->iterator_type) >= 0) {
-		rc = vy_tx_track(itr->tx, itr->lsm, itr->key,
+		rc = vy_tx_track(itr->tx, itr->lsm, itr->key, itr->hint,
 				 itr->iterator_type != ITER_GT,
-				 stmt, true);
+				 stmt, hint, true);
 	} else {
-		rc = vy_tx_track(itr->tx, itr->lsm, stmt, true,
-				 itr->key, itr->iterator_type != ITER_LT);
+		rc = vy_tx_track(itr->tx, itr->lsm, stmt, hint, true,
+				 itr->key, itr->hint,
+				 itr->iterator_type != ITER_LT);
 	}
 	return rc;
 }
@@ -913,7 +920,7 @@ next_key:
 		return -1;
 	if (vy_read_iterator_apply_history(itr, &stmt, &hint) != 0)
 		return -1;
-	if (vy_read_iterator_track_read(itr, stmt) != 0)
+	if (vy_read_iterator_track_read(itr, stmt, hint) != 0)
 		return -1;
 
 	if (itr->last_stmt != NULL)
diff --git a/src/box/vy_tx.c b/src/box/vy_tx.c
index 621898c9..6a3f410e 100644
--- a/src/box/vy_tx.c
+++ b/src/box/vy_tx.c
@@ -927,17 +927,14 @@ vy_tx_rollback_statement(struct vy_tx *tx, void *svp)
 
 int
 vy_tx_track(struct vy_tx *tx, struct vy_lsm *lsm,
-	    struct tuple *left, bool left_belongs,
-	    struct tuple *right, bool right_belongs)
+	    struct tuple *left, hint_t left_hint, bool left_belongs,
+	    struct tuple *right, hint_t right_hint, bool right_belongs)
 {
 	if (vy_tx_is_in_read_view(tx)) {
 		/* No point in tracking reads. */
 		return 0;
 	}
 
-	hint_t left_hint = vy_stmt_hint(left, lsm->cmp_def);
-	hint_t right_hint = vy_stmt_hint(right, lsm->cmp_def);
-
 	struct vy_read_interval *new_interval;
 	new_interval = vy_read_interval_new(tx, lsm, left, left_hint,
 					    left_belongs, right, right_hint,
@@ -1017,7 +1014,8 @@ vy_tx_track(struct vy_tx *tx, struct vy_lsm *lsm,
 }
 
 int
-vy_tx_track_point(struct vy_tx *tx, struct vy_lsm *lsm, struct tuple *stmt)
+vy_tx_track_point(struct vy_tx *tx, struct vy_lsm *lsm,
+		  struct tuple *stmt, hint_t hint)
 {
 	assert(vy_stmt_is_full_key(stmt, lsm->cmp_def));
 
@@ -1026,14 +1024,13 @@ vy_tx_track_point(struct vy_tx *tx, struct vy_lsm *lsm, struct tuple *stmt)
 		return 0;
 	}
 
-	hint_t hint = vy_stmt_hint(stmt, lsm->cmp_def);
 	struct txv *v = write_set_search_key(&tx->write_set, lsm, stmt, hint);
 	if (v != NULL && vy_stmt_type(v->stmt) != IPROTO_UPSERT) {
 		/* Reading from own write set is serializable. */
 		return 0;
 	}
 
-	return vy_tx_track(tx, lsm, stmt, true, stmt, true);
+	return vy_tx_track(tx, lsm, stmt, hint, true, stmt, hint, true);
 }
 
 int
diff --git a/src/box/vy_tx.h b/src/box/vy_tx.h
index f3b9eacc..7e3305b1 100644
--- a/src/box/vy_tx.h
+++ b/src/box/vy_tx.h
@@ -361,9 +361,11 @@ vy_tx_rollback_statement(struct vy_tx *tx, void *svp);
  * @param tx            Transaction that invoked the read.
  * @param lsm           LSM tree that was read from.
  * @param left          Left boundary of the read interval.
+ * @param left_hint     Comparison hint of the left boundary statement.
  * @param left_belongs  Set if the left boundary belongs to
  *                      the interval.
  * @param right         Right boundary of the read interval.
+ * @param right_hint    Comparison hint of the right boundary statement.
  * @param right_belongs Set if the right boundary belongs to
  *                      the interval.
  *
@@ -372,8 +374,8 @@ vy_tx_rollback_statement(struct vy_tx *tx, void *svp);
  */
 int
 vy_tx_track(struct vy_tx *tx, struct vy_lsm *lsm,
-	    struct tuple *left, bool left_belongs,
-	    struct tuple *right, bool right_belongs);
+	    struct tuple *left, hint_t left_hint, bool left_belongs,
+	    struct tuple *right, hint_t right_hint, bool right_belongs);
 
 /**
  * Remember a point read in the conflict manager index.
@@ -381,6 +383,7 @@ vy_tx_track(struct vy_tx *tx, struct vy_lsm *lsm,
  * @param tx    Transaction that invoked the read.
  * @param lsm   LSM tree that was read from.
  * @param stmt  Key that was read.
+ * @param hint  Statement comparison hint.
  *
  * @retval  0 Success.
  * @retval -1 Memory error.
@@ -392,7 +395,8 @@ vy_tx_track(struct vy_tx *tx, struct vy_lsm *lsm,
  * transaction read it from its own write set.
  */
 int
-vy_tx_track_point(struct vy_tx *tx, struct vy_lsm *lsm, struct tuple *stmt);
+vy_tx_track_point(struct vy_tx *tx, struct vy_lsm *lsm,
+		  struct tuple *stmt, hint_t hint);
 
 /** Add a statement to a transaction. */
 int
-- 
2.11.0

  parent reply	other threads:[~2019-04-02 17:33 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-02 17:33 [PATCH 00/13] Incorporate tuple comparison hints into Vinyl Vladimir Davydov
2019-04-02 17:33 ` [PATCH 01/13] vinyl: store tuple comparison hints in memory tree Vladimir Davydov
2019-04-04  8:53   ` Konstantin Osipov
2019-04-04  9:09     ` Vladimir Davydov
2019-04-04  9:48       ` Konstantin Osipov
2019-04-02 17:33 ` [PATCH 02/13] vinyl: store tuple comparison hints in cache tree Vladimir Davydov
2019-04-04 11:39   ` Konstantin Osipov
2019-04-02 17:33 ` [PATCH 03/13] vinyl: store tuple comparison hints in tx write set Vladimir Davydov
2019-04-04 11:41   ` Konstantin Osipov
2019-04-04 12:21     ` Vladimir Davydov
2019-04-04 12:40       ` Konstantin Osipov
2019-04-04 17:28         ` Vladimir Davydov
2019-04-02 17:33 ` [PATCH 04/13] vinyl: store tuple comparison hints in tx read set Vladimir Davydov
2019-04-04 11:42   ` Konstantin Osipov
2019-04-04 12:08     ` Vladimir Davydov
2019-04-02 17:33 ` [PATCH 05/13] vinyl: store tuple comparison hints in range tree Vladimir Davydov
2019-04-02 17:33 ` [PATCH 06/13] vinyl: store tuple comparison hints in page index Vladimir Davydov
2019-04-02 17:33 ` [PATCH 07/13] vinyl: propagate tuple comparison hints to read iterator Vladimir Davydov
2019-04-04 11:43   ` Konstantin Osipov
2019-04-02 17:33 ` [PATCH 08/13] vinyl: propagate tuple comparison hints to write iterator Vladimir Davydov
2019-04-04 11:47   ` Konstantin Osipov
2019-04-02 17:33 ` [PATCH 09/13] vinyl: forward tuple comparison hints to memory tree Vladimir Davydov
2019-04-04 12:10   ` Konstantin Osipov
2019-04-02 17:33 ` [PATCH 10/13] vinyl: forward tuple comparison hints to cache tree Vladimir Davydov
2019-04-04 12:11   ` Konstantin Osipov
2019-04-02 17:33 ` [PATCH 11/13] vinyl: forward tuple comparison hints to read iterator Vladimir Davydov
2019-04-04 12:12   ` Konstantin Osipov
2019-04-02 17:33 ` Vladimir Davydov [this message]
2019-04-04 12:12   ` [PATCH 12/13] vinyl: forward tuple comparison hints to tx read set Konstantin Osipov
2019-04-02 17:33 ` [PATCH 13/13] Make tuple comparison hints mandatory Vladimir Davydov
2019-04-04 12:21   ` Konstantin Osipov

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=fdafe8c7c59de7dd1719557892e54f9cd123b1cc.1554225074.git.vdavydov.dev@gmail.com \
    --to=vdavydov.dev@gmail.com \
    --cc=kostja.osipov@gmail.com \
    --cc=tarantool-patches@freelists.org \
    --subject='Re: [PATCH 12/13] vinyl: forward tuple comparison hints to tx read set' \
    /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