Skip to content

Commit 4cd77b9

Browse files
chore: use quartz in metastore (#13900)
1 parent e9cec1d commit 4cd77b9

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

pkg/ingester-rf1/metastore/metastore.go

+5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"sync"
1313
"time"
1414

15+
"github.com/coder/quartz"
1516
"github.com/go-kit/log"
1617
"github.com/go-kit/log/level"
1718
"github.com/grafana/dskit/flagext"
@@ -88,6 +89,9 @@ type Metastore struct {
8889

8990
done chan struct{}
9091
wg sync.WaitGroup
92+
93+
// Used in tests.
94+
clock quartz.Clock
9195
}
9296

9397
func New(config Config, logger log.Logger, reg prometheus.Registerer, hs health.Service) (*Metastore, error) {
@@ -97,6 +101,7 @@ func New(config Config, logger log.Logger, reg prometheus.Registerer, hs health.
97101
reg: reg,
98102
db: newDB(config, logger),
99103
done: make(chan struct{}),
104+
clock: quartz.NewReal(),
100105
}
101106
m.leaderhealth = raftleader.NewRaftLeaderHealthObserver(hs, logger)
102107
m.state = newMetastoreState(logger, m.db)

pkg/ingester-rf1/metastore/metastore_hack.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func (m *Metastore) cleanupLoop() {
2929
if m.raft.State() != raft.Leader {
3030
continue
3131
}
32-
timestamp := uint64(time.Now().Add(-1 * time.Hour).UnixMilli())
32+
timestamp := uint64(m.clock.Now().Add(-1 * time.Hour).UnixMilli())
3333
req := &raftlogpb.TruncateCommand{Timestamp: timestamp}
3434
_, _, err := applyCommand[*raftlogpb.TruncateCommand, *anypb.Any](m.raft, req, m.config.Raft.ApplyTimeout)
3535
if err != nil {

0 commit comments

Comments
 (0)