Tarantool development patches archive
 help / color / mirror / Atom feed
From: Konstantin Osipov <kostja.osipov@gmail.com>
To: Nikita Pettik <korablev@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org, v.shpilevoy@tarantool.org
Subject: Re: [Tarantool-patches] [PATCH v3 1/2] b-tree: return NULL on matras_alloc fail
Date: Tue, 4 Feb 2020 21:25:41 +0300	[thread overview]
Message-ID: <20200204182541.GA6876@atlas> (raw)
In-Reply-To: <20200204180853.GA78702@tarantool.org>

* Nikita Pettik <korablev@tarantool.org> [20/02/04 21:10]:
> On 04 Feb 20:25, Konstantin Osipov wrote:
> > * Nikita Pettik <korablev@tarantool.org> [20/02/04 20:21]:
> > > > > On 20 Jan 21:13, Ilya Kosarev wrote:
> > > > > > In bps_tree_create_leaf we use matras_alloc in case
> > > > > > bps_tree_garbage_pop didn't work out. However it also might not
> > > > > > succeed. Then we need to return NULL instead of dereferencing NULL
> > > > > > pointer.
> > > > 
> > > > I don't understand the attempt to fix it.
> > > > 
> > > > The reason the allocations are not checked - most likely -because
> > > > BPS should refuse to even begin an operation if there is not
> > > > enough memory in matras.
> > > 
> > > According to the code it doesn't look so. Matras allocation checked
> > > on fails, except two ones in bps_tree_create_inner() and
> > > bps_tree_create_leaf().
> > 
> > Because reserve_blocks() should reserve enough blocks or fail, and
> > it is called before create_inner/create_leaf in all execution paths?
> 
> Consider following path:
> 
> memtx_tree_index_replace
> |
> ->memtx_tree_insert (bps_tree_insert)
>   |
>   ->bps_tree_insert_first_elem
>     |
>     ->bps_tree_create_leaf
>       |
>       -> matras_alloc
> 
> In this case reserve_blocks() is not called. AFAIU path is likely to
> be reachable. Am I missing smth?

No, in this trace I agree with you, we clearly see some sort of
refactoring artefact or a coding bug.

What I am observing is that bps_tree_insert_first_elem() actually checks
the return value of bps_tree_create_leaf(). But
bps_tree_create_leaf() never returns NULL, so this check is never
false.

bps was originally written in C++, so all of these checks for OOm
were added when it was rewritten in C, after the fact.

Looks like we're dealing with an artefact of this rewrite - the
checks are not consistent.


-- 
Konstantin Osipov, Moscow, Russia
https://scylladb.com

  reply	other threads:[~2020-02-04 18:25 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-20 18:13 [Tarantool-patches] [PATCH v3 0/2] Safe truncation and deletion Ilya Kosarev
2020-01-20 18:13 ` [Tarantool-patches] [PATCH v3 1/2] b-tree: return NULL on matras_alloc fail Ilya Kosarev
2020-01-21 10:32   ` Nikita Pettik
2020-01-31  8:18     ` Konstantin Osipov
2020-02-04 17:13       ` Nikita Pettik
2020-02-04 17:25         ` Konstantin Osipov
2020-02-04 18:08           ` Nikita Pettik
2020-02-04 18:25             ` Konstantin Osipov [this message]
2020-01-21 20:55   ` Vladislav Shpilevoy
2020-01-20 18:13 ` [Tarantool-patches] [PATCH v3 2/2] memtx: allow quota overuse for truncation and deletion Ilya Kosarev
2020-01-21 11:42   ` Nikita Pettik
2020-01-21 20:59     ` Vladislav Shpilevoy
2020-02-14 19:57       ` Ilya Kosarev
2020-01-31  8:21   ` Konstantin Osipov
2020-02-04 18:56     ` Ilya Kosarev
2020-02-04 20:06       ` Konstantin Osipov
2020-02-05 19:11         ` Ilya Kosarev
2020-02-05 19:17           ` Konstantin Osipov
2020-02-06 10:50             ` Ilya Kosarev
2020-02-06 14:29               ` Konstantin Osipov
2020-02-06 16:14                 ` Ilya Kosarev
2020-02-06 16:26                   ` Konstantin Osipov
2020-02-10  8:24                     ` Ilya Kosarev
2020-02-10  9:49                       ` Konstantin Osipov
2020-02-10 10:43                         ` Ilya Kosarev
2020-02-10 10:50                           ` Konstantin Osipov
2020-02-14 19:55                             ` Ilya Kosarev

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=20200204182541.GA6876@atlas \
    --to=kostja.osipov@gmail.com \
    --cc=korablev@tarantool.org \
    --cc=tarantool-patches@dev.tarantool.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH v3 1/2] b-tree: return NULL on matras_alloc fail' \
    /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