Re-enable head block delet test

This commit is contained in:
Fabian Reinartz 2017-09-04 15:07:30 +02:00
parent 1698c516ad
commit af2c2f9674
2 changed files with 77 additions and 74 deletions

2
db.go
View File

@ -302,6 +302,8 @@ type dbAppender struct {
func (a dbAppender) Commit() error { func (a dbAppender) Commit() error {
err := a.Appender.Commit() err := a.Appender.Commit()
// We could just run this check every few minutes practically. But for benchmarks
// and high frequency use cases this is the safer way.
if a.db.head.MaxTime()-a.db.head.MinTime() > a.db.head.chunkRange/2*3 { if a.db.head.MaxTime()-a.db.head.MinTime() > a.db.head.chunkRange/2*3 {
select { select {
case a.db.compactc <- struct{}{}: case a.db.compactc <- struct{}{}:

View File

@ -15,6 +15,7 @@ package tsdb
import ( import (
"io/ioutil" "io/ioutil"
"math/rand"
"os" "os"
"testing" "testing"
"unsafe" "unsafe"
@ -192,95 +193,95 @@ func TestMemSeries_truncateChunks(t *testing.T) {
require.False(t, ok, "non-last chunk incorrectly wrapped with sample buffer") require.False(t, ok, "non-last chunk incorrectly wrapped with sample buffer")
} }
// func TestHBDeleteSimple(t *testing.T) { func TestHeadDeleteSimple(t *testing.T) {
// numSamples := int64(10) numSamples := int64(10)
// hb, close := openTestDB(t, nil) head, err := NewHead(nil, nil, nil, 1000)
// defer close() require.NoError(t, err)
// app := hb.Appender() app := head.Appender()
// smpls := make([]float64, numSamples) smpls := make([]float64, numSamples)
// for i := int64(0); i < numSamples; i++ { for i := int64(0); i < numSamples; i++ {
// smpls[i] = rand.Float64() smpls[i] = rand.Float64()
// app.Add(labels.Labels{{"a", "b"}}, i, smpls[i]) app.Add(labels.Labels{{"a", "b"}}, i, smpls[i])
// } }
// require.NoError(t, app.Commit()) require.NoError(t, app.Commit())
// cases := []struct { cases := []struct {
// intervals Intervals intervals Intervals
// remaint []int64 remaint []int64
// }{ }{
// { {
// intervals: Intervals{{0, 3}}, intervals: Intervals{{0, 3}},
// remaint: []int64{4, 5, 6, 7, 8, 9}, remaint: []int64{4, 5, 6, 7, 8, 9},
// }, },
// { {
// intervals: Intervals{{1, 3}}, intervals: Intervals{{1, 3}},
// remaint: []int64{0, 4, 5, 6, 7, 8, 9}, remaint: []int64{0, 4, 5, 6, 7, 8, 9},
// }, },
// { {
// intervals: Intervals{{1, 3}, {4, 7}}, intervals: Intervals{{1, 3}, {4, 7}},
// remaint: []int64{0, 8, 9}, remaint: []int64{0, 8, 9},
// }, },
// { {
// intervals: Intervals{{1, 3}, {4, 700}}, intervals: Intervals{{1, 3}, {4, 700}},
// remaint: []int64{0}, remaint: []int64{0},
// }, },
// { {
// intervals: Intervals{{0, 9}}, intervals: Intervals{{0, 9}},
// remaint: []int64{}, remaint: []int64{},
// }, },
// } }
// Outer: Outer:
// for _, c := range cases { for _, c := range cases {
// // Reset the tombstones. // Reset the tombstones.
// hb.tombstones = newEmptyTombstoneReader() head.tombstones = newEmptyTombstoneReader()
// // Delete the ranges. // Delete the ranges.
// for _, r := range c.intervals { for _, r := range c.intervals {
// require.NoError(t, hb.Delete(r.Mint, r.Maxt, labels.NewEqualMatcher("a", "b"))) require.NoError(t, head.Delete(r.Mint, r.Maxt, labels.NewEqualMatcher("a", "b")))
// } }
// // Compare the result. // Compare the result.
// q := hb.Querier(0, numSamples) q := NewBlockQuerier(head.Index(), head.Chunks(), head.Tombstones(), head.MinTime(), head.MaxTime())
// res := q.Select(labels.NewEqualMatcher("a", "b")) res := q.Select(labels.NewEqualMatcher("a", "b"))
// expSamples := make([]sample, 0, len(c.remaint)) expSamples := make([]sample, 0, len(c.remaint))
// for _, ts := range c.remaint { for _, ts := range c.remaint {
// expSamples = append(expSamples, sample{ts, smpls[ts]}) expSamples = append(expSamples, sample{ts, smpls[ts]})
// } }
// expss := newListSeriesSet([]Series{ expss := newListSeriesSet([]Series{
// newSeries(map[string]string{"a": "b"}, expSamples), newSeries(map[string]string{"a": "b"}, expSamples),
// }) })
// if len(expSamples) == 0 { if len(expSamples) == 0 {
// require.False(t, res.Next()) require.False(t, res.Next())
// continue continue
// } }
// for { for {
// eok, rok := expss.Next(), res.Next() eok, rok := expss.Next(), res.Next()
// require.Equal(t, eok, rok, "next") require.Equal(t, eok, rok, "next")
// if !eok { if !eok {
// continue Outer continue Outer
// } }
// sexp := expss.At() sexp := expss.At()
// sres := res.At() sres := res.At()
// require.Equal(t, sexp.Labels(), sres.Labels(), "labels") require.Equal(t, sexp.Labels(), sres.Labels(), "labels")
// smplExp, errExp := expandSeriesIterator(sexp.Iterator()) smplExp, errExp := expandSeriesIterator(sexp.Iterator())
// smplRes, errRes := expandSeriesIterator(sres.Iterator()) smplRes, errRes := expandSeriesIterator(sres.Iterator())
// require.Equal(t, errExp, errRes, "samples error") require.Equal(t, errExp, errRes, "samples error")
// require.Equal(t, smplExp, smplRes, "samples") require.Equal(t, smplExp, smplRes, "samples")
// } }
// } }
// } }
// func TestDeleteUntilCurMax(t *testing.T) { // func TestDeleteUntilCurMax(t *testing.T) {
// numSamples := int64(10) // numSamples := int64(10)