Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladimir Davydov <vdavydov.dev@gmail.com>
To: tarantool-patches@freelists.org
Subject: [PATCH 09/10] key_def: pass alloc callback to key_def_dump_parts
Date: Fri, 17 May 2019 17:52:43 +0300	[thread overview]
Message-ID: <aff478c066b02cfbfaa9dc2d5e41c47651f90552.1558103547.git.vdavydov.dev@gmail.com> (raw)
In-Reply-To: <cover.1558103547.git.vdavydov.dev@gmail.com>
In-Reply-To: <cover.1558103547.git.vdavydov.dev@gmail.com>

So that we can use an allocator different from the region in vylog.
---
 src/box/key_def.c    |  6 +++---
 src/box/key_def.h    |  4 ++--
 src/box/sql/select.c |  2 +-
 src/box/vy_log.c     | 22 ++++++++++------------
 4 files changed, 16 insertions(+), 18 deletions(-)

diff --git a/src/box/key_def.c b/src/box/key_def.c
index fc547570..46f9c4ef 100644
--- a/src/box/key_def.c
+++ b/src/box/key_def.c
@@ -286,7 +286,7 @@ key_def_new(const struct key_part_def *parts, uint32_t part_count)
 
 int
 key_def_dump_parts(const struct key_def *def, struct key_part_def *parts,
-		   struct region *region)
+		   void *(*alloc_cb)(void *, size_t), void *alloc_ctx)
 {
 	for (uint32_t i = 0; i < def->part_count; i++) {
 		const struct key_part *part = &def->parts[i];
@@ -297,7 +297,7 @@ key_def_dump_parts(const struct key_def *def, struct key_part_def *parts,
 		part_def->nullable_action = part->nullable_action;
 		part_def->coll_id = part->coll_id;
 		if (part->path != NULL) {
-			char *path = region_alloc(region, part->path_len + 1);
+			char *path = alloc_cb(alloc_ctx, part->path_len + 1);
 			if (path == NULL) {
 				diag_set(OutOfMemory, part->path_len + 1,
 					 "region", "part_def->path");
@@ -808,7 +808,7 @@ key_def_find_pk_in_cmp_def(const struct key_def *cmp_def,
 			 "region", "key def parts");
 		goto out;
 	}
-	if (key_def_dump_parts(pk_def, parts, region) != 0)
+	if (key_def_dump_parts(pk_def, parts, region_alloc_cb, region) != 0)
 		goto out;
 	/*
 	 * Second, update field numbers to match the primary key
diff --git a/src/box/key_def.h b/src/box/key_def.h
index f4a1a8fd..147064da 100644
--- a/src/box/key_def.h
+++ b/src/box/key_def.h
@@ -332,12 +332,12 @@ key_def_new(const struct key_part_def *parts, uint32_t part_count);
 
 /**
  * Dump part definitions of the given key def.
- * The region is used for allocating JSON paths, if any.
+ * The callback is used for allocating JSON paths, if any.
  * Return -1 on memory allocation error, 0 on success.
  */
 int
 key_def_dump_parts(const struct key_def *def, struct key_part_def *parts,
-		   struct region *region);
+		   void *(*alloc_cb)(void *, size_t), void *alloc_ctx);
 
 /**
  * Update 'has_optional_parts' of @a key_def with correspondence
diff --git a/src/box/sql/select.c b/src/box/sql/select.c
index d3472a92..5745fb4c 100644
--- a/src/box/sql/select.c
+++ b/src/box/sql/select.c
@@ -1415,7 +1415,7 @@ sql_key_info_new_from_key_def(sql *db, const struct key_def *key_def)
 	key_info->key_def = NULL;
 	key_info->refs = 1;
 	key_info->part_count = key_def->part_count;
-	key_def_dump_parts(key_def, key_info->parts, NULL);
+	key_def_dump_parts(key_def, key_info->parts, NULL, NULL);
 	return key_info;
 }
 
diff --git a/src/box/vy_log.c b/src/box/vy_log.c
index 67b8a763..7157bbf3 100644
--- a/src/box/vy_log.c
+++ b/src/box/vy_log.c
@@ -675,11 +675,10 @@ fail:
  * are duplicated as well.
  */
 static struct vy_log_record *
-vy_log_record_dup(struct region *pool, const struct vy_log_record *src)
+vy_log_record_dup(const struct vy_log_record *src,
+		  void *(*alloc_cb)(void *, size_t), void *alloc_ctx)
 {
-	size_t used = region_used(pool);
-
-	struct vy_log_record *dst = region_alloc(pool, sizeof(*dst));
+	struct vy_log_record *dst = alloc_cb(alloc_ctx, sizeof(*dst));
 	if (dst == NULL) {
 		diag_set(OutOfMemory, sizeof(*dst),
 			 "region", "struct vy_log_record");
@@ -690,7 +689,7 @@ vy_log_record_dup(struct region *pool, const struct vy_log_record *src)
 		const char *data = src->begin;
 		mp_next(&data);
 		size_t size = data - src->begin;
-		dst->begin = region_alloc(pool, size);
+		dst->begin = alloc_cb(alloc_ctx, size);
 		if (dst->begin == NULL) {
 			diag_set(OutOfMemory, size, "region",
 				 "vy_log_record::begin");
@@ -702,7 +701,7 @@ vy_log_record_dup(struct region *pool, const struct vy_log_record *src)
 		const char *data = src->end;
 		mp_next(&data);
 		size_t size = data - src->end;
-		dst->end = region_alloc(pool, size);
+		dst->end = alloc_cb(alloc_ctx, size);
 		if (dst->end == NULL) {
 			diag_set(OutOfMemory, size, "region",
 				 "struct vy_log_record");
@@ -713,21 +712,20 @@ vy_log_record_dup(struct region *pool, const struct vy_log_record *src)
 	if (src->key_def != NULL) {
 		size_t size = src->key_def->part_count *
 				sizeof(struct key_part_def);
-		dst->key_parts = region_alloc(pool, size);
+		dst->key_parts = alloc_cb(alloc_ctx, size);
 		if (dst->key_parts == NULL) {
 			diag_set(OutOfMemory, size, "region",
 				 "struct key_part_def");
 			goto err;
 		}
-		if (key_def_dump_parts(src->key_def, dst->key_parts, pool) != 0)
+		if (key_def_dump_parts(src->key_def, dst->key_parts,
+				       alloc_cb, alloc_ctx) != 0)
 			goto err;
 		dst->key_part_count = src->key_def->part_count;
 		dst->key_def = NULL;
 	}
 	return dst;
-
 err:
-	region_truncate(pool, used);
 	return NULL;
 }
 
@@ -1272,8 +1270,8 @@ vy_log_write(const struct vy_log_record *record)
 {
 	assert(latch_owner(&vy_log.latch) == fiber());
 
-	struct vy_log_record *tx_record = vy_log_record_dup(&vy_log.pool,
-							    record);
+	struct vy_log_record *tx_record = vy_log_record_dup(record,
+					region_alloc_cb, &vy_log.pool);
 	if (tx_record == NULL) {
 		diag_move(diag_get(), &vy_log.tx_diag);
 		vy_log.tx_failed = true;
-- 
2.11.0

  parent reply	other threads:[~2019-05-17 14:52 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-17 14:52 [PATCH 00/10] vinyl: don't yield in DDL on_commit triggers Vladimir Davydov
2019-05-17 14:52 ` [PATCH 01/10] box: zap atfork callback Vladimir Davydov
2019-05-18 18:37   ` [tarantool-patches] " Konstantin Osipov
2019-05-20  8:13     ` Vladimir Davydov
2019-06-01  8:16     ` Konstantin Osipov
2019-06-06 10:04       ` Vladimir Davydov
2019-05-17 14:52 ` [PATCH 02/10] vinyl: add a separate thread for vylog Vladimir Davydov
2019-05-18 18:39   ` [tarantool-patches] " Konstantin Osipov
2019-05-20  8:17     ` Vladimir Davydov
2019-06-01  8:26   ` Konstantin Osipov
2019-06-06 10:20     ` Vladimir Davydov
2019-05-17 14:52 ` [PATCH 03/10] vinyl: move vylog recovery to vylog thread Vladimir Davydov
2019-06-01  8:36   ` [tarantool-patches] " Konstantin Osipov
2019-06-06 10:23     ` Vladimir Davydov
2019-06-07 13:39       ` Konstantin Osipov
2019-06-10 15:24         ` Vladimir Davydov
2019-06-07 13:40       ` Konstantin Osipov
2019-05-17 14:52 ` [PATCH 04/10] vinyl: rework vylog transaction backlog implementation Vladimir Davydov
2019-06-01  8:38   ` [tarantool-patches] " Konstantin Osipov
2019-06-06 11:58     ` Vladimir Davydov
2019-05-17 14:52 ` [PATCH 05/10] vinyl: don't purge deleted runs from vylog on compaction Vladimir Davydov
2019-05-18 18:47   ` [tarantool-patches] " Konstantin Osipov
2019-05-20  8:27     ` Vladimir Davydov
2019-06-01  8:39   ` Konstantin Osipov
2019-06-06 12:40     ` Vladimir Davydov
2019-05-17 14:52 ` [PATCH 06/10] vinyl: lock out compaction while checkpointing is in progress Vladimir Davydov
2019-05-17 14:52 ` [PATCH 07/10] vinyl: don't access last vylog signature outside vylog implementation Vladimir Davydov
2019-05-17 14:52 ` [PATCH 08/10] vinyl: zap ERRINJ_VY_LOG_FLUSH_DELAY Vladimir Davydov
2019-05-17 14:52 ` Vladimir Davydov [this message]
2019-05-18 18:52   ` [tarantool-patches] Re: [PATCH 09/10] key_def: pass alloc callback to key_def_dump_parts Konstantin Osipov
2019-05-20  8:34     ` Vladimir Davydov
2019-06-01  8:41     ` Konstantin Osipov
2019-06-10 15:28       ` Vladimir Davydov
2019-06-16 14:57         ` Konstantin Osipov
2019-05-17 14:52 ` [PATCH 10/10] vinyl: get rid of the latch protecting vylog buffer Vladimir Davydov
2019-06-01  8:44   ` [tarantool-patches] " Konstantin Osipov
2019-06-06 13:15     ` Vladimir Davydov
2019-05-18 18:35 ` [tarantool-patches] Re: [PATCH 00/10] vinyl: don't yield in DDL on_commit triggers Konstantin Osipov
2019-05-20  8:09   ` Vladimir Davydov
2019-06-01  8:09 ` 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=aff478c066b02cfbfaa9dc2d5e41c47651f90552.1558103547.git.vdavydov.dev@gmail.com \
    --to=vdavydov.dev@gmail.com \
    --cc=tarantool-patches@freelists.org \
    --subject='Re: [PATCH 09/10] key_def: pass alloc callback to key_def_dump_parts' \
    /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