[Tarantool-patches] [PATCH 10/14] box/txn: move journal entry allocation into separate routine
Cyrill Gorcunov
gorcunov at gmail.com
Wed Feb 19 21:37:09 MSK 2020
For reuse in next patches.
Signed-off-by: Cyrill Gorcunov <gorcunov at gmail.com>
---
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
More information about the Tarantool-patches
mailing list