From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 323462850D for ; Wed, 6 Mar 2019 15:16:26 -0500 (EST) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id rj2UhM9vY3We for ; Wed, 6 Mar 2019 15:16:26 -0500 (EST) Received: from smtp34.i.mail.ru (smtp34.i.mail.ru [94.100.177.94]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id D674428507 for ; Wed, 6 Mar 2019 15:16:25 -0500 (EST) From: Georgy Kirichenko Subject: [tarantool-patches] [PATCH v2 2/3] Put all new rows to the end of journal request Date: Wed, 6 Mar 2019 23:16:17 +0300 Message-Id: <2134b8fca0963ebd0a8fb818a66cd05e81ef09a6.1551902962.git.georgy@tarantool.org> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-Help: List-Unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-Subscribe: List-Owner: List-post: List-Archive: To: tarantool-patches@freelists.org Cc: Georgy Kirichenko Form a separate transaction with all local changes in case of replication. This is important because we should be able to replicate such changes (e.g. made within an on_replace triggers) back. In the opposite case local changes will be incorporated into originating transaction and wold be skipped by originator replica. Needed for: #2798 --- src/box/txn.c | 36 ++++++++++++++++++++++++++++-------- src/box/txn.h | 4 ++++ 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/src/box/txn.c b/src/box/txn.c index 7900fb3ab..187e1c085 100644 --- a/src/box/txn.c +++ b/src/box/txn.c @@ -141,6 +141,8 @@ txn_begin(bool is_autocommit) /* Initialize members explicitly to save time on memset() */ stailq_create(&txn->stmts); txn->n_rows = 0; + txn->has_rows_with_lsn = false; + txn->has_rows_without_lsn = false; txn->is_autocommit = is_autocommit; txn->has_triggers = false; txn->is_aborted = false; @@ -233,6 +235,8 @@ txn_commit_stmt(struct txn *txn, struct request *request) if (stmt->space == NULL || !space_is_temporary(stmt->space)) { if (txn_add_redo(stmt, request) != 0) goto fail; + txn->has_rows_with_lsn |= stmt->row->replica_id != 0; + txn->has_rows_without_lsn |= stmt->row->replica_id == 0; ++txn->n_rows; } /* @@ -272,13 +276,29 @@ txn_write_to_wal(struct txn *txn) struct txn_stmt *stmt; struct xrow_header **row = req->rows; - stailq_foreach_entry(stmt, &txn->stmts, next) { - if (stmt->row == NULL) - continue; /* A read (e.g. select) request */ - *row++ = stmt->row; - req->approx_len += xrow_approx_len(stmt->row); + if (txn->has_rows_with_lsn) { + /* Write out rows that already have an assigned lsn. */ + stailq_foreach_entry(stmt, &txn->stmts, next) { + if (stmt->row == NULL) + continue; /* A read (e.g. select) request */ + if (stmt->row->replica_id == 0) + continue; /* A row without lsn. */ + *row++ = stmt->row; + req->approx_len += xrow_approx_len(stmt->row); + } + } + if (txn->has_rows_without_lsn) { + /* Write out rows to assign a lsn. */ + stailq_foreach_entry(stmt, &txn->stmts, next) { + if (stmt->row == NULL) + continue; /* A read (e.g. select) request */ + if (stmt->row->replica_id != 0) + continue; /* A row with lsn. */ + *row++ = stmt->row; + req->approx_len += xrow_approx_len(stmt->row); + } } - assert(row == req->rows + req->n_rows); + assert(row == req->rows + txn->n_rows); ev_tstamp start = ev_monotonic_now(loop()); int64_t res = journal_write(req); @@ -399,8 +419,6 @@ txn_rollback() txn_stmt_unref_tuples(stmt); TRASH(txn); - /** Free volatile txn memory. */ - fiber_gc(); fiber_set_txn(fiber(), NULL); } @@ -480,6 +498,8 @@ box_txn_rollback() return -1; } txn_rollback(); /* doesn't throw */ + /** Free volatile txn memory. */ + fiber_gc(); return 0; } diff --git a/src/box/txn.h b/src/box/txn.h index de5cb0de4..cb82ff25b 100644 --- a/src/box/txn.h +++ b/src/box/txn.h @@ -142,6 +142,10 @@ struct txn { struct stailq stmts; /** Total number of WAL rows in this txn. */ int n_rows; + /** True if the txn has rows with an assigned lsn. */ + bool has_rows_with_lsn; + /** True if the txn has rows without a lsn. */ + bool has_rows_without_lsn; /** * True if this transaction is running in autocommit mode * (statement end causes an automatic transaction commit). -- 2.21.0