Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladimir Davydov <vdavydov.dev@gmail.com>
To: Kirill Shcherbatov <kshcherbatov@tarantool.org>
Cc: tarantool-patches@freelists.org, kostja@tarantool.org
Subject: Re: [PATCH v6 3/4] box: manage format fields with JSON tree class
Date: Tue, 11 Dec 2018 12:52:48 +0300	[thread overview]
Message-ID: <20181211095248.3cbpodvxfdy7rpeb@esperanza> (raw)
In-Reply-To: <d0f649c8ab7ad89d8af65ee6f03f70ff88e91f3c.1544084229.git.kshcherbatov@tarantool.org>

On Thu, Dec 06, 2018 at 11:42:30AM +0300, Kirill Shcherbatov wrote:
> As we going to work with format fields in a unified way, we
> started to use the tree JSON class for working with first-level
> format fields.
> 
> Needed for #1012
> ---
>  src/box/sql.c          |  18 +++---
>  src/box/sql/build.c    |   5 +-
>  src/box/tuple.c        |  10 ++--
>  src/box/tuple_format.c | 122 +++++++++++++++++++++++++++++------------
>  src/box/tuple_format.h |  49 ++++++++++++++---
>  src/box/vy_stmt.c      |   4 +-
>  6 files changed, 148 insertions(+), 60 deletions(-)

Pushed to 2.1 with minor changes:

diff --git a/src/box/tuple_format.c b/src/box/tuple_format.c
index eeb68f5d..3af39a37 100644
--- a/src/box/tuple_format.c
+++ b/src/box/tuple_format.c
@@ -41,17 +41,18 @@ static uint32_t formats_size = 0, formats_capacity = 0;
 static struct tuple_field *
 tuple_field_new(void)
 {
-	struct tuple_field *ret = calloc(1, sizeof(struct tuple_field));
-	if (ret == NULL) {
+	struct tuple_field *field = calloc(1, sizeof(struct tuple_field));
+	if (field == NULL) {
 		diag_set(OutOfMemory, sizeof(struct tuple_field), "malloc",
-			 "ret");
+			 "tuple field");
 		return NULL;
 	}
-	ret->type = FIELD_TYPE_ANY;
-	ret->offset_slot = TUPLE_OFFSET_SLOT_NIL;
-	ret->coll_id = COLL_NONE;
-	ret->nullable_action = ON_CONFLICT_ACTION_NONE;
-	return ret;
+	field->token.type = JSON_TOKEN_END;
+	field->type = FIELD_TYPE_ANY;
+	field->offset_slot = TUPLE_OFFSET_SLOT_NIL;
+	field->coll_id = COLL_NONE;
+	field->nullable_action = ON_CONFLICT_ACTION_NONE;
+	return field;
 }
 
 static void
@@ -198,7 +199,7 @@ tuple_format_create(struct tuple_format *format, struct key_def * const *keys,
 	}
 
 	assert(tuple_format_field(format, 0)->offset_slot ==
-		TUPLE_OFFSET_SLOT_NIL);
+	       TUPLE_OFFSET_SLOT_NIL);
 	size_t field_map_size = -current_slot * sizeof(uint32_t);
 	if (field_map_size > UINT16_MAX) {
 		/** tuple->data_offset is 16 bits */
@@ -256,12 +257,15 @@ tuple_format_deregister(struct tuple_format *format)
 	format->id = FORMAT_ID_NIL;
 }
 
-/** Destroy field JSON tree and release allocated memory. */
-static inline void
-tuple_format_fields_destroy(struct tuple_format *format)
+/*
+ * Dismantle the tuple field tree attached to the format and free
+ * memory occupied by tuple fields.
+ */
+static void
+tuple_format_destroy_fields(struct tuple_format *format)
 {
 	struct tuple_field *field, *tmp;
-	json_tree_foreach_entry_safe(&format->fields.root, field,
+	json_tree_foreach_entry_safe(field, &format->fields.root,
 				     struct tuple_field, token, tmp) {
 		json_tree_del(&format->fields, &field->token);
 		tuple_field_delete(field);
@@ -293,6 +297,8 @@ tuple_format_alloc(struct key_def * const *keys, uint16_t key_count,
 		return NULL;
 	}
 	if (json_tree_create(&format->fields) != 0) {
+		diag_set(OutOfMemory, 0, "json_lexer_create",
+			 "tuple field tree");
 		free(format);
 		return NULL;
 	}
@@ -305,7 +311,7 @@ tuple_format_alloc(struct key_def * const *keys, uint16_t key_count,
 		if (json_tree_add(&format->fields, &format->fields.root,
 				  &field->token) != 0) {
 			diag_set(OutOfMemory, 0, "json_tree_add",
-				 "&format->tree");
+				 "tuple field tree entry");
 			tuple_field_delete(field);
 			goto error;
 		}
@@ -325,8 +331,8 @@ tuple_format_alloc(struct key_def * const *keys, uint16_t key_count,
 	format->exact_field_count = 0;
 	format->min_field_count = 0;
 	return format;
-error:;
-	tuple_format_fields_destroy(format);
+error:
+	tuple_format_destroy_fields(format);
 	free(format);
 	return NULL;
 }
@@ -335,7 +341,7 @@ error:;
 static inline void
 tuple_format_destroy(struct tuple_format *format)
 {
-	tuple_format_fields_destroy(format);
+	tuple_format_destroy_fields(format);
 	tuple_dictionary_unref(format->dict);
 }
 
diff --git a/src/box/tuple_format.h b/src/box/tuple_format.h
index 68e9205b..94933780 100644
--- a/src/box/tuple_format.h
+++ b/src/box/tuple_format.h
@@ -184,8 +184,8 @@ struct tuple_format {
 };
 
 /**
- * Return a count of first level nodes correspond to tuple
- * fields.
+ * Return the number of top-level tuple fields defined by
+ * a given format.
  */
 static inline uint32_t
 tuple_format_field_count(const struct tuple_format *format)
@@ -195,8 +195,8 @@ tuple_format_field_count(const struct tuple_format *format)
 }
 
 /**
- * Get the first level node corresponding to tuple field by its
- * fieldno.
+ * Return meta information of a top-level tuple field given
+ * a format and a field index.
  */
 static inline struct tuple_field *
 tuple_format_field(struct tuple_format *format, uint32_t fieldno)

  reply	other threads:[~2018-12-11  9:52 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-06  8:42 [PATCH v6 0/4] box: " Kirill Shcherbatov
2018-12-06  8:42 ` [PATCH v6 1/4] lib: make index_base support for json_lexer Kirill Shcherbatov
2018-12-10 17:34   ` Vladimir Davydov
2018-12-06  8:42 ` [PATCH v6 2/4] lib: implement JSON tree class for json library Kirill Shcherbatov
2018-12-10 17:36   ` Vladimir Davydov
2018-12-06  8:42 ` [PATCH v6 3/4] box: manage format fields with JSON tree class Kirill Shcherbatov
2018-12-11  9:52   ` Vladimir Davydov [this message]
2018-12-06  8:42 ` [PATCH v6 4/4] lib: introduce json_path_cmp, json_path_validate Kirill Shcherbatov
2018-12-10 17:38   ` 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=20181211095248.3cbpodvxfdy7rpeb@esperanza \
    --to=vdavydov.dev@gmail.com \
    --cc=kostja@tarantool.org \
    --cc=kshcherbatov@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='Re: [PATCH v6 3/4] box: manage format fields with JSON tree class' \
    /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