[PATCH v2 03/14] vinyl: rename key stmt construction routine

Vladimir Davydov vdavydov.dev at gmail.com
Wed Mar 13 11:52:49 MSK 2019


Currently, it's called vy_stmt_new_select, but soon a key statement will
be allowed to have any type, not just IPROTO_SELECT. So let's rename it
to vy_stmt_new_key. Let's also rename the wrapper vy_key_from_msgpack to
vy_stmt_new_key_from_msgpack to be consistent with vy_stmt_new_key.
---
 src/box/vinyl.c                 | 15 ++++++++-------
 src/box/vy_lsm.c                | 22 +++++++++++-----------
 src/box/vy_scheduler.c          |  6 ++++--
 src/box/vy_stmt.c               | 19 ++++---------------
 src/box/vy_stmt.h               | 19 +++++++------------
 test/unit/vy_iterators_helper.c |  4 +---
 test/unit/vy_mem.c              |  2 +-
 7 files changed, 36 insertions(+), 51 deletions(-)

diff --git a/src/box/vinyl.c b/src/box/vinyl.c
index 7bfc0884..0146f62c 100644
--- a/src/box/vinyl.c
+++ b/src/box/vinyl.c
@@ -1435,8 +1435,8 @@ vy_get_by_raw_key(struct vy_lsm *lsm, struct vy_tx *tx,
 		  const char *key_raw, uint32_t part_count,
 		  struct tuple **result)
 {
-	struct tuple *key = vy_stmt_new_select(lsm->env->key_format,
-					       key_raw, part_count);
+	struct tuple *key = vy_stmt_new_key(lsm->env->key_format,
+					    key_raw, part_count);
 	if (key == NULL)
 		return -1;
 	int rc = vy_get(lsm, tx, rv, key, result);
@@ -2912,6 +2912,7 @@ vy_prepare_send_slice(struct vy_join_ctx *ctx,
 	int rc = -1;
 	struct vy_run *run = NULL;
 	struct tuple *begin = NULL, *end = NULL;
+	struct tuple_format *key_format = ctx->env->lsm_env.key_format;
 
 	run = vy_run_new(&ctx->env->run_env, slice_info->run->id);
 	if (run == NULL)
@@ -2920,14 +2921,14 @@ vy_prepare_send_slice(struct vy_join_ctx *ctx,
 		goto out;
 
 	if (slice_info->begin != NULL) {
-		begin = vy_key_from_msgpack(ctx->env->lsm_env.key_format,
-					    slice_info->begin);
+		begin = vy_stmt_new_key_from_msgpack(key_format,
+						     slice_info->begin);
 		if (begin == NULL)
 			goto out;
 	}
 	if (slice_info->end != NULL) {
-		end = vy_key_from_msgpack(ctx->env->lsm_env.key_format,
-					  slice_info->end);
+		end = vy_stmt_new_key_from_msgpack(key_format,
+						   slice_info->end);
 		if (end == NULL)
 			goto out;
 	}
@@ -3799,7 +3800,7 @@ vinyl_index_create_iterator(struct index *base, enum iterator_type type,
 			 "mempool", "struct vinyl_iterator");
 		return NULL;
 	}
-	it->key = vy_stmt_new_select(lsm->env->key_format, key, part_count);
+	it->key = vy_stmt_new_key(lsm->env->key_format, key, part_count);
 	if (it->key == NULL) {
 		mempool_free(&env->iterator_pool, it);
 		return NULL;
diff --git a/src/box/vy_lsm.c b/src/box/vy_lsm.c
index 29cd6eab..171664d4 100644
--- a/src/box/vy_lsm.c
+++ b/src/box/vy_lsm.c
@@ -74,7 +74,7 @@ vy_lsm_env_create(struct vy_lsm_env *env, const char *path,
 		  vy_upsert_thresh_cb upsert_thresh_cb,
 		  void *upsert_thresh_arg)
 {
-	env->empty_key = vy_stmt_new_select(key_format, NULL, 0);
+	env->empty_key = vy_stmt_new_key(key_format, NULL, 0);
 	if (env->empty_key == NULL)
 		return -1;
 	env->path = path;
@@ -387,14 +387,14 @@ vy_lsm_recover_slice(struct vy_lsm *lsm, struct vy_range *range,
 	struct vy_run *run;
 
 	if (slice_info->begin != NULL) {
-		begin = vy_key_from_msgpack(lsm->env->key_format,
-					    slice_info->begin);
+		begin = vy_stmt_new_key_from_msgpack(lsm->env->key_format,
+						     slice_info->begin);
 		if (begin == NULL)
 			goto out;
 	}
 	if (slice_info->end != NULL) {
-		end = vy_key_from_msgpack(lsm->env->key_format,
-					  slice_info->end);
+		end = vy_stmt_new_key_from_msgpack(lsm->env->key_format,
+						   slice_info->end);
 		if (end == NULL)
 			goto out;
 	}
@@ -433,14 +433,14 @@ vy_lsm_recover_range(struct vy_lsm *lsm,
 	struct vy_range *range = NULL;
 
 	if (range_info->begin != NULL) {
-		begin = vy_key_from_msgpack(lsm->env->key_format,
-					    range_info->begin);
+		begin = vy_stmt_new_key_from_msgpack(lsm->env->key_format,
+						     range_info->begin);
 		if (begin == NULL)
 			goto out;
 	}
 	if (range_info->end != NULL) {
-		end = vy_key_from_msgpack(lsm->env->key_format,
-					  range_info->end);
+		end = vy_stmt_new_key_from_msgpack(lsm->env->key_format,
+						   range_info->end);
 		if (end == NULL)
 			goto out;
 	}
@@ -1068,8 +1068,8 @@ vy_lsm_split_range(struct vy_lsm *lsm, struct vy_range *range)
 	/*
 	 * Determine new ranges' boundaries.
 	 */
-	struct tuple *split_key = vy_key_from_msgpack(key_format,
-						      split_key_raw);
+	struct tuple *split_key = vy_stmt_new_key_from_msgpack(key_format,
+							       split_key_raw);
 	if (split_key == NULL)
 		goto fail;
 
diff --git a/src/box/vy_scheduler.c b/src/box/vy_scheduler.c
index 92d40780..91cf502b 100644
--- a/src/box/vy_scheduler.c
+++ b/src/box/vy_scheduler.c
@@ -1136,10 +1136,12 @@ vy_task_dump_complete(struct vy_task *task)
 	 * intersecting the run or NULL if the run itersects all
 	 * ranges.
 	 */
-	min_key = vy_key_from_msgpack(key_format, new_run->info.min_key);
+	min_key = vy_stmt_new_key_from_msgpack(key_format,
+					       new_run->info.min_key);
 	if (min_key == NULL)
 		goto fail;
-	max_key = vy_key_from_msgpack(key_format, new_run->info.max_key);
+	max_key = vy_stmt_new_key_from_msgpack(key_format,
+					       new_run->info.max_key);
 	if (max_key == NULL) {
 		tuple_unref(min_key);
 		goto fail;
diff --git a/src/box/vy_stmt.c b/src/box/vy_stmt.c
index 91966d8c..e34ff2b6 100644
--- a/src/box/vy_stmt.c
+++ b/src/box/vy_stmt.c
@@ -236,20 +236,9 @@ vy_stmt_dup_lsregion(const struct tuple *stmt, struct lsregion *lsregion,
 	return mem_stmt;
 }
 
-/**
- * Create the key statement from raw MessagePack data.
- * @param format     Format of an index.
- * @param key        MessagePack data that contain an array of
- *                   fields WITHOUT the array header.
- * @param part_count Count of the key fields that will be saved as
- *                   result.
- *
- * @retval not NULL Success.
- * @retval     NULL Memory allocation error.
- */
 struct tuple *
-vy_stmt_new_select(struct tuple_format *format, const char *key,
-		   uint32_t part_count)
+vy_stmt_new_key(struct tuple_format *format, const char *key,
+		uint32_t part_count)
 {
 	assert(part_count == 0 || key != NULL);
 	/* Key don't have field map */
@@ -649,7 +638,7 @@ vy_stmt_extract_key(const struct tuple *stmt, struct key_def *key_def,
 		return NULL;
 	uint32_t part_count = mp_decode_array(&key_raw);
 	assert(part_count == key_def->part_count);
-	struct tuple *key = vy_stmt_new_select(format, key_raw, part_count);
+	struct tuple *key = vy_stmt_new_key(format, key_raw, part_count);
 	/* Cleanup memory allocated by tuple_extract_key(). */
 	region_truncate(region, region_svp);
 	return key;
@@ -668,7 +657,7 @@ vy_stmt_extract_key_raw(const char *data, const char *data_end,
 		return NULL;
 	uint32_t part_count = mp_decode_array(&key_raw);
 	assert(part_count == key_def->part_count);
-	struct tuple *key = vy_stmt_new_select(format, key_raw, part_count);
+	struct tuple *key = vy_stmt_new_key(format, key_raw, part_count);
 	/* Cleanup memory allocated by tuple_extract_key_raw(). */
 	region_truncate(region, region_svp);
 	return key;
diff --git a/src/box/vy_stmt.h b/src/box/vy_stmt.h
index 0332bbdb..192f47de 100644
--- a/src/box/vy_stmt.h
+++ b/src/box/vy_stmt.h
@@ -382,7 +382,7 @@ vy_stmt_compare_with_raw_key(const struct tuple *stmt, const char *key,
 }
 
 /**
- * Create the SELECT statement from raw MessagePack data.
+ * Create a key statement from raw MessagePack data.
  * @param format     Format of an index.
  * @param key        MessagePack data that contain an array of
  *                   fields WITHOUT the array header.
@@ -393,8 +393,8 @@ vy_stmt_compare_with_raw_key(const struct tuple *stmt, const char *key,
  * @retval not NULL Success.
  */
 struct tuple *
-vy_stmt_new_select(struct tuple_format *format, const char *key,
-		   uint32_t part_count);
+vy_stmt_new_key(struct tuple_format *format, const char *key,
+		uint32_t part_count);
 
 /**
  * Copy the key in a new memory area.
@@ -549,7 +549,7 @@ vy_stmt_upsert_ops(const struct tuple *tuple, uint32_t *mp_size)
 }
 
 /**
- * Create the SELECT statement from MessagePack array.
+ * Create a key statement from MessagePack array.
  * @param format  Format of an index.
  * @param key     MessagePack array of key fields.
  *
@@ -557,15 +557,10 @@ vy_stmt_upsert_ops(const struct tuple *tuple, uint32_t *mp_size)
  * @retval     NULL Memory error.
  */
 static inline struct tuple *
-vy_key_from_msgpack(struct tuple_format *format, const char *key)
+vy_stmt_new_key_from_msgpack(struct tuple_format *format, const char *key)
 {
-	uint32_t part_count;
-	/*
-	 * The statement already is a key, so simply copy it in
-	 * the new struct vy_stmt as SELECT.
-	 */
-	part_count = mp_decode_array(&key);
-	return vy_stmt_new_select(format, key, part_count);
+	uint32_t part_count = mp_decode_array(&key);
+	return vy_stmt_new_key(format, key, part_count);
 }
 
 /**
diff --git a/test/unit/vy_iterators_helper.c b/test/unit/vy_iterators_helper.c
index 0b0fe4ab..9b70ed98 100644
--- a/test/unit/vy_iterators_helper.c
+++ b/test/unit/vy_iterators_helper.c
@@ -117,9 +117,7 @@ vy_new_simple_stmt(struct tuple_format *format,
 		break;
 	}
 	case IPROTO_SELECT: {
-		const char *key = buf;
-		uint part_count = mp_decode_array(&key);
-		ret = vy_stmt_new_select(stmt_env.key_format, key, part_count);
+		ret = vy_stmt_new_key_from_msgpack(stmt_env.key_format, buf);
 		fail_if(ret == NULL);
 		break;
 	}
diff --git a/test/unit/vy_mem.c b/test/unit/vy_mem.c
index 0226a62a..da4117c5 100644
--- a/test/unit/vy_mem.c
+++ b/test/unit/vy_mem.c
@@ -86,7 +86,7 @@ test_iterator_restore_after_insertion()
 	struct slab_cache *slab_cache = cord_slab_cache();
 	lsregion_create(&lsregion, slab_cache->arena);
 
-	struct tuple *select_key = vy_stmt_new_select(format, "", 0);
+	struct tuple *select_key = vy_stmt_new_key(format, NULL, 0);
 
 	struct mempool history_node_pool;
 	mempool_create(&history_node_pool, cord_slab_cache(),
-- 
2.11.0




More information about the Tarantool-patches mailing list