New txn package

William Reade william.reade at canonical.com
Mon Jun 16 08:41:20 UTC 2014


On Mon, Jun 16, 2014 at 6:54 AM, Ian Booth <ian.booth at canonical.com> wrote:
>
> A major feature of the new implementation is that the logic for retrying
> transaction operations after a consistency error is all nicely packaged
> and the
> calling code is much simpler. It is no longer necessary to use a for{}
> loop with
> manual ErrTxnAborted handling. This pattern should be considered obsolete
> and
> rejected when doing code reviews.
>

This is *awesome*. Manual loops should absolutely be rejected now.

The new pattern is to implement a function returning the txn ops to invoke
> and
> pass that to the Runner.Run() method. eg
>
> func doSomething(runner txn.Runner) (err error) {
>   buildTxn := func(attempt int) ([]txn.Op, error) {
>       var ops  []txn.Op
>       ops = ...
>       return ops, nil
>   }
>   if err = runner.Run(buildTxn); err != nil {
>       err = errors.Annotate(err, "failed to ....")
>   }
>   return err
> }
>

Also, code that's tested without txn.TestHook is almost certainly
inadequately tested, and should itself be rejected. If you're modifying
state and touch code that predates TestHook-based verification, please
update it, and try to craft at least one nicely pathological case alongside
the obvious ones.

Far too many of the edge cases in state have hitherto been essentially
untested. Let's try to reclaim some of that territory.

Cheers
William
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/juju-dev/attachments/20140616/37e6ed29/attachment.html>


More information about the Juju-dev mailing list