Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladimir Davydov <vdavydov.dev@gmail.com>
To: Georgy Kirichenko <georgy@tarantool.org>
Cc: tarantool-patches@freelists.org
Subject: Re: [tarantool-patches] [PATCH v3 4/5] Transaction support for applier
Date: Wed, 27 Mar 2019 14:48:32 +0300	[thread overview]
Message-ID: <20190327114832.z6znrtcup4pdlxja@esperanza> (raw)
In-Reply-To: <2d06385bd5d62551ce1132d3d5c937d417ea9e66.1553255718.git.georgy@tarantool.org>

On Fri, Mar 22, 2019 at 03:06:09PM +0300, Georgy Kirichenko wrote:
> +/**
> + * Apply all rows in the rows queue as a single transaction.
> + *
> + * Return 0 for success or -1 in case of an error.
> + */
> +static int
> +applier_apply_tx(struct stailq *rows)
> +{
> +	int res = 0;
> +	struct txn *txn = txn_begin(false);
> +	struct applier_tx_row *item;
> +	if (txn == NULL)
> +		diag_raise();

Just one thing - mixing retval and exceptions to propagate errors
doesn't look good. Besides you won't release the latch in case of
an exception (see below). Please replace with 'return -1'.

> +	stailq_foreach_entry(item, rows, next) {
> +		struct xrow_header *row = &item->row;
> +		res = apply_row(row);
> +		if (res != 0) {
> +			struct error *e = diag_last_error(diag_get());
> +			/*
> +			 * In case of ER_TUPLE_FOUND error and enabled
> +			 * replication_skip_conflict configuration
> +			 * option, skip applying the foreign row and
> +			 * replace it with NOP in the local write ahead
> +			 * log.
> +			 */
> +			if (e->type == &type_ClientError &&
> +			    box_error_code(e) == ER_TUPLE_FOUND &&
> +			    replication_skip_conflict) {
> +				diag_clear(diag_get());
> +				row->type = IPROTO_NOP;
> +				row->bodycnt = 0;
> +				res = apply_row(row);
> +			}
> +		}
> +		if (res != 0)
> +			break;
> +	}
> +	if (res == 0)
> +		res = txn_commit(txn);
> +	else
> +		txn_rollback();
> +	return res;
> +}

> @@ -594,33 +724,11 @@ applier_subscribe(struct applier *applier)
>  		 * that belong to the same server id.
>  		 */
>  		latch_lock(latch);
> -		if (vclock_get(&replicaset.vclock, row.replica_id) < row.lsn) {
> -			int res = apply_row(&row);
> -			if (res != 0) {
> -				struct error *e = diag_last_error(diag_get());
> -				/*
> -				 * In case of ER_TUPLE_FOUND error and enabled
> -				 * replication_skip_conflict configuration
> -				 * option, skip applying the foreign row and
> -				 * replace it with NOP in the local write ahead
> -				 * log.
> -				 */
> -				if (e->type == &type_ClientError &&
> -				    box_error_code(e) == ER_TUPLE_FOUND &&
> -				    replication_skip_conflict) {
> -					diag_clear(diag_get());
> -					struct xrow_header nop;
> -					nop.type = IPROTO_NOP;
> -					nop.bodycnt = 0;
> -					nop.replica_id = row.replica_id;
> -					nop.lsn = row.lsn;
> -					res = apply_row(&nop);
> -				}
> -			}
> -			if (res != 0) {
> -				latch_unlock(latch);
> -				diag_raise();
> -			}
> +		if (vclock_get(&replicaset.vclock, first_row->replica_id) <
> +		    first_row->lsn &&
> +		    applier_apply_tx(&rows) != 0) {
> +			latch_unlock(latch);
> +			diag_raise();
>  		}
>  		latch_unlock(latch);
>  

  parent reply	other threads:[~2019-03-27 11:48 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-22 12:06 [tarantool-patches] [PATCH v3 0/5] Transaction in replication protocol Georgy Kirichenko
2019-03-22 12:06 ` [tarantool-patches] [PATCH v3 1/5] Abort vinyl index creation in case of truncation rollback Georgy Kirichenko
2019-03-27  9:59   ` Vladimir Davydov
2019-03-22 12:06 ` [tarantool-patches] [PATCH v3 2/5] Synchronize lua schema update with space cache Georgy Kirichenko
2019-03-27 10:03   ` Vladimir Davydov
2019-03-27 10:32     ` Vladimir Davydov
2019-03-27 11:45       ` [tarantool-patches] " Konstantin Osipov
2019-03-22 12:06 ` [tarantool-patches] [PATCH v3 3/5] Require for single statement not autocommit in case of ddl Georgy Kirichenko
2019-03-27 10:49   ` Vladimir Davydov
2019-03-22 12:06 ` [tarantool-patches] [PATCH v3 4/5] Transaction support for applier Georgy Kirichenko
2019-03-27 11:41   ` Vladimir Davydov
2019-03-27 11:48   ` Vladimir Davydov [this message]
2019-03-22 12:06 ` [tarantool-patches] [PATCH v3 5/5] Raise an error if remote transaction produces non-local changes Georgy Kirichenko
2019-03-27 12:06   ` Vladimir Davydov

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=20190327114832.z6znrtcup4pdlxja@esperanza \
    --to=vdavydov.dev@gmail.com \
    --cc=georgy@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='Re: [tarantool-patches] [PATCH v3 4/5] Transaction support for applier' \
    /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