Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
To: Cyrill Gorcunov <gorcunov@gmail.com>,
	tml <tarantool-patches@dev.tarantool.org>
Subject: Re: [Tarantool-patches] [PATCH v3 5/6] qsync: implement direct write of CONFIRM/ROLLBACK into a journal
Date: Mon, 27 Jul 2020 22:41:17 +0200	[thread overview]
Message-ID: <67376e86-126e-f6c7-1684-c69980e4860b@tarantool.org> (raw)
In-Reply-To: <20200727140650.447750-6-gorcunov@gmail.com>

Thanks for the patch!

> diff --git a/src/box/txn_limbo.c b/src/box/txn_limbo.c
> index a74bfe244..d8cf6a6f6 100644
> --- a/src/box/txn_limbo.c
> +++ b/src/box/txn_limbo.c
> @@ -237,62 +240,73 @@ txn_limbo_wait_complete(struct txn_limbo *limbo, struct txn_limbo_entry *entry)
>  	return 0;
>  }
>  
> +/**
> + * A callback for synchronous write: txn_limbo_write fiber
> + * waiting to proceed once a record is written to WAL.
> + */
> +static void
> +txn_limbo_write_cb(struct journal_entry *entry)
> +{
> +	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 journal entry.
> + */
>  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);
>  
> +	/*
> +	 * When allocated statically some compilers (such as
> +	 * clang + asan) requires the journal_entry::rows to
> +	 * be last in a container structure. So it it simplier
> +	 * just to create a cummulative buffer.
> +	 */
> +	char buf[sizeof(struct journal_entry) +
> +		 sizeof(struct xrow_header *)];
> +
> +	struct synchro_body_bin body_bin;
>  	struct xrow_header row;
> -	struct request request = {
> -		.header = &row,
> -	};
>  
> -	struct txn *txn = txn_begin();
> -	if (txn == NULL)
> -		return -1;
> +	struct journal_entry *entry = (struct journal_entry *)buf;
> +	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);
> +	xrow_encode_synchro(&row, &body_bin, 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) {

I suggest simply add '|| entry->res < 0' to the check above. To
make a single error handling point.

> +		diag_set(ClientError, ER_WAL_IO);
> +		diag_log();
> +		return -1;
> +	}
>  

  reply	other threads:[~2020-07-27 20:41 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-27 14:06 [Tarantool-patches] [PATCH v3 0/6] qsync: write CONFIRM/ROLLBACK without txn engine Cyrill Gorcunov
2020-07-27 14:06 ` [Tarantool-patches] [PATCH v3 1/6] journal: drop redundant declaration Cyrill Gorcunov
2020-07-27 14:06 ` [Tarantool-patches] [PATCH v3 2/6] journal: bind asynchronous write completion to an entry Cyrill Gorcunov
2020-07-27 20:40   ` Vladislav Shpilevoy
2020-07-27 21:37     ` Cyrill Gorcunov
2020-07-27 14:06 ` [Tarantool-patches] [PATCH v3 3/6] journal: add journal_entry_create helper Cyrill Gorcunov
2020-07-27 14:06 ` [Tarantool-patches] [PATCH v3 4/6] qsync: provide a binary form of syncro entries Cyrill Gorcunov
2020-07-27 14:06 ` [Tarantool-patches] [PATCH v3 5/6] qsync: implement direct write of CONFIRM/ROLLBACK into a journal Cyrill Gorcunov
2020-07-27 20:41   ` Vladislav Shpilevoy [this message]
2020-07-27 21:39     ` Cyrill Gorcunov
2020-07-27 14:06 ` [Tarantool-patches] [PATCH v3 6/6] qsync: drop no longer used encoding helpers Cyrill Gorcunov
2020-07-27 14:12 ` [Tarantool-patches] [PATCH v3 0/6] qsync: write CONFIRM/ROLLBACK without txn engine 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=67376e86-126e-f6c7-1684-c69980e4860b@tarantool.org \
    --to=v.shpilevoy@tarantool.org \
    --cc=gorcunov@gmail.com \
    --cc=tarantool-patches@dev.tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH v3 5/6] 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