[PATCH 12/13] vinyl: forward tuple comparison hints to tx read set

Vladimir Davydov vdavydov.dev at gmail.com
Tue Apr 2 20:33:49 MSK 2019


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




More information about the Tarantool-patches mailing list