From: Nikita Pettik <korablev@tarantool.org> To: tarantool-patches@dev.tarantool.org Cc: v.shpilevoy@tarantool.org Subject: [Tarantool-patches] [PATCH 2/2] vinyl: clean-up read views if *_build_history() fails Date: Thu, 9 Apr 2020 00:37:08 +0300 [thread overview] Message-ID: <73e1f0baf18ec008312d91db4449447b3c06aa86.1586381297.git.korablev@tarantool.org> (raw) In-Reply-To: <cover.1586381297.git.korablev@tarantool.org> In-Reply-To: <cover.1586381297.git.korablev@tarantool.org> vy_write_iterator->read_views[i].history objects are allocated on region (see vy_write_iterator_push_rv()) during building history of the given key. However, in case of fail of vy_write_iterator_build_history() region is truncated but pointers to vy_write_history objects are not nullified. As a result, they may be accessed (for instance while finalizing write_iterator object in vy_write_iterator_stop) which in turn may lead to crash, segfaul or disk formatting. Let's nullify those objects right after function returns with rc != 0. Closes #4864 --- src/box/vy_write_iterator.c | 5 +- .../gh-4864-stmt-alloc-fail-compact.result | 51 +++++++++++++++++++ .../gh-4864-stmt-alloc-fail-compact.test.lua | 24 +++++++++ 3 files changed, 79 insertions(+), 1 deletion(-) diff --git a/src/box/vy_write_iterator.c b/src/box/vy_write_iterator.c index 7a6a20627..f6e6ed4d2 100644 --- a/src/box/vy_write_iterator.c +++ b/src/box/vy_write_iterator.c @@ -961,8 +961,11 @@ vy_write_iterator_build_read_views(struct vy_write_iterator *stream, int *count) size_t used = region_used(region); stream->rv_used_count = 0; if (vy_write_iterator_build_history(stream, &raw_count, - &is_first_insert) != 0) + &is_first_insert) != 0) { + for (int i = 0; i < stream->rv_count; ++i) + stream->read_views[i].history = NULL; goto error; + } if (raw_count == 0) { /* A key is fully optimized. */ region_truncate(region, used); diff --git a/test/vinyl/gh-4864-stmt-alloc-fail-compact.result b/test/vinyl/gh-4864-stmt-alloc-fail-compact.result index 2c03697f6..770efcca8 100644 --- a/test/vinyl/gh-4864-stmt-alloc-fail-compact.result +++ b/test/vinyl/gh-4864-stmt-alloc-fail-compact.result @@ -91,3 +91,54 @@ s.index.pk:stat().run_count s:drop() | --- | ... + +-- All the same except for delayed vy_stmt_alloc() fail. +-- Re-create space for the sake of test purity. +-- +s = box.schema.space.create('test', {engine = 'vinyl'}) + | --- + | ... +_ = s:create_index('pk', {run_count_per_level = 100, page_size = 128, range_size = 1024}) + | --- + | ... + +dump(true) + | --- + | ... +dump() + | --- + | ... + +compact() + | --- + | ... + +dump() + | --- + | ... + +errinj = box.error.injection + | --- + | ... +errinj.set('ERRINJ_VY_MAX_TUPLE_SIZE', 0) + | --- + | - ok + | ... +-- Should finish successfully despite vy_stmt_alloc() fail. +-- +compact() + | --- + | ... +-- 1 range, 1 run +s.index.pk:stat().range_count + | --- + | - 1 + | ... +s.index.pk:stat().run_count + | --- + | - 1 + | ... + +s:drop() + | --- + | ... diff --git a/test/vinyl/gh-4864-stmt-alloc-fail-compact.test.lua b/test/vinyl/gh-4864-stmt-alloc-fail-compact.test.lua index 53a050c9b..8b5c79025 100644 --- a/test/vinyl/gh-4864-stmt-alloc-fail-compact.test.lua +++ b/test/vinyl/gh-4864-stmt-alloc-fail-compact.test.lua @@ -47,3 +47,27 @@ s.index.pk:stat().range_count s.index.pk:stat().run_count s:drop() + +-- All the same except for delayed vy_stmt_alloc() fail. +-- Re-create space for the sake of test purity. +-- +s = box.schema.space.create('test', {engine = 'vinyl'}) +_ = s:create_index('pk', {run_count_per_level = 100, page_size = 128, range_size = 1024}) + +dump(true) +dump() + +compact() + +dump() + +errinj = box.error.injection +errinj.set('ERRINJ_VY_MAX_TUPLE_SIZE', 0) +-- Should finish successfully despite vy_stmt_alloc() fail. +-- +compact() +-- 1 range, 1 run +s.index.pk:stat().range_count +s.index.pk:stat().run_count + +s:drop() -- 2.17.1
next prev parent reply other threads:[~2020-04-08 21:37 UTC|newest] Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-04-08 21:37 [Tarantool-patches] [PATCH 0/2] vinyl: fix uninitialized memory accesses Nikita Pettik 2020-04-08 21:37 ` [Tarantool-patches] [PATCH 1/2] vinyl: init all vars before cleanup in vy_lsm_split_range() Nikita Pettik 2020-04-09 8:18 ` Konstantin Osipov 2020-04-09 10:55 ` Nikita Pettik 2020-04-09 11:07 ` Konstantin Osipov 2020-04-09 11:26 ` Nikita Pettik 2020-04-10 15:13 ` Vladislav Shpilevoy 2020-04-10 15:40 ` Nikita Pettik 2020-04-10 18:24 ` Nikita Pettik 2020-04-11 17:39 ` Vladislav Shpilevoy 2020-04-13 22:29 ` Nikita Pettik 2020-04-14 21:40 ` Nikita Pettik 2020-04-08 21:37 ` Nikita Pettik [this message] 2020-04-09 8:19 ` [Tarantool-patches] [PATCH 2/2] vinyl: clean-up read views if *_build_history() fails Konstantin Osipov 2020-04-09 11:09 ` Nikita Pettik 2020-04-10 15:13 ` Vladislav Shpilevoy 2020-04-10 15:47 ` Nikita Pettik 2020-04-10 21:45 ` Nikita Pettik 2020-04-10 22:32 ` Vladislav Shpilevoy 2020-04-11 17:30 ` Konstantin Osipov 2020-04-13 22:31 ` Nikita Pettik 2020-04-13 22:35 ` Konstantin Osipov 2020-04-13 22:11 ` Nikita Pettik 2020-04-11 17:39 ` 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=73e1f0baf18ec008312d91db4449447b3c06aa86.1586381297.git.korablev@tarantool.org \ --to=korablev@tarantool.org \ --cc=tarantool-patches@dev.tarantool.org \ --cc=v.shpilevoy@tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH 2/2] vinyl: clean-up read views if *_build_history() fails' \ /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