Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladimir Davydov <vdavydov.dev@gmail.com>
To: kostja@tarantool.org
Cc: tarantool-patches@freelists.org
Subject: [PATCH 06/12] vinyl: move vy_key_dup to generic code
Date: Thu, 21 Feb 2019 13:26:06 +0300	[thread overview]
Message-ID: <3735b650cb3759eb7f48f4689aa9d784ca08f534.1550744027.git.vdavydov.dev@gmail.com> (raw)
In-Reply-To: <cover.1550744027.git.vdavydov.dev@gmail.com>
In-Reply-To: <cover.1550744027.git.vdavydov.dev@gmail.com>

This helper function has nothing to do with vinyl - it's simply
duplicates a msgpack array. Let's move it to tuple.c and rename
it to key_dup.
---
 src/box/tuple.c   | 15 +++++++++++++++
 src/box/tuple.h   |  9 +++++++++
 src/box/vy_run.c  | 16 ++++++++--------
 src/box/vy_stmt.c | 15 ---------------
 src/box/vy_stmt.h |  8 --------
 5 files changed, 32 insertions(+), 31 deletions(-)

diff --git a/src/box/tuple.c b/src/box/tuple.c
index 0770db66..6769a487 100644
--- a/src/box/tuple.c
+++ b/src/box/tuple.c
@@ -758,3 +758,18 @@ mp_str(const char *data)
 		return "<failed to format message pack>";
 	return buf;
 }
+
+char *
+key_dup(const char *key)
+{
+	assert(mp_typeof(*key) == MP_ARRAY);
+	const char *end = key;
+	mp_next(&end);
+	char *res = malloc(end - key);
+	if (res == NULL) {
+		diag_set(OutOfMemory, end - key, "malloc", "key");
+		return NULL;
+	}
+	memcpy(res, key, end - key);
+	return res;
+}
diff --git a/src/box/tuple.h b/src/box/tuple.h
index e803260c..d8a020e0 100644
--- a/src/box/tuple.h
+++ b/src/box/tuple.h
@@ -1012,6 +1012,15 @@ tuple_bless(struct tuple *tuple)
 ssize_t
 tuple_to_buf(const struct tuple *tuple, char *buf, size_t size);
 
+/**
+ * Duplicate a raw key (MsgPack array).
+ * @param  key the key to duplicate.
+ * @retval not NULL Pointer to the key copy allocated with malloc().
+ * @retval     NULL Memory error.
+ */
+char *
+key_dup(const char *key);
+
 #if defined(__cplusplus)
 } /* extern "C" */
 
diff --git a/src/box/vy_run.c b/src/box/vy_run.c
index 14975bdf..b85582b2 100644
--- a/src/box/vy_run.c
+++ b/src/box/vy_run.c
@@ -206,7 +206,7 @@ vy_page_info_create(struct vy_page_info *page_info, uint64_t offset,
 	memset(page_info, 0, sizeof(*page_info));
 	page_info->offset = offset;
 	page_info->unpacked_size = 0;
-	page_info->min_key = vy_key_dup(min_key);
+	page_info->min_key = key_dup(min_key);
 	return page_info->min_key == NULL ? -1 : 0;
 }
 
