Skip to content

Commit 9e93242

Browse files
authored
fix(database): stop vacuum timer on DB close (#1018)
Signed-off-by: Chris Gianelloni <[email protected]>
1 parent 2b5501e commit 9e93242

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

database/certs.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,12 @@ func (d *Database) SetPoolRegistration(
4242
deposit uint64,
4343
txn *Txn,
4444
) error {
45-
return d.metadata.SetPoolRegistration(cert, slot, types.Uint64(deposit), txn.Metadata())
45+
return d.metadata.SetPoolRegistration(
46+
cert,
47+
slot,
48+
types.Uint64(deposit),
49+
txn.Metadata(),
50+
)
4651
}
4752

4853
// SetPoolRetirement saves a pool retirement certificate

database/plugin/metadata/sqlite/database.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"log/slog"
2323
"os"
2424
"path/filepath"
25+
"sync"
2526
"time"
2627

2728
"github.com/blinklabs-io/dingo/database/models"
@@ -38,6 +39,7 @@ type MetadataStoreSqlite struct {
3839
db *gorm.DB
3940
logger *slog.Logger
4041
timerVacuum *time.Timer
42+
timerMutex sync.Mutex
4143
dataDir string
4244
}
4345

@@ -141,7 +143,11 @@ func (d *MetadataStoreSqlite) runVacuum() error {
141143
return nil
142144
}
143145

146+
// scheduleDailyVacuum schedules a daily vacuum operation
144147
func (d *MetadataStoreSqlite) scheduleDailyVacuum() {
148+
d.timerMutex.Lock()
149+
defer d.timerMutex.Unlock()
150+
145151
if d.timerVacuum != nil {
146152
d.timerVacuum.Stop()
147153
}
@@ -169,6 +175,13 @@ func (d *MetadataStoreSqlite) AutoMigrate(dst ...any) error {
169175

170176
// Close gets the database handle from our MetadataStore and closes it
171177
func (d *MetadataStoreSqlite) Close() error {
178+
d.timerMutex.Lock()
179+
if d.timerVacuum != nil {
180+
d.timerVacuum.Stop()
181+
d.timerVacuum = nil
182+
}
183+
d.timerMutex.Unlock()
184+
172185
// get DB handle from gorm.DB
173186
db, err := d.DB().DB()
174187
if err != nil {

0 commit comments

Comments
 (0)