Skip to content
This repository has been archived by the owner on Aug 13, 2019. It is now read-only.

Commit

Permalink
Add block ULID to index reader errors
Browse files Browse the repository at this point in the history
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
  • Loading branch information
gouthamve committed Jan 16, 2018
1 parent 50211e8 commit 2c3400a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 10 deletions.
38 changes: 35 additions & 3 deletions block.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 {
Expand Down
14 changes: 7 additions & 7 deletions index/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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")
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 2c3400a

Please sign in to comment.