@@ -510,7 +510,7 @@ vy_page_info_decode(struct vy_page_info *page, const struct xrow_header *xrow,
 		case VY_PAGE_INFO_MIN_KEY:
 			key_beg = pos;
 			mp_next(&pos);
-			page->min_key = vy_key_dup(key_beg);
+			page->min_key = key_dup(key_beg);
 			if (page->min_key == NULL)
 				return -1;
 			break;
@@ -595,14 +595,14 @@ vy_run_info_decode(struct vy_run_info *run_info,
 		case VY_RUN_INFO_MIN_KEY:
 			tmp = pos;
 			mp_next(&pos);
-			run_info->min_key = vy_key_dup(tmp);
+			run_info->min_key = key_dup(tmp);
 			if (run_info->min_key == NULL)
 				return -1;
 			break;
 		case VY_RUN_INFO_MAX_KEY:
 			tmp = pos;
 			mp_next(&pos);
-			run_info->max_key = vy_key_dup(tmp);
+			run_info->max_key = key_dup(tmp);
 			if (run_info->max_key == NULL)
 				return -1;
 			break;
@@ -2157,7 +2157,7 @@ vy_run_writer_start_page(struct vy_run_writer *writer,
 		return -1;
 	if (run->info.page_count == 0) {
 		assert(run->info.min_key == NULL);
-		run->info.min_key = vy_key_dup(key);
+		run->info.min_key = key_dup(key);
 		if (run->info.min_key == NULL)
 			return -1;
 	}
@@ -2311,7 +2311,7 @@ vy_run_writer_commit(struct vy_run_writer *writer)
 		goto out;
 
 	assert(run->info.max_key == NULL);
-	run->info.max_key = vy_key_dup(key);
+	run->info.max_key = key_dup(key);
 	if (run->info.max_key == NULL)
 		goto out;
 
@@ -2424,7 +2424,7 @@ vy_run_rebuild_index(struct vy_run *run, const char *dir,
 			if (key == NULL)
 				goto close_err;
 			if (run->info.min_key == NULL) {
-				run->info.min_key = vy_key_dup(key);
+				run->info.min_key = key_dup(key);
 				if (run->info.min_key == NULL)
 					goto close_err;
 			}
@@ -2454,7 +2454,7 @@ vy_run_rebuild_index(struct vy_run *run, const char *dir,
 	}
 
 	if (key != NULL) {
-		run->info.max_key = vy_key_dup(key);
+		run->info.max_key = key_dup(key);
 		if (run->info.max_key == NULL)
 			goto close_err;
 	}
diff --git a/src/box/vy_stmt.c b/src/box/vy_stmt.c
index 618e6025..9d9f2c75 100644
--- a/src/box/vy_stmt.c
+++ b/src/box/vy_stmt.c
@@ -252,21 +252,6 @@ vy_stmt_new_select(struct tuple_format *format, const char *key,
 	return stmt;
 }
 
-char *
-vy_key_dup(const char *key)
-{
-	assert(mp_typeof(*key) == MP_ARRAY);
-	const char *end = key;
-	mp_next(&end);
-	char *res = malloc(end - key);
-	if (res == NULL) {
-		diag_set(OutOfMemory, end - key, "malloc", "key");
-		return NULL;
-	}
-	memcpy(res, key, end - key);
-	return res;
-}
-
 /**
  * Create a statement without type and with reserved space for operations.
  * Operations can be saved in the space available by @param extra.
diff --git a/src/box/vy_stmt.h b/src/box/vy_stmt.h
index 3efad12c..dff0b94f 100644
--- a/src/box/vy_stmt.h
+++ b/src/box/vy_stmt.h
@@ -424,14 +424,6 @@ vy_stmt_new_select(struct tuple_format *format, const char *key,
 		   uint32_t part_count);
 
 /**
- * Copy the key in a new memory area.
- * @retval not NULL Success.
- * @retval     NULL Memory error.
- */
-char *
-vy_key_dup(const char *key);
-
-/**
  * Create a new surrogate DELETE from @a key using format.
  *
  * Example:
-- 
2.11.0

  parent reply	other threads:[~2019-02-21 10:26 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-21 10:26 [PATCH 00/12] vinyl: do not fill secondary tuples with nulls Vladimir Davydov
2019-02-21 10:26 ` [PATCH 01/12] vinyl: use vy_lsm_env::empty_key where appropriate Vladimir Davydov
2019-02-21 10:59   ` [tarantool-patches] " Konstantin Osipov
2019-02-21 10:26 ` [PATCH 02/12] vinyl: make vy_tuple_delete static Vladimir Davydov
2019-02-21 11:00   ` [tarantool-patches] " Konstantin Osipov
2019-02-21 10:26 ` [PATCH 03/12] key_def: cleanup virtual function initialization Vladimir Davydov
2019-02-21 11:01   ` [tarantool-patches] " Konstantin Osipov
2019-02-21 12:05     ` Vladimir Davydov
2019-02-21 10:26 ` [PATCH 04/12] key_def: move cmp and hash functions declarations to key_def.h Vladimir Davydov
2019-02-21 11:02   ` [tarantool-patches] " Konstantin Osipov
2019-02-21 10:26 ` [PATCH 05/12] vinyl: move vy_tuple_key_contains_null to generic code Vladimir Davydov
2019-02-21 11:02   ` [tarantool-patches] " Konstantin Osipov
2019-02-21 10:26 ` Vladimir Davydov [this message]
2019-02-21 11:04   ` [tarantool-patches] Re: [PATCH 06/12] vinyl: move vy_key_dup " Konstantin Osipov
2019-02-21 11:52     ` Vladimir Davydov
2019-02-21 10:26 ` [PATCH 07/12] vinyl: sanitize full/empty key stmt detection Vladimir Davydov
2019-02-21 11:10   ` [tarantool-patches] " Konstantin Osipov
2019-02-21 12:11     ` Vladimir Davydov
2019-03-01 12:57   ` Vladimir Davydov
2019-02-21 10:26 ` [PATCH 08/12] vinyl: remove optimized comparators Vladimir Davydov
2019-02-21 11:11   ` [tarantool-patches] " Konstantin Osipov
2019-02-21 10:26 ` [PATCH 09/12] vinyl: introduce statement environment Vladimir Davydov
2019-02-21 11:14   ` [tarantool-patches] " Konstantin Osipov
2019-02-21 10:26 ` [PATCH 10/12] vinyl: rename key stmt construction routine Vladimir Davydov
2019-02-21 11:15   ` [tarantool-patches] " Konstantin Osipov
2019-02-21 12:14     ` Vladimir Davydov
2019-02-21 10:26 ` [PATCH 11/12] vinyl: don't use IPROTO_SELECT type for key statements Vladimir Davydov
2019-02-21 11:16   ` [tarantool-patches] " Konstantin Osipov
2019-02-21 10:26 ` [PATCH 12/12] vinyl: do not fill secondary tuples with nulls when decoded Vladimir Davydov
2019-02-21 15:39 ` [PATCH 00/12] vinyl: do not fill secondary tuples with nulls Vladimir Davydov

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=3735b650cb3759eb7f48f4689aa9d784ca08f534.1550744027.git.vdavydov.dev@gmail.com \
    --to=vdavydov.dev@gmail.com \
    --cc=kostja@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='Re: [PATCH 06/12] vinyl: move vy_key_dup to generic code' \
    /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