logical/framework: rollback should return error, easier API

This commit is contained in:
Mitchell Hashimoto
2015-03-21 11:08:13 +01:00
parent c9e64725d7
commit c872e0f788
2 changed files with 16 additions and 11 deletions

View File

@@ -34,8 +34,7 @@ type Backend struct {
Secrets []*Secret
// Rollback is called when a WAL entry (see wal.go) has to be rolled
// back. It is called with the data from the entry. Boolean true should
// be returned on success. Errors should just be logged.
// back. It is called with the data from the entry.
//
// RollbackMinAge is the minimum age of a WAL entry before it is attempted
// to be rolled back. This should be longer than the maximum time it takes
@@ -51,7 +50,7 @@ type Backend struct {
type OperationFunc func(*logical.Request, *FieldData) (*logical.Response, error)
// RollbackFunc is the callback for rollbacks.
type RollbackFunc func(*logical.Request, string, interface{}) bool
type RollbackFunc func(*logical.Request, string, interface{}) error
// logical.Backend impl.
func (b *Backend) HandleRequest(req *logical.Request) (*logical.Response, error) {
@@ -242,10 +241,16 @@ func (b *Backend) handleRollback(
}
// Attempt a rollback
if b.Rollback(req, entry.Kind, entry.Data) {
if err := DeleteWAL(req.Storage, k); err != nil {
merr = multierror.Append(merr, err)
}
err = b.Rollback(req, entry.Kind, entry.Data)
if err != nil {
err = fmt.Errorf(
"Error rolling back '%s' entry: %s", entry.Kind, err)
}
if err == nil {
err = DeleteWAL(req.Storage, k)
}
if err != nil {
merr = multierror.Append(merr, err)
}
}