From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org> To: tarantool-patches@freelists.org Cc: kostja@tarantool.org Subject: [tarantool-patches] [PATCH v2 4/8] tuple: account the whole array in field.data and size Date: Sat, 31 Aug 2019 23:35:54 +0200 [thread overview] Message-ID: <90053257c45e518e1f0bad35d237fd8ccf4bf8c3.1567287197.git.v.shpilevoy@tarantool.org> (raw) In-Reply-To: <cover.1567287197.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 87f1d0b74..8ce3c3e82 100644 --- a/src/box/update/update_field.h +++ b/src/box/update/update_field.h @@ -306,6 +306,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. @@ -314,8 +315,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)
next prev parent reply other threads:[~2019-08-31 21:32 UTC|newest] Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-08-31 21:35 [tarantool-patches] [PATCH v2 0/8] JSON updates Vladislav Shpilevoy 2019-08-31 21:35 ` [tarantool-patches] [PATCH v2 1/8] tuple: expose JSON go_to_key and go_to_index functions Vladislav Shpilevoy 2019-08-31 21:35 ` [tarantool-patches] [PATCH v2 2/8] tuple: rework updates to improve code extendibility Vladislav Shpilevoy [not found] ` <20190903192059.GE15611@atlas> [not found] ` <6ee759cf-a975-e6a9-6f52-f855958ffe06@tarantool.org> [not found] ` <20191005132055.GD3913@atlas> [not found] ` <20191005135037.GJ3913@atlas> 2019-10-19 15:11 ` [Tarantool-patches] [tarantool-patches] " Vladislav Shpilevoy 2019-08-31 21:35 ` [tarantool-patches] [PATCH v2 3/8] json: lexer_eof and token_cmp helper functions Vladislav Shpilevoy [not found] ` <20190903192433.GF15611@atlas> [not found] ` <f5612e04-dc56-f4bd-1298-c5841ac909f5@tarantool.org> [not found] ` <20191005132231.GE3913@atlas> [not found] ` <20191005135014.GI3913@atlas> 2019-10-19 15:08 ` [Tarantool-patches] [tarantool-patches] " Vladislav Shpilevoy 2019-08-31 21:35 ` Vladislav Shpilevoy [this message] 2019-08-31 21:35 ` [tarantool-patches] [PATCH v2 5/8] tuple: enable JSON bar updates Vladislav Shpilevoy 2019-08-31 21:35 ` [tarantool-patches] [PATCH v2 6/8] tuple: make update operation tokens consumable Vladislav Shpilevoy 2019-08-31 21:35 ` [tarantool-patches] [PATCH v2 7/8] tuple: JSON updates support intersection by arrays Vladislav Shpilevoy 2019-08-31 21:35 ` [tarantool-patches] [PATCH v2 8/8] tuple: JSON updates support intersection by maps 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=90053257c45e518e1f0bad35d237fd8ccf4bf8c3.1567287197.git.v.shpilevoy@tarantool.org \ --to=v.shpilevoy@tarantool.org \ --cc=kostja@tarantool.org \ --cc=tarantool-patches@freelists.org \ --subject='Re: [tarantool-patches] [PATCH v2 4/8] 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