Skip to content

Commit

Permalink
indexheader: don't fail the start of the Snapshotter
Browse files Browse the repository at this point in the history
Signed-off-by: Vladimir Varankin <vladimir.varankin@grafana.com>
  • Loading branch information
narqo committed Jun 18, 2024
1 parent 013b16e commit e1114e3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
8 changes: 2 additions & 6 deletions pkg/storegateway/bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,14 +361,10 @@ func (s *BucketStore) syncBlocks(ctx context.Context, initialSync bool) error {
}

// Start snapshotter in the end of the sync, but do that only once per BucketStore's lifetime.
// We do that here so the snapshotter watched after blocks from both initial sync and those discovered later.
var err error
// We do that here, so the snapshotter watched after blocks from both initial sync and those discovered later.
s.snapshotterStartOnce.Do(func() {
err = s.snapshotter.Start(ctx, s.indexReaderPool)
s.snapshotter.Start(ctx, s.indexReaderPool)
})
if err != nil {
return errors.Wrap(err, "start index headers snapshotter")
}

return nil
}
Expand Down
17 changes: 8 additions & 9 deletions pkg/storegateway/indexheader/snapshotter.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"bytes"
"context"
"encoding/json"
"fmt"
"os"
"path/filepath"
"time"
Expand Down Expand Up @@ -46,13 +45,15 @@ type blocksLoader interface {
LoadedBlocks() map[ulid.ULID]int64
}

func (s *Snapshotter) Start(ctx context.Context, bl blocksLoader) error {
err := s.PersistLoadedBlocks(bl)
if err != nil {
return fmt.Errorf("persist initial list of lazy-loaded index headers: %w", err)
}

// Start spawns a background job that periodically persists the list of lazy-loaded index headers.
func (s *Snapshotter) Start(ctx context.Context, bl blocksLoader) {
go func() {
err := s.PersistLoadedBlocks(bl)
if err != nil {
// Note, the decision here is to only log the error but not failing the job. We may reconsider that later.
level.Warn(s.logger).Log("msg", "failed to persist initial list of lazy-loaded index headers", "err", err)
}

tick := time.NewTicker(time.Minute)
defer tick.Stop()

Expand All @@ -69,8 +70,6 @@ func (s *Snapshotter) Start(ctx context.Context, bl blocksLoader) error {
}
}
}()

return nil
}

func (s *Snapshotter) Stop() {
Expand Down

0 comments on commit e1114e3

Please sign in to comment.