@@ -26,10 +26,11 @@ var pragmas = []string{
26
26
"PRAGMA temp_store = memory" ,
27
27
"PRAGMA mmap_size = 30000000000" ,
28
28
"PRAGMA page_size = 32768" ,
29
- "PRAGMA auto_vacuum = NONE" , // not useful until we implement GC
29
+ "PRAGMA auto_vacuum = NONE" ,
30
30
"PRAGMA automatic_index = OFF" ,
31
31
"PRAGMA journal_mode = WAL" ,
32
- "PRAGMA read_uncommitted = ON" ,
32
+ "PRAGMA wal_autocheckpoint = 256" , // checkpoint @ 256 pages
33
+ "PRAGMA journal_size_limit = 0" , // always reset journal and wal files
33
34
}
34
35
35
36
// Any changes to this schema should be matched for the `lotus-shed indexes backfill-events` command
@@ -438,6 +439,9 @@ func NewEventIndex(ctx context.Context, path string, chainStore *store.ChainStor
438
439
eventIndex := EventIndex {db : db }
439
440
440
441
q , err := db .QueryContext (ctx , "SELECT name FROM sqlite_master WHERE type='table' AND name='_meta';" )
442
+ if q != nil {
443
+ defer func () { _ = q .Close () }()
444
+ }
441
445
if errors .Is (err , sql .ErrNoRows ) || ! q .Next () {
442
446
// empty database, create the schema
443
447
for _ , ddl := range ddls {
@@ -521,7 +525,7 @@ func (ei *EventIndex) Close() error {
521
525
}
522
526
523
527
func (ei * EventIndex ) CollectEvents (ctx context.Context , te * TipSetEvents , revert bool , resolver func (ctx context.Context , emitter abi.ActorID , ts * types.TipSet ) (address.Address , bool )) error {
524
- tx , err := ei .db .Begin ( )
528
+ tx , err := ei .db .BeginTx ( ctx , nil )
525
529
if err != nil {
526
530
return xerrors .Errorf ("begin transaction: %w" , err )
527
531
}
@@ -743,6 +747,7 @@ func (ei *EventIndex) prefillFilter(ctx context.Context, f *eventFilter, exclude
743
747
if err != nil {
744
748
return xerrors .Errorf ("prepare prefill query: %w" , err )
745
749
}
750
+ defer func () { _ = stmt .Close () }()
746
751
747
752
q , err := stmt .QueryContext (ctx , values ... )
748
753
if err != nil {
@@ -751,6 +756,7 @@ func (ei *EventIndex) prefillFilter(ctx context.Context, f *eventFilter, exclude
751
756
}
752
757
return xerrors .Errorf ("exec prefill query: %w" , err )
753
758
}
759
+ defer func () { _ = q .Close () }()
754
760
755
761
var ces []* CollectedEvent
756
762
var currentID int64 = - 1
@@ -839,7 +845,6 @@ func (ei *EventIndex) prefillFilter(ctx context.Context, f *eventFilter, exclude
839
845
Codec : row .codec ,
840
846
Value : row .value ,
841
847
})
842
-
843
848
}
844
849
845
850
if ce != nil {
0 commit comments