From: Nikita Pettik <korablev@tarantool.org> To: tarantool-patches@dev.tarantool.org Cc: v.shpilevoy@tarantool.org Subject: [Tarantool-patches] [PATCH 1/2] vinyl: validate resulting tuple after upsert is applied Date: Tue, 14 Apr 2020 00:55:44 +0300 [thread overview] Message-ID: <cde2578032347540029c2a324d9e50d90c0af64b.1586808463.git.korablev@tarantool.org> (raw) In-Reply-To: <cover.1586808463.git.korablev@tarantool.org> In-Reply-To: <cover.1586808463.git.korablev@tarantool.org> There's no check that the result of upsert squashing will feature correct format. As a consequence one is able to get tuples in space which do not respect format. For instance: box.schema.space.create('vinyl',{engine='vinyl',field_count=1}) box.space.vinyl:insert{1} box.space.vinyl:upsert({1},{{'=',2,5}}) The last statement does not raise any errors. So upsert is applied and now there's [1, 5] tuple in space (which violates 'field_count' format restriction). To avoid such situations, let's validate result of upsert application and check format of resulting tuple. Part of #1622 --- src/box/vy_upsert.c | 4 +++ .../vinyl/gh-1622-skip-invalid-upserts.result | 26 +++++++++++++++++++ .../gh-1622-skip-invalid-upserts.test.lua | 11 ++++++++ 3 files changed, 41 insertions(+) create mode 100644 test/vinyl/gh-1622-skip-invalid-upserts.result create mode 100644 test/vinyl/gh-1622-skip-invalid-upserts.test.lua diff --git a/src/box/vy_upsert.c b/src/box/vy_upsert.c index ebea2789c..6855b9820 100644 --- a/src/box/vy_upsert.c +++ b/src/box/vy_upsert.c @@ -134,6 +134,10 @@ vy_apply_upsert(const struct tuple *new_stmt, const struct tuple *old_stmt, &mp_size, 0, suppress_error, &column_mask); result_mp_end = result_mp + mp_size; + if (tuple_validate_raw(format, result_mp) != 0) { + region_truncate(region, region_svp); + return NULL; + } if (old_type != IPROTO_UPSERT) { assert(old_type == IPROTO_INSERT || old_type == IPROTO_REPLACE); diff --git a/test/vinyl/gh-1622-skip-invalid-upserts.result b/test/vinyl/gh-1622-skip-invalid-upserts.result new file mode 100644 index 000000000..437ff3c51 --- /dev/null +++ b/test/vinyl/gh-1622-skip-invalid-upserts.result @@ -0,0 +1,26 @@ +-- test-run result file version 2 +s = box.schema.space.create('test', { engine = 'vinyl', field_count = 2 }) + | --- + | ... +pk = s:create_index('pk') + | --- + | ... +s:replace{1, 1} + | --- + | - [1, 1] + | ... +-- Error is logged, upsert is not applied. +-- +s:upsert({1, 1}, {{'=', 3, 5}}) + | --- + | ... +-- Invalid upsert still appears during read. +-- +s:select{} + | --- + | - error: Tuple field count 3 does not match space field count 2 + | ... + +s:drop() + | --- + | ... diff --git a/test/vinyl/gh-1622-skip-invalid-upserts.test.lua b/test/vinyl/gh-1622-skip-invalid-upserts.test.lua new file mode 100644 index 000000000..952d2bcde --- /dev/null +++ b/test/vinyl/gh-1622-skip-invalid-upserts.test.lua @@ -0,0 +1,11 @@ +s = box.schema.space.create('test', { engine = 'vinyl', field_count = 2 }) +pk = s:create_index('pk') +s:replace{1, 1} +-- Error is logged, upsert is not applied. +-- +s:upsert({1, 1}, {{'=', 3, 5}}) +-- Invalid upsert still appears during read. +-- +s:select{} + +s:drop() \ No newline at end of file -- 2.17.1
next prev parent reply other threads:[~2020-04-13 21:55 UTC|newest] Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-04-13 21:55 [Tarantool-patches] [PATCH 0/2] Validate result of upserts squash & skip invalid upserts which can't be applied Nikita Pettik 2020-04-13 21:55 ` Nikita Pettik [this message] 2020-06-22 19:28 ` [Tarantool-patches] [PATCH 1/2] vinyl: validate resulting tuple after upsert is applied Aleksandr Lyapunov 2020-04-13 21:55 ` [Tarantool-patches] [PATCH 2/2] vinyl: skip invalid upserts during squash Nikita Pettik 2020-04-13 22:12 ` Konstantin Osipov 2020-05-14 2:11 ` Nikita Pettik 2020-05-14 6:56 ` Konstantin Osipov 2020-05-19 19:10 ` Nikita Pettik 2020-05-19 19:39 ` Konstantin Osipov 2020-05-21 2:51 ` Nikita Pettik 2020-05-21 8:36 ` Konstantin Osipov 2020-05-01 0:31 ` Vladislav Shpilevoy 2020-05-14 2:21 ` Nikita Pettik 2020-05-14 21:32 ` Vladislav Shpilevoy 2020-05-19 18:18 ` Nikita Pettik 2020-05-20 22:13 ` Vladislav Shpilevoy 2020-05-26 21:33 ` Vladislav Shpilevoy 2020-05-27 20:05 ` Nikita Pettik 2020-05-29 21:47 ` Vladislav Shpilevoy 2020-06-01 19:24 ` Nikita Pettik 2020-05-20 22:13 ` [Tarantool-patches] [PATCH 0/2] Validate result of upserts squash & skip invalid upserts which can't be applied Vladislav Shpilevoy 2020-05-22 2:42 ` Nikita Pettik 2020-05-26 21:33 ` Vladislav Shpilevoy 2020-05-27 20:10 ` Nikita Pettik 2020-06-22 14:13 ` Aleksandr Lyapunov 2020-06-22 20:21 ` Nikita Pettik 2020-06-23 12:32 ` Aleksandr Lyapunov 2020-06-02 21:36 ` Vladislav Shpilevoy 2020-06-02 21:37 ` 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=cde2578032347540029c2a324d9e50d90c0af64b.1586808463.git.korablev@tarantool.org \ --to=korablev@tarantool.org \ --cc=tarantool-patches@dev.tarantool.org \ --cc=v.shpilevoy@tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH 1/2] vinyl: validate resulting tuple after upsert is applied' \ /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