overlay: call rollback on commit error

Rollback was not being called when the function was called with
a key which does not exist. This failure to call rollback kept
the database open and caused all new requests to block.

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
This commit is contained in:
Derek McGowan 2017-05-11 15:55:47 -07:00
parent fa4e114979
commit 7027e8862a
No known key found for this signature in database
GPG Key ID: F58C5D0A4405ACDB

View File

@ -152,6 +152,14 @@ func (o *snapshotter) Commit(ctx context.Context, name, key string) error {
return err
}
defer func() {
if err != nil {
if rerr := t.Rollback(); rerr != nil {
log.G(ctx).WithError(rerr).Warn("Failure rolling back transaction")
}
}
}()
// grab the existing id
id, _, _, err := storage.GetInfo(ctx, key)
if err != nil {
@ -163,10 +171,7 @@ func (o *snapshotter) Commit(ctx context.Context, name, key string) error {
return err
}
if _, err := storage.CommitActive(ctx, key, name, snapshot.Usage(usage)); err != nil {
if rerr := t.Rollback(); rerr != nil {
log.G(ctx).WithError(rerr).Warn("Failure rolling back transaction")
}
if _, err = storage.CommitActive(ctx, key, name, snapshot.Usage(usage)); err != nil {
return errors.Wrap(err, "failed to commit snapshot")
}
return t.Commit()