Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
To: tarantool-patches@freelists.org
Subject: [tarantool-patches] [PATCH 09/13] tuple: account the whole array in field.data and size
Date: Tue, 13 Aug 2019 01:05:19 +0200	[thread overview]
Message-ID: <7b6088916aa3f4aacefcf9bb02d81ba732d190a6.1565649886.git.v.shpilevoy@tarantool.org> (raw)
In-Reply-To: <cover.1565649886.git.v.shpilevoy@tarantool.org>

Before the patch a struct field object, describing an array,
didn't account array header in its size and data. Indeed, it
was not needed, because anyway updates could be only 'flat',
and the header was regenerated anyway.

But after next patches an array update may be not on the top
level of an update tree. And its parent node with the current way
of accounting would not be able to see exact borders of each
child.

Part of #1261
---
 src/box/tuple_update.c        | 28 ++++++++++++++++------------
 src/box/update/update_array.c |  9 +++++----
 src/box/update/update_field.h |  6 ++++--
 3 files changed, 25 insertions(+), 18 deletions(-)

diff --git a/src/box/tuple_update.c b/src/box/tuple_update.c
index 87946919d..81e1f7e97 100644
--- a/src/box/tuple_update.c
+++ b/src/box/tuple_update.c
@@ -193,11 +193,12 @@ update_read_ops(struct tuple_update *update, const char *expr,
  * @retval -1 Error.
  */
 static int
-update_do_ops(struct tuple_update *update, const char *old_data,
-	      const char *old_data_end, uint32_t part_count)
+update_do_ops(struct tuple_update *update, const char *header,
+	      const char *old_data, const char *old_data_end,
+	      uint32_t part_count)
 {
-	if (update_array_create(&update->root_array, old_data, old_data_end,
-				part_count) != 0)
+	if (update_array_create(&update->root_array, header, old_data,
+				old_data_end, part_count) != 0)
 		return -1;
 	struct update_op *op = update->ops;
 	struct update_op *ops_end = op + update->op_count;
@@ -214,12 +215,12 @@ update_do_ops(struct tuple_update *update, const char *old_data,
  *        and it is enough to simply write the error to the log.
  */
 static int
-upsert_do_ops(struct tuple_update *update, const char *old_data,
-	      const char *old_data_end, uint32_t part_count,
-	      bool suppress_error)
+upsert_do_ops(struct tuple_update *update, const char *header,
+	      const char *old_data, const char *old_data_end,
+	      uint32_t part_count, bool suppress_error)
 {
-	if (update_array_create(&update->root_array, old_data, old_data_end,
-				part_count) != 0)
+	if (update_array_create(&update->root_array, header, old_data,
+				old_data_end, part_count) != 0)
 		return -1;
 	struct update_op *op = update->ops;
 	struct update_op *ops_end = op + update->op_count;
@@ -276,11 +277,13 @@ tuple_update_execute(const char *expr,const char *expr_end,
 {
 	struct tuple_update update;
 	update_init(&update, index_base);
+	const char *header = old_data;
 	uint32_t field_count = mp_decode_array(&old_data);
 
 	if (update_read_ops(&update, expr, expr_end, dict, field_count) != 0)
 		return NULL;
-	if (update_do_ops(&update, old_data, old_data_end, field_count))
+	if (update_do_ops(&update, header, old_data, old_data_end,
+			  field_count) != 0)
 		return NULL;
 	if (column_mask)
 		*column_mask = update.column_mask;
@@ -296,12 +299,13 @@ tuple_upsert_execute(const char *expr,const char *expr_end,
 {
 	struct tuple_update update;
 	update_init(&update, index_base);
+	const char *header = old_data;
 	uint32_t field_count = mp_decode_array(&old_data);
 
 	if (update_read_ops(&update, expr, expr_end, dict, field_count) != 0)
 		return NULL;
-	if (upsert_do_ops(&update, old_data, old_data_end, field_count,
-			  suppress_error))
+	if (upsert_do_ops(&update, header, old_data, old_data_end, field_count,
+			  suppress_error) != 0)
 		return NULL;
 	if (column_mask)
 		*column_mask = update.column_mask;
diff --git a/src/box/update/update_array.c b/src/box/update/update_array.c
index 985d555af..5b834b644 100644
--- a/src/box/update/update_array.c
+++ b/src/box/update/update_array.c
@@ -143,12 +143,13 @@ update_array_extract_item(struct update_field *field, struct update_op *op)
 }
 
 int
-update_array_create(struct update_field *field, const char *data,
-		    const char *data_end, uint32_t field_count)
+update_array_create(struct update_field *field, const char *header,
+		    const char *data, const char *data_end,
+		    uint32_t field_count)
 {
 	field->type = UPDATE_ARRAY;
-	field->data = data;
-	field->size = data_end - data;
+	field->data = header;
+	field->size = data_end - header;
 	field->array.rope = rope_new(&fiber()->gc);
 	if (field->array.rope == NULL)
 		return -1;
diff --git a/src/box/update/update_field.h b/src/box/update/update_field.h
index b03c7479f..35ec85238 100644
--- a/src/box/update/update_field.h
+++ b/src/box/update/update_field.h
@@ -303,6 +303,7 @@ update_##type##_store(struct update_field *field, char *out, char *out_end);
 /**
  * Initialize @a field as an array to update.
  * @param[out] field Field to initialize.
+ * @param header Header of the MessagePack array @a data.
  * @param data MessagePack data of the array to update.
  * @param data_end End of @a data.
  * @param field_count Field count in @data.
@@ -311,8 +312,9 @@ update_##type##_store(struct update_field *field, char *out, char *out_end);
  * @retval -1 Error.
  */
 int
-update_array_create(struct update_field *field, const char *data,
-		    const char *data_end, uint32_t field_count);
+update_array_create(struct update_field *field, const char *header,
+		    const char *data, const char *data_end,
+		    uint32_t field_count);
 
 OP_DECL_GENERIC(array)
 
-- 
2.20.1 (Apple Git-117)

  parent reply	other threads:[~2019-08-12 23:03 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-12 23:05 [tarantool-patches] [PATCH 00/13] JSON updates Vladislav Shpilevoy
2019-08-12 23:05 ` [tarantool-patches] [PATCH 01/13] tuple: remove alloc and alloc_ctx args from update() Vladislav Shpilevoy
2019-08-12 23:05 ` [tarantool-patches] [PATCH 10/13] tuple: enable JSON bar updates Vladislav Shpilevoy
2019-08-12 23:05 ` [tarantool-patches] [PATCH 11/13] tuple: make update operation tokens consumable Vladislav Shpilevoy
2019-08-12 23:05 ` [tarantool-patches] [PATCH 12/13] tuple: JSON updates support intersection by arrays Vladislav Shpilevoy
2019-08-12 23:05 ` [tarantool-patches] [PATCH 13/13] tuple: JSON updates support intersection by maps Vladislav Shpilevoy
2019-08-12 23:05 ` [tarantool-patches] [PATCH 02/13] rope: make rope library macro template Vladislav Shpilevoy
2019-08-12 23:05 ` [tarantool-patches] [PATCH 03/13] tuple: relax struct tuple_update dependency on rope Vladislav Shpilevoy
2019-08-12 23:05 ` [tarantool-patches] [PATCH 04/13] int96: add a missing header Vladislav Shpilevoy
2019-08-12 23:05 ` [tarantool-patches] [PATCH 05/13] tuple: implement update by field name Vladislav Shpilevoy
2019-08-12 23:05 ` [tarantool-patches] [PATCH 06/13] tuple: expose JSON go_to_key and go_to_index functions Vladislav Shpilevoy
2019-08-12 23:05 ` [tarantool-patches] [PATCH 07/13] tuple: rework updates to improve code extendibility Vladislav Shpilevoy
2019-08-12 23:05 ` [tarantool-patches] [PATCH 08/13] json: lexer_eof and token_cmp helper functions Vladislav Shpilevoy
2019-08-12 23:05 ` Vladislav Shpilevoy [this message]
2019-08-20 18:49 ` [tarantool-patches] Re: [PATCH 00/13] JSON updates Vladislav Shpilevoy

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=7b6088916aa3f4aacefcf9bb02d81ba732d190a6.1565649886.git.v.shpilevoy@tarantool.org \
    --to=v.shpilevoy@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='Re: [tarantool-patches] [PATCH 09/13] tuple: account the whole array in field.data and size' \
    /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