From: Georgy Kirichenko <georgy@tarantool.org> To: tarantool-patches@freelists.org Cc: Georgy Kirichenko <georgy@tarantool.org> 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 [thread overview] Message-ID: <2134b8fca0963ebd0a8fb818a66cd05e81ef09a6.1551902962.git.georgy@tarantool.org> (raw) In-Reply-To: <cover.1551902962.git.georgy@tarantool.org> 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
next prev parent reply other threads:[~2019-03-06 20:16 UTC|newest] Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-03-06 20:16 [tarantool-patches] [PATCH v2 0/3] Transaction boundaries for applier Georgy Kirichenko 2019-03-06 20:16 ` [tarantool-patches] [PATCH v2 1/3] Applier gets rid of a xstream Georgy Kirichenko 2019-03-07 9:31 ` Vladimir Davydov 2019-03-06 20:16 ` Georgy Kirichenko [this message] 2019-03-07 9:46 ` [tarantool-patches] [PATCH v2 2/3] Put all new rows to the end of journal request Vladimir Davydov 2019-03-07 10:38 ` [tarantool-patches] " Konstantin Osipov 2019-03-07 10:53 ` Vladimir Davydov 2019-03-07 11:22 ` Konstantin Osipov 2019-03-06 20:16 ` [tarantool-patches] [PATCH v2 3/3] Transaction support for applier Georgy Kirichenko 2019-03-07 10:38 ` Vladimir Davydov 2019-03-07 10:40 ` [tarantool-patches] " Konstantin Osipov
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=2134b8fca0963ebd0a8fb818a66cd05e81ef09a6.1551902962.git.georgy@tarantool.org \ --to=georgy@tarantool.org \ --cc=tarantool-patches@freelists.org \ --subject='Re: [tarantool-patches] [PATCH v2 2/3] Put all new rows to the end of journal request' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox