From da9614fa545813e30934738c6b09a6da496edc22 Mon Sep 17 00:00:00 2001 From: Fabian Reinartz Date: Tue, 5 Dec 2017 17:17:33 +0100 Subject: [PATCH] Allow tombstone file to not exist --- block_test.go | 1 + index/index_test.go | 40 ---------------------------------------- tombstones.go | 4 +++- 3 files changed, 4 insertions(+), 41 deletions(-) diff --git a/block_test.go b/block_test.go index 0764d7490..690cd07ad 100644 --- a/block_test.go +++ b/block_test.go @@ -20,6 +20,7 @@ import ( "testing" "github.com/prometheus/tsdb/index" + "github.com/prometheus/tsdb/testutil" ) func TestSetCompactionFailed(t *testing.T) { diff --git a/index/index_test.go b/index/index_test.go index dbaf9fdac..83b6ef657 100644 --- a/index/index_test.go +++ b/index/index_test.go @@ -20,10 +20,8 @@ import ( "path/filepath" "sort" "testing" - "unsafe" "github.com/pkg/errors" - "github.com/prometheus/prometheus/pkg/textparse" "github.com/prometheus/tsdb/chunkenc" "github.com/prometheus/tsdb/chunks" "github.com/prometheus/tsdb/labels" @@ -382,41 +380,3 @@ func TestPersistence_index_e2e(t *testing.T) { testutil.Ok(t, ir.Close()) } - -func readPrometheusLabels(fn string, n int) ([]labels.Labels, error) { - f, err := os.Open(fn) - if err != nil { - return nil, err - } - defer f.Close() - - b, err := ioutil.ReadAll(f) - if err != nil { - return nil, err - } - - p := textparse.New(b) - i := 0 - var mets []labels.Labels - hashes := map[uint64]struct{}{} - - for p.Next() && i < n { - m := make(labels.Labels, 0, 10) - p.Metric((*promlabels.Labels)(unsafe.Pointer(&m))) - - h := m.Hash() - if _, ok := hashes[h]; ok { - continue - } - mets = append(mets, m) - hashes[h] = struct{}{} - i++ - } - if err := p.Err(); err != nil { - return nil, err - } - if i != n { - return mets, errors.Errorf("requested %d metrics but found %d", n, i) - } - return mets, nil -} diff --git a/tombstones.go b/tombstones.go index 8ca089e61..0de3e1a99 100644 --- a/tombstones.go +++ b/tombstones.go @@ -109,7 +109,9 @@ type Stone struct { func readTombstones(dir string) (memTombstones, error) { b, err := ioutil.ReadFile(filepath.Join(dir, tombstoneFilename)) - if err != nil { + if os.IsNotExist(err) { + return memTombstones{}, nil + } else if err != nil { return nil, err }