From: Cyrill Gorcunov <gorcunov@gmail.com> To: tml <tarantool-patches@dev.tarantool.org> Cc: Vladislav Shpilevoy <v.shpilevoy@tarantool.org> Subject: [Tarantool-patches] [PATCH v2 6/7] qsync: implement direct write of CONFIRM/ROLLBACK into a journal Date: Thu, 23 Jul 2020 15:29:41 +0300 [thread overview] Message-ID: <20200723122942.196011-7-gorcunov@gmail.com> (raw) In-Reply-To: <20200723122942.196011-1-gorcunov@gmail.com> When we need to write CONFIRM or ROLLBACK message (which is just a binary record in msgpack format) into a journal we use txn code to allocate a new transaction, encode there a message and pass it to walk the long txn path before it hit the journal. This is not only resource wasting but also somehow strange from arhitectural point of view. Instead lets encode a record on the stack and write it directly to the journal. Closes #5129 Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com> --- src/box/txn_limbo.c | 92 +++++++++++++++++++++++++-------------------- 1 file changed, 51 insertions(+), 41 deletions(-) diff --git a/src/box/txn_limbo.c b/src/box/txn_limbo.c index a74bfe244..3eca244dc 100644 --- a/src/box/txn_limbo.c +++ b/src/box/txn_limbo.c @@ -32,6 +32,9 @@ #include "txn_limbo.h" #include "replication.h" +#include "iproto_constants.h" +#include "journal.h" + struct txn_limbo txn_limbo; static inline void @@ -237,62 +240,69 @@ txn_limbo_wait_complete(struct txn_limbo *limbo, struct txn_limbo_entry *entry) return 0; } +static void +txn_limbo_write_cb(struct journal_entry *entry) +{ + /* + * It is safe to call fiber_wakeup on + * active fiber but we need to call wakeup + * in case if we're sitting in WAL thread. + */ + assert(entry->complete_data != NULL); + fiber_wakeup(entry->complete_data); +} + +/** + * Write CONFIRM or ROLLBACK message to a journal directly + * without involving transaction engine because using txn + * engine is far from being cheap while we only need to + * write a small message. + */ static int -txn_limbo_write_confirm_rollback(struct txn_limbo *limbo, int64_t lsn, - bool is_confirm) +txn_limbo_write(uint32_t replica_id, int64_t lsn, int type) { + assert(replica_id != REPLICA_ID_NIL); + assert(type == IPROTO_CONFIRM || type == IPROTO_ROLLBACK); assert(lsn > 0); - struct xrow_header row; - struct request request = { - .header = &row, - }; + char buf[sizeof(struct journal_entry) + + sizeof(struct xrow_header *) + + sizeof(struct xrow_header)]; - struct txn *txn = txn_begin(); - if (txn == NULL) - return -1; + struct journal_entry *entry = (void *)buf; + struct xrow_header *row = (void *)&entry->rows[1]; + entry->rows[0] = row; - int res = 0; - if (is_confirm) { - res = xrow_encode_confirm(&row, &txn->region, - limbo->instance_id, lsn); - } else { - /* - * This LSN is the first to be rolled back, so - * the last "safe" lsn is lsn - 1. - */ - res = xrow_encode_rollback(&row, &txn->region, - limbo->instance_id, lsn); + struct request_synchro_body body; + xrow_encode_confirm_rollback(row, &body, replica_id, + lsn, type); + + journal_entry_create(entry, 1, xrow_approx_len(row), + txn_limbo_write_cb, fiber()); + + if (journal_write(entry) != 0) { + diag_set(ClientError, ER_WAL_IO); + diag_log(); + return -1; } - if (res == -1) - goto rollback; - /* - * This is not really a transaction. It just uses txn API - * to put the data into WAL. And obviously it should not - * go to the limbo and block on the very same sync - * transaction which it tries to confirm now. - */ - txn_set_flag(txn, TXN_FORCE_ASYNC); - if (txn_begin_stmt(txn, NULL) != 0) - goto rollback; - if (txn_commit_stmt(txn, &request) != 0) - goto rollback; + if (entry->res < 0) { + diag_set(ClientError, ER_WAL_IO); + diag_log(); + return -1; + } - return txn_commit(txn); -rollback: - txn_rollback(txn); - return -1; + return 0; } /** * Write a confirmation entry to WAL. After it's written all the * transactions waiting for confirmation may be finished. */ -static int +static inline int txn_limbo_write_confirm(struct txn_limbo *limbo, int64_t lsn) { - return txn_limbo_write_confirm_rollback(limbo, lsn, true); + return txn_limbo_write(limbo->instance_id, lsn, IPROTO_CONFIRM); } void @@ -338,10 +348,10 @@ txn_limbo_read_confirm(struct txn_limbo *limbo, int64_t lsn) * transactions following the current one and waiting for * confirmation must be rolled back. */ -static int +static inline int txn_limbo_write_rollback(struct txn_limbo *limbo, int64_t lsn) { - return txn_limbo_write_confirm_rollback(limbo, lsn, false); + return txn_limbo_write(limbo->instance_id, lsn, IPROTO_ROLLBACK); } void -- 2.26.2
next prev parent reply other threads:[~2020-07-23 12:31 UTC|newest] Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-07-23 12:29 [Tarantool-patches] [PATCH v2 0/5] qsync: write CONFIRM/ROLLBACK without txn engine Cyrill Gorcunov 2020-07-23 12:29 ` [Tarantool-patches] [PATCH v2 1/7] journal: drop redundant declaration Cyrill Gorcunov 2020-07-23 12:29 ` [Tarantool-patches] [PATCH v2 2/7] wal: bind asynchronous write completion to an entry Cyrill Gorcunov 2020-07-23 22:10 ` Vladislav Shpilevoy 2020-07-24 17:48 ` Cyrill Gorcunov 2020-07-23 12:29 ` [Tarantool-patches] [PATCH v2 3/7] journal: add journal_entry_create helper Cyrill Gorcunov 2020-07-23 22:10 ` Vladislav Shpilevoy 2020-07-24 17:50 ` Cyrill Gorcunov 2020-07-23 12:29 ` [Tarantool-patches] [PATCH v2 4/7] qsync: provide a binary form of CONFIRM/ROLLBACK entries Cyrill Gorcunov 2020-07-23 22:10 ` Vladislav Shpilevoy 2020-07-24 18:07 ` Cyrill Gorcunov 2020-07-23 12:29 ` [Tarantool-patches] [PATCH v2 5/7] qsync: provide a way to encode preallocated " Cyrill Gorcunov 2020-07-23 22:10 ` Vladislav Shpilevoy 2020-07-24 18:08 ` Cyrill Gorcunov 2020-07-23 12:29 ` Cyrill Gorcunov [this message] 2020-07-23 22:10 ` [Tarantool-patches] [PATCH v2 6/7] qsync: implement direct write of CONFIRM/ROLLBACK into a journal Vladislav Shpilevoy 2020-07-24 18:16 ` Cyrill Gorcunov 2020-07-23 12:29 ` [Tarantool-patches] [PATCH v2 7/7] qsync: drop no longer used xrow_encode_confirm, rollback Cyrill Gorcunov 2020-07-23 22:13 ` [Tarantool-patches] [PATCH v2 0/5] qsync: write CONFIRM/ROLLBACK without txn engine Vladislav Shpilevoy 2020-07-24 18:16 ` Cyrill Gorcunov
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=20200723122942.196011-7-gorcunov@gmail.com \ --to=gorcunov@gmail.com \ --cc=tarantool-patches@dev.tarantool.org \ --cc=v.shpilevoy@tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH v2 6/7] qsync: implement direct write of CONFIRM/ROLLBACK into a journal' \ /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