From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id E449171212; Thu, 5 Aug 2021 21:19:19 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org E449171212 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1628187560; bh=3Cmbv5miZQb3Ii1fdvL52G7PiWtHx2VTxsA/3QxkmEA=; h=To:Cc:Date:In-Reply-To:References:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=ecIZNV7z7ZaSWATgsBZnTEm+nITc+zNvS0wZhco9rsVwqw8gSP7gfpRbVMC0W4ySN mZ32JnJZBQ6G9vzIvbu7F65SZy3+zJpa1OCBcJYliqQuKjJJapA/F9Ukibi0JhHinI P3DR9426hLiJSFQliDuTVAaqNaUP2N1LWAodT5yo= Received: from smtp53.i.mail.ru (smtp53.i.mail.ru [94.100.177.113]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id D3A04741D7 for ; Thu, 5 Aug 2021 21:17:51 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org D3A04741D7 Received: by smtp53.i.mail.ru with esmtpa (envelope-from ) id 1mBhwE-0005CS-VN; Thu, 05 Aug 2021 21:17:51 +0300 To: v.shpilevoy@tarantool.org, vdavydov@tarantool.org Cc: tarantool-patches@dev.tarantool.org, mechanik20051988 Date: Thu, 5 Aug 2021 21:17:41 +0300 Message-Id: <970c0f5f41acb002a2f95f0774aba7667b91036c.1628184138.git.mechanik20.05.1988@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD92087353F0EC44DD94BB7C0677F3ED9D05EB08EAFC9298EA6182A05F53808504005AA9F5E9178D1945235236265C3068A3A8C3F4C848838696702356247F7609D X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE706EA9E10470DC775EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006373768BF035B57E5168638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D810D92D614847E73ECCF179078E3BD1EC117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC55D5BE2F85BDEC5FA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352026055571C92BF10FC26CFBAC0749D213D2E47CDBA5A96583BA9C0B312567BB2376E601842F6C81A19E625A9149C048EE9647ADFADE5905B14DB3626BA78294CCD8FC6C240DEA7642DBF02ECDB25306B2B78CF848AE20165D0A6AB1C7CE11FEE386A7C529F68B8E5C302FCEF25BFAB345C4224003CC836476EA7A3FFF5B025636E2021AF6380DFAD1A18204E546F3947CB11811A4A51E3B096D1867E19FE1407959CC434672EE6371089D37D7C0E48F6C8AA50765F790063780E7E366B0FF8F58EFF80C71ABB335746BA297DBC24807EABDAD6C7F3747799A X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8183A4AFAF3EA6BDC446469D8A8717206BB30CE973C7F71088D389F09A950265B5527C5BB646FA45C2E9C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EF3033054805BDE987699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34F3735C80F9F4B96D995C1C12E6A9074168E8BEA2956EE8B66659B8326A98B5A6AEDE531AD26DD0C01D7E09C32AA3244CFF0C0DBA27B9286FDE5734AD1A12800E69B6CAE0477E908D927AC6DF5659F194 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojh4v93/7HD3UBeqyC/MvT/Q== X-Mailru-Sender: 583F1D7ACE8F49BD29FC049B2A5BF963272C3B768E89E9F19BAD4FFA1A30E747ED0389503CE99B38B79567116EAC6FCF4E830D9205DBEA545646F0D3C63A617F27ACC94E9A535D22112434F685709FCF0DA7A0AF5A3A8387 X-Mras: Ok Subject: [Tarantool-patches] [PATCH 3/7] txn: detach transaction from fiber. X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: mechanik20051988 via Tarantool-patches Reply-To: mechanik20051988 Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" From: mechanik20051988 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