Add block ULID to index reader errors

Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
This commit is contained in:
Goutham Veeramachaneni 2018-01-16 22:52:50 +05:30
parent 50211e89ad
commit 2c3400ab4e
2 changed files with 42 additions and 10 deletions

View File

@ -319,7 +319,7 @@ func (pb *Block) Index() (IndexReader, error) {
if err := pb.startRead(); err != nil { if err := pb.startRead(); err != nil {
return nil, err 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. // Chunks returns a new ChunkReader against the block data.
@ -344,8 +344,40 @@ func (pb *Block) setCompactionFailed() error {
} }
type blockIndexReader struct { type blockIndexReader struct {
IndexReader ir IndexReader
b *Block 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 { func (r blockIndexReader) Close() error {

View File

@ -585,6 +585,10 @@ func NewFileReader(path string, version int) (*Reader, error) {
} }
func newReader(b ByteSlice, c io.Closer, 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{ r := &Reader{
b: b, b: b,
c: c, c: c,
@ -595,10 +599,6 @@ func newReader(b ByteSlice, c io.Closer, version int) (*Reader, error) {
version: version, version: version,
} }
if version != 1 && version != 2 {
return nil, errors.Errorf("unexpected file version %d", version)
}
// Verify magic number. // Verify magic number.
if b.Len() < 4 { if b.Len() < 4 {
return nil, errors.Wrap(errInvalidSize, "index header") return nil, errors.Wrap(errInvalidSize, "index header")
@ -674,7 +674,7 @@ func (r *Reader) readTOC() error {
d := decbuf{b: b[:len(b)-4]} d := decbuf{b: b[:len(b)-4]}
if d.crc32() != expCRC { if d.crc32() != expCRC {
return errInvalidChecksum return errors.Wrap(errInvalidChecksum, "read TOC")
} }
r.toc.symbols = d.be64() r.toc.symbols = d.be64()
@ -763,7 +763,7 @@ func (r *Reader) readSymbols(off int) error {
nextPos = basePos + uint32(origLen-d.len()) nextPos = basePos + uint32(origLen-d.len())
cnt-- cnt--
} }
return d.err() return errors.Wrap(d.err(), "read symbols")
} }
// readOffsetTable reads an offset table at the given position calls f for each // 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 { if d.err() != nil {
return d.err() 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. // Postings returns a postings list for the given label pair.