Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
To: imeevma@tarantool.org, sergos@tarantool.org
Cc: tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH v1 1/1] sql: do not reset region on select
Date: Wed, 4 Nov 2020 23:14:38 +0100	[thread overview]
Message-ID: <46f1c499-b84b-7c4a-d8a1-189d3c5965d9@tarantool.org> (raw)
In-Reply-To: <de3a3542d3f69017d221a681dd5476f0fd240ba2.1604310090.git.imeevma@gmail.com>

Hi! Thanks for the patch!

See 2 comments below.

On 02.11.2020 10:49, imeevma@tarantool.org wrote:
> Prior to this patch, region on fiber was reset during select(), get(),
> count(), max(), or min(). This would result in an error if one of these
> operations was used in a user-defined function in SQL. After this patch,
> these functions truncate region instead of resetting it.
> 
> Closes #5427
> ---
> https://github.com/tarantool/tarantool/issues/5427
> https://github.com/tarantool/tarantool/tree/imeevma/gh-5427-lua-func-changes-result
> 
> @ChangeLog
>  - Region truncated instead of resetting on select() (gh-5427).

1. I suggest to make the message more understandable for users. They have
no idea what a region is. For instance, consider

	Memory corruption when SQL called Lua functions with box calls inside

>  src/box/box.cc                                |   5 +-
>  src/box/index.cc                              |  20 +++
>  src/box/txn.h                                 |   6 +-
>  .../gh-5427-lua-func-changes-result.result    | 153 ++++++++++++++++++
>  .../gh-5427-lua-func-changes-result.test.lua  |  86 ++++++++++
>  5 files changed, 264 insertions(+), 6 deletions(-)
>  create mode 100644 test/sql/gh-5427-lua-func-changes-result.result
>  create mode 100644 test/sql/gh-5427-lua-func-changes-result.test.lua
> 
> diff --git a/src/box/box.cc b/src/box/box.cc
> index 18568df3b..473ef52ad 100644
> --- a/src/box/box.cc
> +++ b/src/box/box.cc
> @@ -1388,7 +1388,8 @@ box_select(uint32_t space_id, uint32_t index_id,
>  	   struct port *port)
>  {
>  	(void)key_end;
> -
> +	struct region *region = &fiber()->gc;
> +	size_t used = region_used(region);
>  	rmean_collect(rmean_box, IPROTO_SELECT, 1);

2. I must say I couldn't come up with a better idea so far. I remember I
also proposed to start a transaction for each VDBE statement, but not sure
it is a right thing to do.

It means, we probably should go for this one, but a bit polished.

In the current solution I don't like, that you basically just inlined
txn_commit_ro_stmt(), but instead I would rather want you to patch it to
make it work.

So for example txn_begin_ro_stmt inside remembers the current region size,
and returns it via an out parameter struct txn_ro_savepoint *svp. Which
you create on the stack.

Then, after you are done with the statement, you call txn_commit_ro_stmt,
which takes const struct txn_ro_savepoint *svp, and does the region_truncate
inside.

  reply	other threads:[~2020-11-04 22:14 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-02  9:49 imeevma
2020-11-04 22:14 ` Vladislav Shpilevoy [this message]
2020-12-16  5:34   ` Mergen Imeev
2020-12-17 22:04     ` Vladislav Shpilevoy
2020-12-22 19:30       ` Mergen Imeev
2020-12-23 14:58         ` Vladislav Shpilevoy
2020-12-23 19:20           ` Mergen Imeev
2020-12-23 19:15 imeevma
2020-12-24 10:48 ` Nikita Pettik
2020-12-24 10:58   ` Nikita Pettik

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=46f1c499-b84b-7c4a-d8a1-189d3c5965d9@tarantool.org \
    --to=v.shpilevoy@tarantool.org \
    --cc=imeevma@tarantool.org \
    --cc=sergos@tarantool.org \
    --cc=tarantool-patches@dev.tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH v1 1/1] sql: do not reset region on select' \
    /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