multi: add reset closure to kvdb.Update

Similarly as with kvdb.View this commits adds a reset closure to the
kvdb.Update call in order to be able to reset external state if the
underlying db backend needs to retry the transaction.
This commit is contained in:
Andras Banki-Horvath committed 2020-11-05 17:57:12 +01:00
1 parent 2a358327f4
commit d89f51d1d0
44 files changed
+208 -162

No files matched your search

+8 -6
View File
@@ -41,10 +41,7 @@ type missionControlStore struct {
}
func newMissionControlStore(db kvdb.Backend, maxRecords int) (*missionControlStore, error) {
store := &missionControlStore{
db: db,
maxRecords: maxRecords,
}
var store *missionControlStore
// Create buckets if not yet existing.
err := kvdb.Update(db, func(tx kvdb.RwTx) error {
@@ -64,6 +61,11 @@ func newMissionControlStore(db kvdb.Backend, maxRecords int) (*missionControlSto
}
return nil
}, func() {
store = &missionControlStore{
db: db,
maxRecords: maxRecords,
}
})
if err != nil {
return nil, err
@@ -81,7 +83,7 @@ func (b *missionControlStore) clear() error {
_, err := tx.CreateTopLevelBucket(resultsKey)
return err
})
}, func() {})
}
// fetchAll returns all results currently stored in the database.
@@ -251,7 +253,7 @@ func (b *missionControlStore) AddResult(rp *paymentResult) error {
// Put into results bucket.
return bucket.Put(k, v)
})
}, func() {})
}
// getResultKey returns a byte slice representing a unique key for this payment