Hi all
A new txn package has been introduced under state.
This package provides a txn.Runner interface, the implementation of which
provides functionality previously inside the State struct. All of the
transaction hooks for use in tests also have been moved across.
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.
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
}
The standalone txn.Runner will also be used moving forward in the Juju internal
storage implementation, where we want to have access to a database without
bringing in all of the State baggage. It will also allow the introduction of
consistent behaviour like exponential backoff in the case of transaction
consistency errors etc.
--
Juju-dev mailing list
[email protected]
Modify settings or unsubscribe at:
https://lists.ubuntu.com/mailman/listinfo/juju-dev