From 2c3400ab4e1f8036e7c0637ea3ed5d634ef5b3ab Mon Sep 17 00:00:00 2001 From: Goutham Veeramachaneni Date: Tue, 16 Jan 2018 22:52:50 +0530 Subject: [PATCH] Add block ULID to index reader errors Signed-off-by: Goutham Veeramachaneni --- block.go | 38 +++++++++++++++++++++++++++++++++++--- index/index.go | 14 +++++++------- 2 files changed, 42 insertions(+), 10 deletions(-) diff --git a/block.go b/block.go index 2dab0c32d..8cf28fe0e 100644 --- a/block.go +++ b/block.go @@ -319,7 +319,7 @@ func (pb *Block) Index() (IndexReader, error) { if err := pb.startRead(); err != nil { return nil, err } - return blockIndexReader{IndexReader: pb.indexr, b: pb}, nil + return blockIndexReader{ir: pb.indexr, b: pb}, nil } // Chunks returns a new ChunkReader against the block data. @@ -344,8 +344,40 @@ func (pb *Block) setCompactionFailed() error { } type blockIndexReader struct { - IndexReader - b *Block + ir IndexReader + b *Block +} + +func (r blockIndexReader) Symbols() (map[string]struct{}, error) { + s, err := r.ir.Symbols() + return s, errors.Wrapf(err, "block: %s", r.b.Meta().ULID) +} + +func (r blockIndexReader) LabelValues(names ...string) (index.StringTuples, error) { + st, err := r.ir.LabelValues(names...) + return st, errors.Wrapf(err, "block: %s", r.b.Meta().ULID) +} + +func (r blockIndexReader) Postings(name, value string) (index.Postings, error) { + p, err := r.ir.Postings(name, value) + return p, errors.Wrapf(err, "block: %s", r.b.Meta().ULID) +} + +func (r blockIndexReader) SortedPostings(p index.Postings) index.Postings { + return r.ir.SortedPostings(p) +} + +func (r blockIndexReader) Series(ref uint64, lset *labels.Labels, chks *[]chunks.Meta) error { + return errors.Wrapf( + r.ir.Series(ref, lset, chks), + "block: %s", + r.b.Meta().ULID, + ) +} + +func (r blockIndexReader) LabelIndices() ([][]string, error) { + ss, err := r.ir.LabelIndices() + return ss, errors.Wrapf(err, "block: %s", r.b.Meta().ULID) } func (r blockIndexReader) Close() error { diff --git a/index/index.go b/index/index.go index df8d7b5fe..a07ee8c11 100644 --- a/index/index.go +++ b/index/index.go @@ -585,6 +585,10 @@ func NewFileReader(path string, version int) (*Reader, error) { } func newReader(b ByteSlice, c io.Closer, version int) (*Reader, error) { + if version != 1 && version != 2 { + return nil, errors.Errorf("unexpected file version %d", version) + } + r := &Reader{ b: b, c: c, @@ -595,10 +599,6 @@ func newReader(b ByteSlice, c io.Closer, version int) (*Reader, error) { version: version, } - if version != 1 && version != 2 { - return nil, errors.Errorf("unexpected file version %d", version) - - } // Verify magic number. if b.Len() < 4 { return nil, errors.Wrap(errInvalidSize, "index header") @@ -674,7 +674,7 @@ func (r *Reader) readTOC() error { d := decbuf{b: b[:len(b)-4]} if d.crc32() != expCRC { - return errInvalidChecksum + return errors.Wrap(errInvalidChecksum, "read TOC") } r.toc.symbols = d.be64() @@ -763,7 +763,7 @@ func (r *Reader) readSymbols(off int) error { nextPos = basePos + uint32(origLen-d.len()) cnt-- } - return d.err() + return errors.Wrap(d.err(), "read symbols") } // readOffsetTable reads an offset table at the given position calls f for each @@ -876,7 +876,7 @@ func (r *Reader) Series(id uint64, lbls *labels.Labels, chks *[]chunks.Meta) err if d.err() != nil { return d.err() } - return r.dec.Series(d.get(), lbls, chks) + return errors.Wrap(r.dec.Series(d.get(), lbls, chks), "read series") } // Postings returns a postings list for the given label pair.