mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-27 14:11:04 +02:00
invoices: reduce log spam when migrating invoices to SQL
This commit is contained in:
@@ -17,6 +17,7 @@ import (
|
|||||||
"github.com/lightningnetwork/lnd/sqldb"
|
"github.com/lightningnetwork/lnd/sqldb"
|
||||||
"github.com/lightningnetwork/lnd/sqldb/sqlc"
|
"github.com/lightningnetwork/lnd/sqldb/sqlc"
|
||||||
"github.com/pmezard/go-difflib/difflib"
|
"github.com/pmezard/go-difflib/difflib"
|
||||||
|
"golang.org/x/time/rate"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -433,11 +434,17 @@ func MigrateInvoicesToSQL(ctx context.Context, db kvdb.Backend,
|
|||||||
}
|
}
|
||||||
log.Debugf("Created SQL invoice hash index in %v", time.Since(t0))
|
log.Debugf("Created SQL invoice hash index in %v", time.Since(t0))
|
||||||
|
|
||||||
|
s := rate.Sometimes{
|
||||||
|
Interval: 30 * time.Second,
|
||||||
|
}
|
||||||
|
|
||||||
|
t0 = time.Now()
|
||||||
|
chunk := 0
|
||||||
total := 0
|
total := 0
|
||||||
|
|
||||||
// Now we can start migrating the invoices. We'll do this in
|
// Now we can start migrating the invoices. We'll do this in
|
||||||
// batches to reduce memory usage.
|
// batches to reduce memory usage.
|
||||||
for {
|
for {
|
||||||
t0 = time.Now()
|
|
||||||
query := InvoiceQuery{
|
query := InvoiceQuery{
|
||||||
IndexOffset: offset,
|
IndexOffset: offset,
|
||||||
NumMaxInvoices: uint64(batchSize),
|
NumMaxInvoices: uint64(batchSize),
|
||||||
@@ -445,13 +452,11 @@ func MigrateInvoicesToSQL(ctx context.Context, db kvdb.Backend,
|
|||||||
|
|
||||||
queryResult, err := kvStore.QueryInvoices(ctx, query)
|
queryResult, err := kvStore.QueryInvoices(ctx, query)
|
||||||
if err != nil && !errors.Is(err, ErrNoInvoicesCreated) {
|
if err != nil && !errors.Is(err, ErrNoInvoicesCreated) {
|
||||||
return fmt.Errorf("unable to query invoices: "+
|
return fmt.Errorf("unable to query invoices: %w", err)
|
||||||
"%w", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(queryResult.Invoices) == 0 {
|
if len(queryResult.Invoices) == 0 {
|
||||||
log.Infof("All invoices migrated")
|
log.Infof("All invoices migrated. Total: %d", total)
|
||||||
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -461,9 +466,19 @@ func MigrateInvoicesToSQL(ctx context.Context, db kvdb.Backend,
|
|||||||
}
|
}
|
||||||
|
|
||||||
offset = queryResult.LastIndexOffset
|
offset = queryResult.LastIndexOffset
|
||||||
total += len(queryResult.Invoices)
|
resultCnt := len(queryResult.Invoices)
|
||||||
log.Debugf("Migrated %d KV invoices to SQL in %v\n", total,
|
total += resultCnt
|
||||||
time.Since(t0))
|
chunk += resultCnt
|
||||||
|
|
||||||
|
s.Do(func() {
|
||||||
|
elapsed := time.Since(t0).Seconds()
|
||||||
|
ratePerSec := float64(chunk) / elapsed
|
||||||
|
log.Debugf("Migrated %d invoices (%.2f invoices/sec)",
|
||||||
|
total, ratePerSec)
|
||||||
|
|
||||||
|
t0 = time.Now()
|
||||||
|
chunk = 0
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clean up the hash index as it's no longer needed.
|
// Clean up the hash index as it's no longer needed.
|
||||||
|
Reference in New Issue
Block a user