Skip to content

Commit

Permalink
chore: use quartz in metastore (#13900)
Browse files Browse the repository at this point in the history
  • Loading branch information
grobinson-grafana authored Sep 10, 2024
1 parent e9cec1d commit 4cd77b9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions pkg/ingester-rf1/metastore/metastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"sync"
"time"

"github.com/coder/quartz"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/grafana/dskit/flagext"
Expand Down Expand Up @@ -88,6 +89,9 @@ type Metastore struct {

done chan struct{}
wg sync.WaitGroup

// Used in tests.
clock quartz.Clock
}

func New(config Config, logger log.Logger, reg prometheus.Registerer, hs health.Service) (*Metastore, error) {
Expand All @@ -97,6 +101,7 @@ func New(config Config, logger log.Logger, reg prometheus.Registerer, hs health.
reg: reg,
db: newDB(config, logger),
done: make(chan struct{}),
clock: quartz.NewReal(),
}
m.leaderhealth = raftleader.NewRaftLeaderHealthObserver(hs, logger)
m.state = newMetastoreState(logger, m.db)
Expand Down
2 changes: 1 addition & 1 deletion pkg/ingester-rf1/metastore/metastore_hack.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (m *Metastore) cleanupLoop() {
if m.raft.State() != raft.Leader {
continue
}
timestamp := uint64(time.Now().Add(-1 * time.Hour).UnixMilli())
timestamp := uint64(m.clock.Now().Add(-1 * time.Hour).UnixMilli())
req := &raftlogpb.TruncateCommand{Timestamp: timestamp}
_, _, err := applyCommand[*raftlogpb.TruncateCommand, *anypb.Any](m.raft, req, m.config.Raft.ApplyTimeout)
if err != nil {
Expand Down

0 comments on commit 4cd77b9

Please sign in to comment.