From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtpng2.m.smailru.net (smtpng2.m.smailru.net [94.100.179.3]) (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 DC74942EF5C for ; Wed, 24 Jun 2020 01:16:19 +0300 (MSK) From: Vladislav Shpilevoy Date: Wed, 24 Jun 2020 00:16:18 +0200 Message-Id: <6e27b7a8eb9cf5f294e360484a50caf764136a39.1592950555.git.v.shpilevoy@tarantool.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH 1/1] [tosquash] txn: refactor txn_commit_async List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: tarantool-patches@dev.tarantool.org, sergepetrenko@tarantool.org * txn_free() is not needed in txn_commit_async() when it fails. It is done in txn_rollback() if necessary; * if on_rollback trigger allocation failed, the transaction wasn't rolled back. --- Branch: http://github.com/tarantool/tarantool/tree/gh-4842-sync-replication Issue: https://github.com/tarantool/tarantool/issues/4842 src/box/txn.c | 51 ++++++++++++++++++++++----------------------------- 1 file changed, 22 insertions(+), 29 deletions(-) diff --git a/src/box/txn.c b/src/box/txn.c index 2e2b225c0..400705d36 100644 --- a/src/box/txn.c +++ b/src/box/txn.c @@ -659,56 +659,49 @@ txn_commit_async(struct txn *txn) bool is_sync = txn_has_flag(txn, TXN_WAIT_ACK); struct txn_limbo_entry *limbo_entry; if (is_sync) { + /* + * We'll need this trigger for sync transactions later, + * but allocation failure is inappropriate after the entry + * is sent to journal, so allocate early. + */ + size_t size; + 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; + } + /* See txn_commit(). */ uint32_t origin_id = req->rows[0]->replica_id; int64_t lsn = req->rows[txn->n_applier_rows - 1]->lsn; limbo_entry = txn_limbo_append(&txn_limbo, origin_id, txn); if (limbo_entry == NULL) { txn_rollback(txn); - txn_free(txn); return -1; } assert(lsn > 0); txn_limbo_assign_lsn(&txn_limbo, limbo_entry, lsn); - } - /* - * We'll need this trigger for sync transactions later, - * but allocation failure is inappropriate after the entry - * is sent to journal, so allocate early. - */ - struct trigger *trig; - if (is_sync) { - size_t size; - trig = region_alloc_object(&txn->region, typeof(*trig), &size); - if (trig == NULL) { - diag_set(OutOfMemory, size, "region_alloc_object", - "trig"); - return -1; - } + /* + * Set a trigger to abort waiting for confirm on + * WAL write failure. + */ + trigger_create(trig, txn_limbo_on_rollback, + limbo_entry, NULL); + txn_on_rollback(txn, trig); } fiber_set_txn(fiber(), NULL); if (journal_write_async(req) != 0) { fiber_set_txn(fiber(), txn); txn_rollback(txn); - if (is_sync) - txn_limbo_abort(&txn_limbo, limbo_entry); - diag_set(ClientError, ER_WAL_IO); diag_log(); return -1; } - - if (is_sync) { - /* - * Set a trigger to abort waiting for confirm on - * WAL write failure. - */ - trigger_create(trig, txn_limbo_on_rollback, - limbo_entry, NULL); - txn_on_rollback(txn, trig); - } return 0; } -- 2.21.1 (Apple Git-122.3)