[PATCH 10/12] vinyl: rename key stmt construction routine

Vladimir Davydov vdavydov.dev at gmail.com
Thu Feb 21 13:26:10 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_array, because its key feature is that in contrast
to vy_stmt_new_key it takes a msgpack array instead of key data + part
count.
---
 src/box/vinyl.c                 | 14 +++++++-------
 src/box/vy_lsm.c                | 22 +++++++++++-----------
 src/box/vy_scheduler.c          |  4 ++--
 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, 33 insertions(+), 51 deletions(-)

diff --git a/src/box/vinyl.c b/src/box/vinyl.c
index c469077e..925784b0 100644
--- a/src/box/vinyl.c
+++ b/src/box/vinyl.c
@@ -1436,8 +1436,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);
@@ -2914,14 +2914,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_array(ctx->env->lsm_env.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_array(ctx->env->lsm_env.key_format,
+						 slice_info->end);
 		if (end == NULL)
 			goto out;
 	}
@@ -3793,7 +3793,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 eca8a334..2bb56d87 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_array(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_array(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_array(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_array(lsm->env->key_format,
+						 range_info->end);
 		if (end == NULL)
 			goto out;
 	}
@@ -1069,8 +1069,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_array(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 f0e47fce..ad28712b 100644
--- a/src/box/vy_scheduler.c
+++ b/src/box/vy_scheduler.c
@@ -1150,10 +1150,10 @@ 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_array(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_array(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 57abad23..5ac7d833 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 */
@@ -629,7 +618,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;
@@ -648,7 +637,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 3881a2f4..6c834aee 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);
 
 /**
  * Create a new surrogate DELETE from @a key using format.
@@ -541,7 +541,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.
  *
@@ -549,15 +549,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_array(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 bcb60001..1e61ec97 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_array(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