Skip to content

Commit 0cef70e

Browse files
authored
fix(database): track a closed sqlite and prevent vacuum (#1019)
Signed-off-by: Chris Gianelloni <[email protected]>
1 parent 9e93242 commit 0cef70e

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

database/plugin/metadata/sqlite/database.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ type MetadataStoreSqlite struct {
4141
timerVacuum *time.Timer
4242
timerMutex sync.Mutex
4343
dataDir string
44+
closed bool
4445
}
4546

4647
// New creates a new database
@@ -134,7 +135,10 @@ func (d *MetadataStoreSqlite) init() error {
134135
}
135136

136137
func (d *MetadataStoreSqlite) runVacuum() error {
137-
if d.dataDir == "" {
138+
d.timerMutex.Lock()
139+
closed := d.closed
140+
d.timerMutex.Unlock()
141+
if d.dataDir == "" || closed {
138142
return nil
139143
}
140144
if result := d.DB().Raw("VACUUM"); result.Error != nil {
@@ -147,6 +151,9 @@ func (d *MetadataStoreSqlite) runVacuum() error {
147151
func (d *MetadataStoreSqlite) scheduleDailyVacuum() {
148152
d.timerMutex.Lock()
149153
defer d.timerMutex.Unlock()
154+
if d.closed {
155+
return
156+
}
150157

151158
if d.timerVacuum != nil {
152159
d.timerVacuum.Stop()
@@ -176,6 +183,7 @@ func (d *MetadataStoreSqlite) AutoMigrate(dst ...any) error {
176183
// Close gets the database handle from our MetadataStore and closes it
177184
func (d *MetadataStoreSqlite) Close() error {
178185
d.timerMutex.Lock()
186+
d.closed = true
179187
if d.timerVacuum != nil {
180188
d.timerVacuum.Stop()
181189
d.timerVacuum = nil

0 commit comments

Comments
 (0)