From: mechanik20051988 via Tarantool-patches <tarantool-patches@dev.tarantool.org> To: v.shpilevoy@tarantool.org, vdavydov@tarantool.org Cc: tarantool-patches@dev.tarantool.org, mechanik20051988 <mechanik20.05.1988@gmail.com> Subject: [Tarantool-patches] [PATCH 3/7] txn: detach transaction from fiber. Date: Thu, 5 Aug 2021 21:17:41 +0300 [thread overview] Message-ID: <970c0f5f41acb002a2f95f0774aba7667b91036c.1628184138.git.mechanik20.05.1988@gmail.com> (raw) In-Reply-To: <cover.1628184138.git.mechanik20.05.1988@gmail.com> From: mechanik20051988 <mechanik20.05.1988@gmail.com> Detach transaction from fiber: now it is possible to start transaction in fiber, save the pointer to it in some place independent from the fiber and then restore it other fiber. For this purpose `fiber_on_stop` and `fiber_on_yield` triggers was changed: previously they received pointer to transaction from the fiber storage, now they receive it as their argument, because fiber storage can be already empty when they called. Also implement function `txn_detach`, which clear `fiber_on_stop` and `fiber_on_yeild` triggers. Detached transaction does not rollback in case when fiber stopped, but can be aborted in case it does not support yeild. Path of #5860 --- src/box/txn.c | 29 ++++++++++++++++++++++------- src/box/txn.h | 11 +++++++++++ 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/src/box/txn.c b/src/box/txn.c index b80e722a4..de6a7f37d 100644 --- a/src/box/txn.c +++ b/src/box/txn.c @@ -302,8 +302,9 @@ txn_begin(void) rlist_create(&txn->savepoints); txn->fiber = NULL; fiber_set_txn(fiber(), txn); - /* fiber_on_yield is initialized by engine on demand */ - trigger_create(&txn->fiber_on_stop, txn_on_stop, NULL, NULL); + trigger_create(&txn->fiber_on_yield, txn_on_yield, txn, NULL); + trigger_create(&txn->fiber_on_stop, txn_on_stop, txn, NULL); + /* fiber_on_yield is added by engine on demand */ trigger_add(&fiber()->on_stop, &txn->fiber_on_stop); /* * By default all transactions may yield. @@ -1016,7 +1017,6 @@ txn_can_yield(struct txn *txn, bool set) trigger_clear(&txn->fiber_on_yield); } else if (!set && could) { txn_clear_flags(txn, TXN_CAN_YIELD); - trigger_create(&txn->fiber_on_yield, txn_on_yield, NULL, NULL); trigger_add(&fiber()->on_yield, &txn->fiber_on_yield); } return could; @@ -1216,9 +1216,8 @@ txn_savepoint_release(struct txn_savepoint *svp) static int txn_on_stop(struct trigger *trigger, void *event) { - (void) trigger; (void) event; - struct txn *txn = in_txn(); + struct txn *txn = trigger->data; assert(txn->signature == TXN_SIGNATURE_UNKNOWN); txn->signature = TXN_SIGNATURE_ROLLBACK; txn_rollback(txn); @@ -1246,12 +1245,28 @@ txn_on_stop(struct trigger *trigger, void *event) static int txn_on_yield(struct trigger *trigger, void *event) { - (void) trigger; (void) event; - struct txn *txn = in_txn(); + struct txn *txn = trigger->data; assert(txn != NULL); assert(!txn_has_flag(txn, TXN_CAN_YIELD)); txn_rollback_to_svp(txn, NULL); txn_set_flags(txn, TXN_IS_ABORTED_BY_YIELD); return 0; } + +struct txn * +txn_detach(void) +{ + struct txn *txn = in_txn(); + if (txn == NULL) + return NULL; + if (!txn_has_flag(txn, TXN_CAN_YIELD)) { + struct trigger trigger; + trigger.data = txn; + txn_on_yield(&trigger, NULL); + } + trigger_clear(&txn->fiber_on_yield); + trigger_clear(&txn->fiber_on_stop); + fiber_set_txn(fiber(), NULL); + return txn; +} \ No newline at end of file diff --git a/src/box/txn.h b/src/box/txn.h index 8741dc6a1..b8bba67b8 100644 --- a/src/box/txn.h +++ b/src/box/txn.h @@ -457,6 +457,17 @@ fiber_set_txn(struct fiber *fiber, struct txn *txn) fiber->storage.txn = txn; } +/** + * Detach transaction from fiber. + * By default if the fiber is stopped the transaction + * started in this fiber is rollback. This function + * detaches transaction from fiber, leaving it alive + * after fiber is stopped. + * @pre txn == in_txn() + */ +struct txn * +txn_detach(void); + /** * Start a transaction explicitly. * @pre no transaction is active -- 2.20.1
next prev parent reply other threads:[~2021-08-05 18:19 UTC|newest] Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-08-05 18:17 [Tarantool-patches] [PATCH 0/7] implement iproto streams mechanik20051988 via Tarantool-patches 2021-08-05 18:17 ` [Tarantool-patches] [PATCH 1/7] iproto: implement stream id in binary iproto protocol mechanik20051988 via Tarantool-patches 2021-08-06 8:20 ` Vladimir Davydov via Tarantool-patches 2021-08-05 18:17 ` [Tarantool-patches] [PATCH 2/7] salad: fix segfault in case when mhash table allocation failure mechanik20051988 via Tarantool-patches 2021-08-06 8:33 ` Vladimir Davydov via Tarantool-patches 2021-08-05 18:17 ` mechanik20051988 via Tarantool-patches [this message] 2021-08-06 8:51 ` [Tarantool-patches] [PATCH 3/7] txn: detach transaction from fiber Vladimir Davydov via Tarantool-patches 2021-08-05 18:17 ` [Tarantool-patches] [PATCH 4/7] iproto: implement streams in iproto mechanik20051988 via Tarantool-patches 2021-08-06 10:30 ` Vladimir Davydov via Tarantool-patches 2021-08-05 18:17 ` [Tarantool-patches] [PATCH 5/7] net.box: add stream support to net.box mechanik20051988 via Tarantool-patches 2021-08-06 12:03 ` Vladimir Davydov via Tarantool-patches 2021-08-05 18:17 ` [Tarantool-patches] [PATCH 6/7] iproto: implement interactive transactions over iproto streams mechanik20051988 via Tarantool-patches 2021-08-06 12:59 ` Vladimir Davydov via Tarantool-patches 2021-08-09 10:39 ` Vladimir Davydov via Tarantool-patches 2021-08-09 10:40 ` [Tarantool-patches] [PATCH 1/2] xrow: remove unused call_request::header Vladimir Davydov via Tarantool-patches 2021-08-09 10:40 ` [Tarantool-patches] [PATCH 2/2] iproto: clear request::header for client requests Vladimir Davydov via Tarantool-patches 2021-08-09 11:27 ` Evgeny Mekhanik via Tarantool-patches 2021-08-09 11:26 ` [Tarantool-patches] [PATCH 1/2] xrow: remove unused call_request::header Evgeny Mekhanik via Tarantool-patches 2021-08-05 18:17 ` [Tarantool-patches] [PATCH 7/7] net.box: add interactive transaction support in net.box mechanik20051988 via Tarantool-patches 2021-08-06 14:04 ` Vladimir Davydov via Tarantool-patches
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=970c0f5f41acb002a2f95f0774aba7667b91036c.1628184138.git.mechanik20.05.1988@gmail.com \ --to=tarantool-patches@dev.tarantool.org \ --cc=mechanik20.05.1988@gmail.com \ --cc=mechanik20051988@tarantool.org \ --cc=v.shpilevoy@tarantool.org \ --cc=vdavydov@tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH 3/7] txn: detach transaction from fiber.' \ /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