From d05611c027731d93e1c18e14fdde66c66cd34a1e Mon Sep 17 00:00:00 2001 From: Krasi Georgiev Date: Fri, 21 Sep 2018 11:07:35 +0300 Subject: [PATCH] removed some unused code and moved mockSeriesSet in querier_test (#394) Signed-off-by: Krasi Georgiev --- block.go | 6 ------ db_test.go | 6 +++--- head_test.go | 4 ++-- querier.go | 24 --------------------- querier_test.go | 56 +++++++++++++++++++++++++++++++++++-------------- wal.go | 9 -------- 6 files changed, 45 insertions(+), 60 deletions(-) diff --git a/block.go b/block.go index 7c4ccf0dc..5cec4ca56 100644 --- a/block.go +++ b/block.go @@ -185,16 +185,10 @@ type BlockMetaCompaction struct { Failed bool `json:"failed,omitempty"` } -const ( - flagNone = 0 - flagStd = 1 -) - const indexFilename = "index" const metaFilename = "meta.json" func chunkDir(dir string) string { return filepath.Join(dir, "chunks") } -func walDir(dir string) string { return filepath.Join(dir, "wal") } func readMetaFile(dir string) (*BlockMeta, error) { b, err := ioutil.ReadFile(filepath.Join(dir, metaFilename)) diff --git a/db_test.go b/db_test.go index 916df5efd..073b727b3 100644 --- a/db_test.go +++ b/db_test.go @@ -247,7 +247,7 @@ Outer: expSamples = append(expSamples, sample{ts, smpls[ts]}) } - expss := newListSeriesSet([]Series{ + expss := newMockSeriesSet([]Series{ newSeries(map[string]string{"a": "b"}, expSamples), }) @@ -474,7 +474,7 @@ Outer: expSamples = append(expSamples, sample{ts, smpls[ts]}) } - expss := newListSeriesSet([]Series{ + expss := newMockSeriesSet([]Series{ newSeries(map[string]string{"a": "b"}, expSamples), }) @@ -753,7 +753,7 @@ func TestTombstoneClean(t *testing.T) { expSamples = append(expSamples, sample{ts, smpls[ts]}) } - expss := newListSeriesSet([]Series{ + expss := newMockSeriesSet([]Series{ newSeries(map[string]string{"a": "b"}, expSamples), }) diff --git a/head_test.go b/head_test.go index 76a8b72e6..0392912ce 100644 --- a/head_test.go +++ b/head_test.go @@ -355,7 +355,7 @@ Outer: expSamples = append(expSamples, sample{ts, smpls[ts]}) } - expss := newListSeriesSet([]Series{ + expss := newMockSeriesSet([]Series{ newSeries(map[string]string{"a": "b"}, expSamples), }) @@ -553,7 +553,7 @@ func TestDelete_e2e(t *testing.T) { )) } } - expSs := newListSeriesSet(matchedSeries) + expSs := newMockSeriesSet(matchedSeries) // Compare both SeriesSets. for { eok, rok := expSs.Next(), ss.Next() diff --git a/querier.go b/querier.go index 2e048e495..dbd49cec8 100644 --- a/querier.go +++ b/querier.go @@ -892,30 +892,6 @@ func (it *deletedIterator) Err() error { return it.it.Err() } -type mockSeriesSet struct { - next func() bool - series func() Series - err func() error -} - -func (m *mockSeriesSet) Next() bool { return m.next() } -func (m *mockSeriesSet) At() Series { return m.series() } -func (m *mockSeriesSet) Err() error { return m.err() } - -func newListSeriesSet(list []Series) *mockSeriesSet { - i := -1 - return &mockSeriesSet{ - next: func() bool { - i++ - return i < len(list) - }, - series: func() Series { - return list[i] - }, - err: func() error { return nil }, - } -} - type errSeriesSet struct { err error } diff --git a/querier_test.go b/querier_test.go index 3515df3eb..87a45b647 100644 --- a/querier_test.go +++ b/querier_test.go @@ -28,6 +28,30 @@ import ( "github.com/prometheus/tsdb/testutil" ) +type mockSeriesSet struct { + next func() bool + series func() Series + err func() error +} + +func (m *mockSeriesSet) Next() bool { return m.next() } +func (m *mockSeriesSet) At() Series { return m.series() } +func (m *mockSeriesSet) Err() error { return m.err() } + +func newMockSeriesSet(list []Series) *mockSeriesSet { + i := -1 + return &mockSeriesSet{ + next: func() bool { + i++ + return i < len(list) + }, + series: func() Series { + return list[i] + }, + err: func() error { return nil }, + } +} + type mockSeriesIterator struct { seek func(int64) bool at func() (int64, float64) @@ -101,14 +125,14 @@ func TestMergedSeriesSet(t *testing.T) { exp SeriesSet }{ { - a: newListSeriesSet([]Series{ + a: newMockSeriesSet([]Series{ newSeries(map[string]string{ "a": "a", }, []sample{ {t: 1, v: 1}, }), }), - b: newListSeriesSet([]Series{ + b: newMockSeriesSet([]Series{ newSeries(map[string]string{ "a": "a", }, []sample{ @@ -120,7 +144,7 @@ func TestMergedSeriesSet(t *testing.T) { {t: 1, v: 1}, }), }), - exp: newListSeriesSet([]Series{ + exp: newMockSeriesSet([]Series{ newSeries(map[string]string{ "a": "a", }, []sample{ @@ -135,7 +159,7 @@ func TestMergedSeriesSet(t *testing.T) { }), }, { - a: newListSeriesSet([]Series{ + a: newMockSeriesSet([]Series{ newSeries(map[string]string{ "handler": "prometheus", "instance": "127.0.0.1:9090", @@ -149,7 +173,7 @@ func TestMergedSeriesSet(t *testing.T) { {t: 1, v: 2}, }), }), - b: newListSeriesSet([]Series{ + b: newMockSeriesSet([]Series{ newSeries(map[string]string{ "handler": "prometheus", "instance": "127.0.0.1:9090", @@ -163,7 +187,7 @@ func TestMergedSeriesSet(t *testing.T) { {t: 2, v: 2}, }), }), - exp: newListSeriesSet([]Series{ + exp: newMockSeriesSet([]Series{ newSeries(map[string]string{ "handler": "prometheus", "instance": "127.0.0.1:9090", @@ -397,25 +421,25 @@ func TestBlockQuerier(t *testing.T) { mint: 0, maxt: 0, ms: []labels.Matcher{}, - exp: newListSeriesSet([]Series{}), + exp: newMockSeriesSet([]Series{}), }, { mint: 0, maxt: 0, ms: []labels.Matcher{labels.NewEqualMatcher("a", "a")}, - exp: newListSeriesSet([]Series{}), + exp: newMockSeriesSet([]Series{}), }, { mint: 1, maxt: 0, ms: []labels.Matcher{labels.NewEqualMatcher("a", "a")}, - exp: newListSeriesSet([]Series{}), + exp: newMockSeriesSet([]Series{}), }, { mint: 2, maxt: 6, ms: []labels.Matcher{labels.NewEqualMatcher("a", "a")}, - exp: newListSeriesSet([]Series{ + exp: newMockSeriesSet([]Series{ newSeries(map[string]string{ "a": "a", }, @@ -433,7 +457,7 @@ func TestBlockQuerier(t *testing.T) { mint: 2, maxt: 6, ms: []labels.Matcher{labels.NewPrefixMatcher("p", "abc")}, - exp: newListSeriesSet([]Series{ + exp: newMockSeriesSet([]Series{ newSeries(map[string]string{ "a": "ab", "p": "abce", @@ -567,7 +591,7 @@ func TestBlockQuerierDelete(t *testing.T) { mint: 2, maxt: 7, ms: []labels.Matcher{labels.NewEqualMatcher("a", "a")}, - exp: newListSeriesSet([]Series{ + exp: newMockSeriesSet([]Series{ newSeries(map[string]string{ "a": "a", }, @@ -585,7 +609,7 @@ func TestBlockQuerierDelete(t *testing.T) { mint: 2, maxt: 7, ms: []labels.Matcher{labels.NewEqualMatcher("b", "b")}, - exp: newListSeriesSet([]Series{ + exp: newMockSeriesSet([]Series{ newSeries(map[string]string{ "a": "a", "b": "b", @@ -603,7 +627,7 @@ func TestBlockQuerierDelete(t *testing.T) { mint: 1, maxt: 4, ms: []labels.Matcher{labels.NewEqualMatcher("a", "a")}, - exp: newListSeriesSet([]Series{ + exp: newMockSeriesSet([]Series{ newSeries(map[string]string{ "a": "a", "b": "b", @@ -616,7 +640,7 @@ func TestBlockQuerierDelete(t *testing.T) { mint: 1, maxt: 3, ms: []labels.Matcher{labels.NewEqualMatcher("a", "a")}, - exp: newListSeriesSet([]Series{}), + exp: newMockSeriesSet([]Series{}), }, }, } @@ -1266,7 +1290,7 @@ func BenchmarkMergedSeriesSet(b *testing.B) { for i := 0; i < b.N; i++ { var sets []SeriesSet for _, s := range in { - sets = append(sets, newListSeriesSet(s)) + sets = append(sets, newMockSeriesSet(s)) } ms := sel(sets) diff --git a/wal.go b/wal.go index 59206d8d0..28217639d 100644 --- a/wal.go +++ b/wal.go @@ -750,15 +750,6 @@ func (w *SegmentWAL) Close() error { return errors.Wrapf(w.dirFile.Close(), "closing WAL dir %s", w.dirFile.Name()) } -const ( - minSectorSize = 512 - - // walPageBytes is the alignment for flushing records to the backing Writer. - // It should be a multiple of the minimum sector size so that WAL can safely - // distinguish between torn writes and ordinary data corruption. - walPageBytes = 16 * minSectorSize -) - func (w *SegmentWAL) write(t WALEntryType, flag uint8, buf []byte) error { // Cut to the next segment if the entry exceeds the file size unless it would also // exceed the size of a new segment.