Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladimir Davydov via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: mechanik20051988 <mechanik20051988@tarantool.org>
Cc: v.shpilevoy@tarantool.org, tarantool-patches@dev.tarantool.org,
	mechanik20051988 <mechanik20.05.1988@gmail.com>
Subject: Re: [Tarantool-patches] [PATCH 3/7] txn: detach transaction from fiber.
Date: Fri, 6 Aug 2021 11:51:07 +0300	[thread overview]
Message-ID: <20210806085107.e3z6s6she6ikgmha@esperanza> (raw)
In-Reply-To: <970c0f5f41acb002a2f95f0774aba7667b91036c.1628184138.git.mechanik20.05.1988@gmail.com>

On Thu, Aug 05, 2021 at 09:17:41PM +0300, mechanik20051988 wrote:
> 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.

This is not true anymore, because you clear both triggers on detach.
Please revert this part.

> 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);

This trigger needs to be cleared only if TXN_CAN_YIELD is unset.
Then you don't need to modify txn_begin and txn_can_yield.

> +	trigger_clear(&txn->fiber_on_stop);
> +	fiber_set_txn(fiber(), NULL);
> +	return txn;
> +}
> \ No newline at end of file

Please fix.

> 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);
> +

I think we should introduce txn_attach, for symmetry and so as not
access fiber storage directly from the iproto code, but to be sure I
need to see the patch that makes use of this function, which is the next
to the last one in the series...

This means that there's no point in this patch alone - it doesn't ease
the review process, because to figure out how the function it introduces
is going to be used, the reviewer needs to look at a following patch.
Besides, the code it introduces is never used nor tested until the rest
of the series is applied so it can't be committed right now.

That being said, please fold this patch into the commit introducing
transactions in the protocol.

  reply	other threads:[~2021-08-06  8:51 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 ` [Tarantool-patches] [PATCH 3/7] txn: detach transaction from fiber mechanik20051988 via Tarantool-patches
2021-08-06  8:51   ` Vladimir Davydov via Tarantool-patches [this message]
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=20210806085107.e3z6s6she6ikgmha@esperanza \
    --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