@@ -17,6 +17,7 @@ import (
17
17
"github.com/lightningnetwork/lnd/sqldb"
18
18
"github.com/lightningnetwork/lnd/sqldb/sqlc"
19
19
"github.com/pmezard/go-difflib/difflib"
20
+ "golang.org/x/time/rate"
20
21
)
21
22
22
23
var (
@@ -433,25 +434,29 @@ func MigrateInvoicesToSQL(ctx context.Context, db kvdb.Backend,
433
434
}
434
435
log .Debugf ("Created SQL invoice hash index in %v" , time .Since (t0 ))
435
436
437
+ s := rate.Sometimes {
438
+ Interval : 30 * time .Second ,
439
+ }
440
+
441
+ t0 = time .Now ()
442
+ chunk := 0
436
443
total := 0
444
+
437
445
// Now we can start migrating the invoices. We'll do this in
438
446
// batches to reduce memory usage.
439
447
for {
440
- t0 = time .Now ()
441
448
query := InvoiceQuery {
442
449
IndexOffset : offset ,
443
450
NumMaxInvoices : uint64 (batchSize ),
444
451
}
445
452
446
453
queryResult , err := kvStore .QueryInvoices (ctx , query )
447
454
if err != nil && ! errors .Is (err , ErrNoInvoicesCreated ) {
448
- return fmt .Errorf ("unable to query invoices: " +
449
- "%w" , err )
455
+ return fmt .Errorf ("unable to query invoices: %w" , err )
450
456
}
451
457
452
458
if len (queryResult .Invoices ) == 0 {
453
- log .Infof ("All invoices migrated" )
454
-
459
+ log .Infof ("All invoices migrated. Total: %d" , total )
455
460
break
456
461
}
457
462
@@ -461,9 +466,19 @@ func MigrateInvoicesToSQL(ctx context.Context, db kvdb.Backend,
461
466
}
462
467
463
468
offset = queryResult .LastIndexOffset
464
- total += len (queryResult .Invoices )
465
- log .Debugf ("Migrated %d KV invoices to SQL in %v\n " , total ,
466
- time .Since (t0 ))
469
+ resultCnt := len (queryResult .Invoices )
470
+ total += resultCnt
471
+ chunk += resultCnt
472
+
473
+ s .Do (func () {
474
+ elapsed := time .Since (t0 ).Seconds ()
475
+ ratePerSec := float64 (chunk ) / elapsed
476
+ log .Debugf ("Migrated %d invoices (%.2f invoices/sec)" ,
477
+ total , ratePerSec )
478
+
479
+ t0 = time .Now ()
480
+ chunk = 0
481
+ })
467
482
}
468
483
469
484
// Clean up the hash index as it's no longer needed.
0 commit comments