Skip to content

Commit

Permalink
cleanup boltdb files in queriers during startup/shutdown (#2558)
Browse files Browse the repository at this point in the history
  • Loading branch information
sandeepsukhani authored Aug 27, 2020
1 parent 2bb2eeb commit 4f6a4c2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pkg/storage/stores/shipper/downloads/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,14 @@ func (t *Table) Close() {
defer t.dbsMtx.Unlock()

for name, db := range t.dbs {
dbPath := db.boltdb.Path()

if err := db.boltdb.Close(); err != nil {
level.Error(util.Logger).Log("msg", fmt.Errorf("failed to close file %s for table %s", name, t.name))
level.Error(util.Logger).Log("msg", fmt.Sprintf("failed to close file %s for table %s", name, t.name), "err", err)
}

if err := os.Remove(dbPath); err != nil {
level.Error(util.Logger).Log("msg", fmt.Sprintf("failed to remove file %s for table %s", name, t.name), "err", err)
}
}

Expand Down
10 changes: 10 additions & 0 deletions pkg/storage/stores/shipper/downloads/table_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package downloads
import (
"context"
"fmt"
"os"
"sync"
"time"

Expand Down Expand Up @@ -37,6 +38,15 @@ type TableManager struct {
}

func NewTableManager(cfg Config, boltIndexClient BoltDBIndexClient, storageClient StorageClient, registerer prometheus.Registerer) (*TableManager, error) {
// cleanup existing directory and re-create it since we do not use existing files in it.
if err := os.RemoveAll(cfg.CacheDir); err != nil {
return nil, err
}

if err := chunk_util.EnsureDirectory(cfg.CacheDir); err != nil {
return nil, err
}

ctx, cancel := context.WithCancel(context.Background())
tm := &TableManager{
cfg: cfg,
Expand Down

0 comments on commit 4f6a4c2

Please sign in to comment.