Skip to content

Commit

Permalink
Revert "Allow out of order samples to be written to the WAL (grafana#…
Browse files Browse the repository at this point in the history
…5490)"

This reverts commit 7275f65.
  • Loading branch information
tpaschalis committed Oct 17, 2023
1 parent 52bc273 commit 2158e9b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 29 deletions.
10 changes: 10 additions & 0 deletions pkg/metrics/wal/wal.go
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,11 @@ func (a *appender) Append(ref storage.SeriesRef, l labels.Labels, t int64, v flo
series.Lock()
defer series.Unlock()

if t < series.lastTs {
a.w.metrics.totalOutOfOrderSamples.Inc()
return 0, storage.ErrOutOfOrderSample
}

// NOTE(rfratto): always modify pendingSamples and sampleSeries together.
a.pendingSamples = append(a.pendingSamples, record.RefSample{
Ref: series.ref,
Expand Down Expand Up @@ -819,6 +824,11 @@ func (a *appender) AppendHistogram(ref storage.SeriesRef, l labels.Labels, t int
series.Lock()
defer series.Unlock()

if t < series.lastTs {
a.w.metrics.totalOutOfOrderSamples.Inc()
return 0, storage.ErrOutOfOrderSample
}

switch {
case h != nil:
// NOTE(rfratto): always modify pendingHistograms and histogramSeries
Expand Down
29 changes: 0 additions & 29 deletions pkg/metrics/wal/wal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,35 +434,6 @@ func TestGlobalReferenceID_Normal(t *testing.T) {
require.True(t, ref3 == 2)
}

func TestDBAllowOOOSamples(t *testing.T) {
walDir := t.TempDir()

s, err := NewStorage(log.NewNopLogger(), nil, walDir)
require.NoError(t, err)
defer func() {
require.NoError(t, s.Close())
}()

app := s.Appender(context.Background())

// Write some samples
payload := buildSeries([]string{"foo", "bar", "baz"})
for _, metric := range payload {
metric.Write(t, app)
}

require.NoError(t, app.Commit())
for _, metric := range payload {
for _, sa := range metric.samples {
// We want to set the timestamp to before. This should no longer trigger an out of order.
sa.ts = sa.ts - 10_000
}
}
for _, metric := range payload {
metric.Write(t, app)
}
}

func BenchmarkAppendExemplar(b *testing.B) {
walDir := b.TempDir()

Expand Down

0 comments on commit 2158e9b

Please sign in to comment.