multi: add reset closure to kvdb.View

This commit adds a reset() closure to the kvdb.View function which will
be called before each retry (including the first) of the view
transaction. The reset() closure can be used to reset external state
(eg slices or maps) where the view closure puts intermediate results.
This commit is contained in:
Andras Banki-Horvath committed 2020-11-05 17:57:12 +01:00
1 parent ffb27284df
commit 2a358327f4
47 files changed
+340 -82

No files matched your search

+2
View File
@@ -203,6 +203,8 @@ func (d *DB) FetchClosedChannels(pendingOnly bool) ([]*ChannelCloseSummary, erro
chanSummaries = append(chanSummaries, chanSummary)
return nil
})
}, func() {
chanSummaries = nil
}); err != nil {
return nil, err
}
+2
View File
@@ -190,6 +190,8 @@ func (c *ChannelGraph) SourceNode() (*LightningNode, error) {
source = node
return nil
}, func() {
source = nil
})
if err != nil {
return nil, err
+2
View File
@@ -282,6 +282,8 @@ func (d *DB) FetchAllInvoices(pendingOnly bool) ([]Invoice, error) {
return nil
})
}, func() {
invoices = nil
})
if err != nil {
return nil, err
@@ -126,6 +126,8 @@ func (db *DB) fetchAllPayments() ([]*outgoingPayment, error) {
payments = append(payments, payment)
return nil
})
}, func() {
payments = nil
})
if err != nil {
return nil, err
@@ -144,6 +146,8 @@ func (db *DB) fetchPaymentStatus(paymentHash [32]byte) (PaymentStatus, error) {
var err error
paymentStatus, err = fetchPaymentStatusTx(tx, paymentHash)
return err
}, func() {
paymentStatus = StatusUnknown
})
if err != nil {
return StatusUnknown, err
@@ -424,6 +428,8 @@ func (db *DB) fetchPaymentsMigration9() ([]*Payment, error) {
return nil
})
})
}, func() {
payments = nil
})
if err != nil {
return nil, err
@@ -418,6 +418,8 @@ func TestMigrateOptionalChannelCloseSummaryFields(t *testing.T) {
"serialization")
}
return nil
}, func() {
dbSummary = nil
})
if err != nil {
t.Fatalf("unable to view DB: %v", err)
@@ -521,6 +523,8 @@ func TestMigrateGossipMessageStoreKeys(t *testing.T) {
}
return nil
}, func() {
rawMsg = nil
})
if err != nil {
t.Fatal(err)
+2
View File
@@ -303,6 +303,8 @@ func (db *DB) FetchPayments() ([]*Payment, error) {
return nil
})
})
}, func() {
payments = nil
})
if err != nil {
return nil, err