[tarantool-patches] Re: [PATCH 2/2] Get rid of aurocommit from a txn structure

Konstantin Osipov kostja at tarantool.org
Thu Apr 11 09:43:51 MSK 2019


* Georgy Kirichenko <georgy at tarantool.org> [19/04/10 10:26]:
> Move transaction auto start and auto commit behavior to box level.
> Now transaction won't start and commit automatically without
> txn_begin/txn_commit invocations. This is a part of a bigger transaction
> refactoring in order to implement detachable transactions and a parallel
> applier.

This change is looking good, the only nit is about so much labor
one has to do to run an autocommit transaction. If it was C++, I
would suggest adding a lambda which would auto-commit on
destruction, But given it's plain C, how about simply making the
code a bit more straightforward in its flow ?

> +	if (txn_commit_stmt(txn, request) != 0 ||
> +	    (autocommit && txn_commit(txn) != 0))
> +		goto fail;
> +	if (autocommit)
> +		fiber_gc();
> +

This piece in particular, I would rewrite:

 if (txn_commit_stmt())
       goto fail()
if (autocommit) {
    if (txn_commit()
        goto fail;
    fiber_gc();
}
> +	rc = 0;
> +done:
> +	if (tuple != NULL)
> +		tuple_unref(tuple);
>  	return rc;
> +
> +fail:
> +	if (autocommit)
> +		txn_rollback();
> +	goto done;

I think using double labels like here is on the verge of goto
abuse.

> -		if (box_process_rw(&request, space, NULL) != 0) {
> +		struct txn *txn = txn_begin();
> +		if (txn == NULL || box_process_rw(&request, space, NULL) != 0 ||
> +		    txn_commit(txn) != 0) {
>  			say_error("error applying row: %s", request_str(&request));
> +			if (txn != NULL)
> +				txn_rollback();
>  			diag_raise();

Here is another example.

-- 
Konstantin Osipov, Moscow, Russia, +7 903 626 22 32
http://tarantool.io - www.twitter.com/kostja_osipov




More information about the Tarantool-patches mailing list