From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp45.i.mail.ru (smtp45.i.mail.ru [94.100.177.105]) (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 99F7D445321 for ; Mon, 20 Jul 2020 23:43:10 +0300 (MSK) From: Vladislav Shpilevoy Date: Mon, 20 Jul 2020 22:43:06 +0200 Message-Id: <3701daa1eb82b9d24fdf110b17f8438186d8f897.1595277631.git.v.shpilevoy@tarantool.org> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH 2/2] txn: single failure point for WAL and TX async commit errors List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: tarantool-patches@dev.tarantool.org, gorcunov@gmail.com The same as the previous commit, but applied to the async transaction commit (txn_commit_async()). There were 6 failure points. After the patch the failures are handled in one place. Follow up #5146 --- src/box/txn.c | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/src/box/txn.c b/src/box/txn.c index 375c01f85..bd9fcdbe6 100644 --- a/src/box/txn.c +++ b/src/box/txn.c @@ -711,23 +711,18 @@ txn_commit_async(struct txn *txn) * output to mark this event. */ diag_log(); - txn_rollback(txn); - return -1; + goto rollback; }); - if (txn_prepare(txn) != 0) { - txn_rollback(txn); - return -1; - } + if (txn_prepare(txn) != 0) + goto rollback; if (txn_commit_nop(txn)) return 0; req = txn_journal_entry_new(txn); - if (req == NULL) { - txn_rollback(txn); - return -1; - } + if (req == NULL) + goto rollback; bool is_sync = txn_has_flag(txn, TXN_WAIT_SYNC); struct txn_limbo_entry *limbo_entry; @@ -741,19 +736,16 @@ txn_commit_async(struct txn *txn) struct trigger *trig = region_alloc_object(&txn->region, typeof(*trig), &size); if (trig == NULL) { - txn_rollback(txn); diag_set(OutOfMemory, size, "region_alloc_object", "trig"); - return -1; + goto rollback; } /* See txn_commit(). */ uint32_t origin_id = req->rows[0]->replica_id; limbo_entry = txn_limbo_append(&txn_limbo, origin_id, txn); - if (limbo_entry == NULL) { - txn_rollback(txn); - return -1; - } + if (limbo_entry == NULL) + goto rollback; if (txn_has_flag(txn, TXN_WAIT_ACK)) { int64_t lsn = req->rows[txn->n_applier_rows - 1]->lsn; @@ -779,14 +771,17 @@ txn_commit_async(struct txn *txn) fiber_set_txn(fiber(), NULL); if (journal_write_async(req) != 0) { fiber_set_txn(fiber(), txn); - txn_rollback(txn); - diag_set(ClientError, ER_WAL_IO); diag_log(); - return -1; + goto rollback; } return 0; + +rollback: + assert(txn->fiber == NULL); + txn_rollback(txn); + return -1; } int -- 2.21.1 (Apple Git-122.3)