Rename Iterator to Postings

This commit is contained in:
Fabian Reinartz 2016-12-14 21:58:29 +01:00
parent c1acd3fe85
commit d56b281006
6 changed files with 48 additions and 48 deletions

View file

@ -66,7 +66,7 @@ func (h *HeadBlock) LabelValues(names ...string) (StringTuples, error) {
} }
// Postings returns the postings list iterator for the label pair. // Postings returns the postings list iterator for the label pair.
func (h *HeadBlock) Postings(name, value string) (Iterator, error) { func (h *HeadBlock) Postings(name, value string) (Postings, error) {
return h.index.Postings(term{name, value}), nil return h.index.Postings(term{name, value}), nil
} }

View file

@ -27,7 +27,7 @@ func (ix *memIndex) numSeries() int {
return len(ix.forward) return len(ix.forward)
} }
func (ix *memIndex) Postings(t term) Iterator { func (ix *memIndex) Postings(t term) Postings {
return ix.postings.get(t) return ix.postings.get(t)
} }
@ -64,7 +64,7 @@ type memPostings struct {
} }
// Postings returns an iterator over the postings list for s. // Postings returns an iterator over the postings list for s.
func (p *memPostings) get(t term) Iterator { func (p *memPostings) get(t term) Postings {
return &listIterator{list: p.m[t], idx: -1} return &listIterator{list: p.m[t], idx: -1}
} }
@ -76,8 +76,8 @@ func (p *memPostings) add(id uint32, terms ...term) {
} }
} }
// Iterator provides iterative access over a postings list. // Postings provides iterative access over a postings list.
type Iterator interface { type Postings interface {
// Next advances the iterator and returns true if another value was found. // Next advances the iterator and returns true if another value was found.
Next() bool Next() bool
@ -92,80 +92,80 @@ type Iterator interface {
Err() error Err() error
} }
// errIterator is an empty iterator that always errors. // errPostings is an empty iterator that always errors.
type errIterator struct { type errPostings struct {
err error err error
} }
func (e errIterator) Next() bool { return false } func (e errPostings) Next() bool { return false }
func (e errIterator) Seek(uint32) bool { return false } func (e errPostings) Seek(uint32) bool { return false }
func (e errIterator) Value() uint32 { return 0 } func (e errPostings) Value() uint32 { return 0 }
func (e errIterator) Err() error { return e.err } func (e errPostings) Err() error { return e.err }
// Intersect returns a new iterator over the intersection of the // Intersect returns a new postings list over the intersection of the
// input iterators. // input postings.
func Intersect(its ...Iterator) Iterator { func Intersect(its ...Postings) Postings {
if len(its) == 0 { if len(its) == 0 {
return errIterator{err: nil} return errPostings{err: nil}
} }
a := its[0] a := its[0]
for _, b := range its[1:] { for _, b := range its[1:] {
a = &intersectIterator{a: a, b: b} a = &intersectPostings{a: a, b: b}
} }
return a return a
} }
type intersectIterator struct { type intersectPostings struct {
a, b Iterator a, b Postings
} }
func (it *intersectIterator) Value() uint32 { func (it *intersectPostings) Value() uint32 {
return 0 return 0
} }
func (it *intersectIterator) Next() bool { func (it *intersectPostings) Next() bool {
return false return false
} }
func (it *intersectIterator) Seek(id uint32) bool { func (it *intersectPostings) Seek(id uint32) bool {
return false return false
} }
func (it *intersectIterator) Err() error { func (it *intersectPostings) Err() error {
return nil return nil
} }
// Merge returns a new iterator over the union of the input iterators. // Merge returns a new iterator over the union of the input iterators.
func Merge(its ...Iterator) Iterator { func Merge(its ...Postings) Postings {
if len(its) == 0 { if len(its) == 0 {
return nil return nil
} }
a := its[0] a := its[0]
for _, b := range its[1:] { for _, b := range its[1:] {
a = &mergeIterator{a: a, b: b} a = &mergePostings{a: a, b: b}
} }
return a return a
} }
type mergeIterator struct { type mergePostings struct {
a, b Iterator a, b Postings
} }
func (it *mergeIterator) Value() uint32 { func (it *mergePostings) Value() uint32 {
return 0 return 0
} }
func (it *mergeIterator) Next() bool { func (it *mergePostings) Next() bool {
return false return false
} }
func (it *mergeIterator) Seek(id uint32) bool { func (it *mergePostings) Seek(id uint32) bool {
return false return false
} }
func (it *mergeIterator) Err() error { func (it *mergePostings) Err() error {
return nil return nil
} }

View file

@ -153,7 +153,7 @@ func newBlockQuerier(ix IndexReader, s SeriesReader, mint, maxt int64) *blockQue
} }
func (q *blockQuerier) Select(ms ...Matcher) SeriesSet { func (q *blockQuerier) Select(ms ...Matcher) SeriesSet {
var its []Iterator var its []Postings
for _, m := range ms { for _, m := range ms {
its = append(its, q.selectSingle(m)) its = append(its, q.selectSingle(m))
} }
@ -166,10 +166,10 @@ func (q *blockQuerier) Select(ms ...Matcher) SeriesSet {
} }
} }
func (q *blockQuerier) selectSingle(m Matcher) Iterator { func (q *blockQuerier) selectSingle(m Matcher) Postings {
tpls, err := q.index.LabelValues(m.Name()) tpls, err := q.index.LabelValues(m.Name())
if err != nil { if err != nil {
return errIterator{err: err} return errPostings{err: err}
} }
// TODO(fabxc): use interface upgrading to provide fast solution // TODO(fabxc): use interface upgrading to provide fast solution
// for equality and prefix matches. Tuples are lexicographically sorted. // for equality and prefix matches. Tuples are lexicographically sorted.
@ -178,7 +178,7 @@ func (q *blockQuerier) selectSingle(m Matcher) Iterator {
for i := 0; i < tpls.Len(); i++ { for i := 0; i < tpls.Len(); i++ {
vals, err := tpls.At(i) vals, err := tpls.At(i)
if err != nil { if err != nil {
return errIterator{err: err} return errPostings{err: err}
} }
if m.Match(vals[0]) { if m.Match(vals[0]) {
res = append(res, vals[0]) res = append(res, vals[0])
@ -186,15 +186,15 @@ func (q *blockQuerier) selectSingle(m Matcher) Iterator {
} }
if len(res) == 0 { if len(res) == 0 {
return errIterator{err: nil} return errPostings{err: nil}
} }
var rit []Iterator var rit []Postings
for _, v := range res { for _, v := range res {
it, err := q.index.Postings(m.Name(), v) it, err := q.index.Postings(m.Name(), v)
if err != nil { if err != nil {
return errIterator{err: err} return errPostings{err: err}
} }
rit = append(rit, it) rit = append(rit, it)
} }
@ -379,7 +379,7 @@ func (s *shardSeriesSet) Next() bool {
// blockSeriesSet is a set of series from an inverted index query. // blockSeriesSet is a set of series from an inverted index query.
type blockSeriesSet struct { type blockSeriesSet struct {
index IndexReader index IndexReader
it Iterator it Postings
err error err error
cur Series cur Series
@ -655,7 +655,7 @@ func (r *sampleRing) last() (int64, float64, bool) {
} }
func (r *sampleRing) samples() []sample { func (r *sampleRing) samples() []sample {
res := make([]sample, 0, r.l) res := make([]sample, r.l)
var k = r.f + r.l var k = r.f + r.l
var j int var j int
@ -664,12 +664,8 @@ func (r *sampleRing) samples() []sample {
j = r.l - k + r.f j = r.l - k + r.f
} }
for _, s := range r.buf[r.f:k] { n := copy(res, r.buf[r.f:k])
res = append(res, s) copy(res[n:], r.buf[:j])
}
for _, s := range r.buf[:j] {
res = append(res, s)
}
return res return res
} }

View file

@ -55,7 +55,7 @@ type IndexReader interface {
LabelValues(names ...string) (StringTuples, error) LabelValues(names ...string) (StringTuples, error)
// Postings returns the postings list iterator for the label pair. // Postings returns the postings list iterator for the label pair.
Postings(name, value string) (Iterator, error) Postings(name, value string) (Postings, error)
// Series returns the series for the given reference. // Series returns the series for the given reference.
Series(ref uint32) (Series, error) Series(ref uint32) (Series, error)

View file

@ -25,6 +25,8 @@ func BenchmarkLabelMapAccess(b *testing.B) {
} }
}) })
} }
_ = v
} }
func BenchmarkLabelSetAccess(b *testing.B) { func BenchmarkLabelSetAccess(b *testing.B) {
@ -47,4 +49,6 @@ func BenchmarkLabelSetAccess(b *testing.B) {
} }
}) })
} }
_ = v
} }

View file

@ -165,7 +165,7 @@ type IndexWriter interface {
WriteLabelIndex(names []string, values []string) error WriteLabelIndex(names []string, values []string) error
// WritePostings writes a postings list for a single label pair. // WritePostings writes a postings list for a single label pair.
WritePostings(name, value string, it Iterator) error WritePostings(name, value string, it Postings) error
// Size returns the size of the data written so far. // Size returns the size of the data written so far.
Size() int64 Size() int64
@ -365,7 +365,7 @@ func (w *indexWriter) WriteLabelIndex(names []string, values []string) error {
}) })
} }
func (w *indexWriter) WritePostings(name, value string, it Iterator) error { func (w *indexWriter) WritePostings(name, value string, it Postings) error {
key := name + string(sep) + value key := name + string(sep) + value
w.postings = append(w.postings, hashEntry{ w.postings = append(w.postings, hashEntry{