From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-f196.google.com (mail-lj1-f196.google.com [209.85.208.196]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 70F194696C8 for ; Wed, 19 Feb 2020 21:39:12 +0300 (MSK) Received: by mail-lj1-f196.google.com with SMTP id q23so1458289ljm.4 for ; Wed, 19 Feb 2020 10:39:12 -0800 (PST) From: Cyrill Gorcunov Date: Wed, 19 Feb 2020 21:37:09 +0300 Message-Id: <20200219183713.17646-11-gorcunov@gmail.com> In-Reply-To: <20200219183713.17646-1-gorcunov@gmail.com> References: <20200219183713.17646-1-gorcunov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH 10/14] box/txn: move journal entry allocation into separate routine List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: tml For reuse in next patches. Signed-off-by: Cyrill Gorcunov --- src/box/txn.c | 44 ++++++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/src/box/txn.c b/src/box/txn.c index a6a0704c8..4dbaf5b91 100644 --- a/src/box/txn.c +++ b/src/box/txn.c @@ -494,41 +494,57 @@ txn_entry_complete_cb(struct journal_entry *entry, void *data) fiber_set_txn(fiber(), NULL); } -static int64_t -txn_write_to_wal_async(struct txn *txn) +/** + * Allocate and prepare new journal entry. + */ +static struct journal_entry * +txn_entry_new(struct txn *txn) { assert(txn->n_new_rows + txn->n_applier_rows > 0); + struct journal_entry *req; + struct txn_stmt *stmt; - /* Prepare a journal entry. */ - struct journal_entry *req = journal_entry_new(txn->n_new_rows + - txn->n_applier_rows, - &txn->region, - txn_entry_complete_cb, - txn); - if (req == NULL) { - txn_rollback(txn); - return -1; - } + req = journal_entry_new(txn->n_new_rows + txn->n_applier_rows, + &txn->region, txn_entry_complete_cb, txn); + if (req == NULL) + return NULL; - struct txn_stmt *stmt; struct xrow_header **remote_row = req->rows; struct xrow_header **local_row = req->rows + txn->n_applier_rows; + stailq_foreach_entry(stmt, &txn->stmts, next) { if (stmt->has_triggers) { txn_init_triggers(txn); rlist_splice(&txn->on_commit, &stmt->on_commit); } + + /* A read (e.g. select) request */ if (stmt->row == NULL) - continue; /* A read (e.g. select) request */ + continue; + if (stmt->row->replica_id == 0) *local_row++ = stmt->row; else *remote_row++ = stmt->row; + req->approx_len += xrow_approx_len(stmt->row); } + assert(remote_row == req->rows + txn->n_applier_rows); assert(local_row == remote_row + txn->n_new_rows); + return req; +} + +static int64_t +txn_write_to_wal_async(struct txn *txn) +{ + struct journal_entry *req = txn_entry_new(txn); + if (req == NULL) { + txn_rollback(txn); + return -1; + } + /* Send the entry to the journal. */ if (journal_write_async(req) < 0) { diag_set(ClientError, ER_WAL_IO); -- 2.20.1