From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: From: Vladimir Davydov Subject: [PATCH v2 1/3] txn: move stmt list/savepoint manipulation out of txn_stmt_new Date: Tue, 30 Jul 2019 13:49:13 +0300 Message-Id: <37bedba5d2f3670547633d0c70169e47d6f6476b.1564483378.git.vdavydov.dev@gmail.com> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit To: tarantool-patches@freelists.org List-ID: txn_stmt_new is supposed to simply allocate an initialize a new txn_stmt struct. Adding the new statement to the txn's statement list and setting up a savepoint for rollback looks confusing. Move it to txn_begin_stmt. --- src/box/txn.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/box/txn.c b/src/box/txn.c index 05ec6f14..27ae43ac 100644 --- a/src/box/txn.c +++ b/src/box/txn.c @@ -84,10 +84,10 @@ txn_add_redo(struct txn *txn, struct txn_stmt *stmt, struct request *request) /** Initialize a new stmt object within txn. */ static struct txn_stmt * -txn_stmt_new(struct txn *txn) +txn_stmt_new(struct region *region) { struct txn_stmt *stmt; - stmt = region_alloc_object(&txn->region, struct txn_stmt); + stmt = region_alloc_object(region, struct txn_stmt); if (stmt == NULL) { diag_set(OutOfMemory, sizeof(*stmt), "region", "struct txn_stmt"); @@ -100,12 +100,6 @@ txn_stmt_new(struct txn *txn) stmt->new_tuple = NULL; stmt->engine_savepoint = NULL; stmt->row = NULL; - - /* Set the savepoint for statement rollback. */ - txn->sub_stmt_begin[txn->in_sub_stmt] = stailq_last(&txn->stmts); - txn->in_sub_stmt++; - - stailq_add_tail_entry(&txn->stmts, stmt, next); return stmt; } @@ -246,9 +240,15 @@ txn_begin_stmt(struct txn *txn, struct space *space) diag_set(ClientError, ER_SUB_STMT_MAX); return -1; } - struct txn_stmt *stmt = txn_stmt_new(txn); + struct txn_stmt *stmt = txn_stmt_new(&txn->region); if (stmt == NULL) return -1; + + /* Set the savepoint for statement rollback. */ + txn->sub_stmt_begin[txn->in_sub_stmt] = stailq_last(&txn->stmts); + txn->in_sub_stmt++; + stailq_add_tail_entry(&txn->stmts, stmt, next); + if (space == NULL) return 0; -- 2.20.1