[Tarantool-patches] [PATCH v8 1/2] applier: send transaction's first row WAL time in the applier_writer_f

Vladislav Shpilevoy v.shpilevoy at tarantool.org
Mon Jun 7 22:20:58 MSK 2021


Thanks for the patch!

> diff --git a/src/box/applier.cc b/src/box/applier.cc
> index 33181fdbf..38695a54f 100644
> --- a/src/box/applier.cc
> +++ b/src/box/applier.cc> @@ -751,11 +764,35 @@ applier_txn_rollback_cb(struct trigger *trigger, void *event)
>  	return 0;
>  }
>  
> +struct replica_cb_data {
> +	/** Replica ID the data belongs to. */
> +	uint32_t replica_id;
> +	/**
> +	 * Timestamp of a transaction to be accounted
> +	 * for relay lag. Usually it is a first row in
> +	 * a transaction.
> +	 */
> +	double txn_start_tm;
> +};
> +
> +/** Update replica associated data once write is complete. */
> +static void
> +replica_txn_wal_write_cb(struct replica_cb_data *rcb)
> +{
> +	struct replica *r = replica_by_id(rcb->replica_id);
> +	if (likely(r != NULL))
> +		r->applier_txn_start_tm = rcb->txn_start_tm;

I spent some time trying to understand why did you delete the
check that we should not override the timestamp until its ACK is
sent.

But then I realized that indeed the correct way is to send the
latest timestamp of a tx batch, not the first one. Because the
replica confirms receipt of the transactions up to the latest one.
I am 90% sure it is correct. And you need to add a comment here
why do you use the latest timestamp.

Also that means you need to use the last row's timestamp, not the
first row's one. By the same reason. I doubt they are different,
but still it would be more correct. In apply_plain_tx() below you
should use last stailq entry, not first entry.

> @@ -931,10 +978,21 @@ apply_plain_tx(struct stailq *rows, bool skip_conflict, bool use_triggers)
>  			goto fail;
>  		}
>  
> +		struct replica_cb_data *rcb;
> +		rcb = region_alloc_object(&txn->region, typeof(*rcb), &size);
> +		if (rcb == NULL) {
> +			diag_set(OutOfMemory, size, "region_alloc_object", "rcb");
> +			goto fail;
> +		}
> +
>  		trigger_create(on_rollback, applier_txn_rollback_cb, NULL, NULL);
>  		txn_on_rollback(txn, on_rollback);
>  
> -		trigger_create(on_wal_write, applier_txn_wal_write_cb, NULL, NULL);
> +		item = stailq_first_entry(rows, struct applier_tx_row, next);
> +		rcb->replica_id = replica_id;
> +		rcb->txn_start_tm = item->row.tm;
> +
> +		trigger_create(on_wal_write, applier_txn_wal_write_cb, rcb, NULL);
>  		txn_on_wal_write(txn, on_wal_write);
>  	}


More information about the Tarantool-patches mailing list