containerd/snapshots/storage
Danny Canter 3b71cfd407 metastore: Add WithTransaction convenience method
Most snapshotters end up manually handling the rollback logic, either
by calling `t.Rollback()` in every failure path, setting up a custom
defer func to log on certain errors, or just deferring `t.Rollback()`
even for `snapshotter.Commit()` which *will* cause `t.Rollback()` to return
an error afaict, but it's just never checked and luckily bolt handles this
alright...

The devmapper snapshotter has a solution to this which is to have a
method that starts either a read-only or writable transaction inside
the method, and you pass in a callback to do your bidding and any
failures are rolled back, and if it's writable will handle the commit
for you. This seems like the right model to me, it removes the burden
from the snapshot author to remember to either defer/call rollback
in every method for every failure case.

This change exposes the convenience method from devmapper to the
snapshots/storage package as a method off of `storage.MetaStore` and moves
over the devmapper snapshotter to use this.

Signed-off-by: Danny Canter <danny@dcantah.dev>
2022-12-07 23:49:09 -08:00
..
bolt_test.go Move testutils to pkg 2018-05-22 17:08:38 -04:00
bolt.go feat: replace github.com/pkg/errors to errors 2022-01-07 10:27:03 +08:00
metastore_bench_test.go test: use T.TempDir to create temporary test directory 2022-03-15 14:03:50 +08:00
metastore_test.go Use testify 2022-04-01 18:17:58 -07:00
metastore.go metastore: Add WithTransaction convenience method 2022-12-07 23:49:09 -08:00