From: Alexander Turenko <alexander.turenko@tarantool.org>
To: Leonid Vasiliev <lvasiliev@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH] Move rollback to savepoint from ffi to C-API
Date: Wed, 5 Feb 2020 19:53:09 +0300 [thread overview]
Message-ID: <20200205165309.jnvb6p5sbv2zns54@tkn_work_nb> (raw)
In-Reply-To: <851af63f-4ced-c1de-cac8-eebcd0b6dcd3@tarantool.org>
We agreed on the following wording with Igor and Leonid:
commit 34234427a3cc1f181ef6583c36ed7e4193bafde7
Author: Leonid Vasiliev <lvasiliev@tarantool.org>
Date: Fri Dec 13 10:49:33 2019 +0300
box: rewrite rollback to savepoint to Lua/C
LuaJIT records traces while interpreting Lua bytecode (considering it's
hot enough) in order to compile the corresponding execution flow to a
machine code. A Lua/C call aborts trace recording, but an FFI call does
not abort it per se. If code inside an FFI call yields to another fiber
while recording a trace and the new current fiber interpreting a Lua
bytecode too, then unrelated instructions will be recorded to the
current trace.
In short, we should not yield a current fiber inside an FFI call.
There is another problem. Machine code of a compiled trace may sink a
value from a Lua state down to a host register, change it and write back
only at trace exit. So the interpreter state may be outdated during the
compiled trace execution. A Lua/C call aborts a trace and so the code
inside a callee always see an actual interpreter state. An FFI call
however can be turned into a single machine's CALL instruction in the
compiled code and if the callee accesses a Lua state, then it may see an
irrelevant value.
In short, we should not access a Lua state directly or reenter to the
interpreter from an FFI call.
The box.rollback_to_savepoint() function may yield and another fiber
will be scheduled for execution. If this fiber touches a Lua state, then
it may see an inconsistent state and the behaviour will be undefined.
Noted that <struct txn>.id starts from 1, because we lean on this fact
to use luaL_toint64(), which does not distinguish an unexpected Lua type
and cdata<int64_t> with zero value. It seems that this assumption
already exists: the code that prepare arguments for 'on_commit' triggers
uses luaL_toint64() too (see lbox_txn_pairs()).
Fixes #4427
Co-authored-by: Alexander Turenko <alexander.turenko@tarantool.org>
Reviewed-by: Igor Munkin <imun@tarantool.org>
Pushed to master, 2.3, 2.2 and 1.10.
CCed Kirill.
WBR, Alexander Turenko.
On Mon, Jan 27, 2020 at 10:24:18AM +0300, Leonid Vasiliev wrote:
> The result patch:
>
> https://github.com/tarantool/tarantool/issues/4427
> https://github.com/tarantool/tarantool/tree/lvasiliev/gh-4427-move-rollback-from-ffi-to-c-api-v2
>
> box: rewrite rollback to savepoint to Lua/C
>
> The fix is prevent an emerge of "FFI sandwich".
> See
> https://github.com/tarantool/tarantool/issues/4427#issuecomment-524798109
> for more information.
>
> One of the aims of this change (in addition to the fix) is to increase
> locality of highly
> coupled code for the rollback to savepoint.
>
> Noted that <struct txn>.id starts from 1, because I lean on this fact to
> use luaL_toint64(), which does not distinguish an unexpected Lua type
> case and cdata<int64_t> with zero value. It seems that this assumption
> already exists: the code that prepare arguments for 'on_commit' triggers
> uses luaL_toint64() too (see lbox_txn_pairs()).
>
> Fixes #4427
>
> Co-authored-by: Alexander Turenko<alexander.turenko@tarantool.org>
> Co-authored-by: Leonid Vasiliev<lvasiliev@tarantool.org>
prev parent reply other threads:[~2020-02-05 16:53 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-13 12:08 Leonid Vasiliev
2020-01-16 21:17 ` Alexander Turenko
2020-01-20 21:17 ` Leonid Vasiliev
2020-01-21 2:33 ` Alexander Turenko
2020-01-24 14:35 ` Igor Munkin
2020-01-27 7:24 ` Leonid Vasiliev
2020-02-05 16:53 ` Alexander Turenko [this message]
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=20200205165309.jnvb6p5sbv2zns54@tkn_work_nb \
--to=alexander.turenko@tarantool.org \
--cc=lvasiliev@tarantool.org \
--cc=tarantool-patches@dev.tarantool.org \
--subject='Re: [Tarantool-patches] [PATCH] Move rollback to savepoint from ffi to C-API' \
/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