mirror of
https://github.com/prometheus/prometheus.git
synced 2025-02-02 08:31:11 -08:00
Rename Iterator to Postings
This commit is contained in:
parent
c1acd3fe85
commit
d56b281006
2
head.go
2
head.go
|
@ -66,7 +66,7 @@ func (h *HeadBlock) LabelValues(names ...string) (StringTuples, error) {
|
|||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
|
|
58
index.go
58
index.go
|
@ -27,7 +27,7 @@ func (ix *memIndex) numSeries() int {
|
|||
return len(ix.forward)
|
||||
}
|
||||
|
||||
func (ix *memIndex) Postings(t term) Iterator {
|
||||
func (ix *memIndex) Postings(t term) Postings {
|
||||
return ix.postings.get(t)
|
||||
}
|
||||
|
||||
|
@ -64,7 +64,7 @@ type memPostings struct {
|
|||
}
|
||||
|
||||
// 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}
|
||||
}
|
||||
|
||||
|
@ -76,8 +76,8 @@ func (p *memPostings) add(id uint32, terms ...term) {
|
|||
}
|
||||
}
|
||||
|
||||
// Iterator provides iterative access over a postings list.
|
||||
type Iterator interface {
|
||||
// Postings provides iterative access over a postings list.
|
||||
type Postings interface {
|
||||
// Next advances the iterator and returns true if another value was found.
|
||||
Next() bool
|
||||
|
||||
|
@ -92,80 +92,80 @@ type Iterator interface {
|
|||
Err() error
|
||||
}
|
||||
|
||||
// errIterator is an empty iterator that always errors.
|
||||
type errIterator struct {
|
||||
// errPostings is an empty iterator that always errors.
|
||||
type errPostings struct {
|
||||
err error
|
||||
}
|
||||
|
||||
func (e errIterator) Next() bool { return false }
|
||||
func (e errIterator) Seek(uint32) bool { return false }
|
||||
func (e errIterator) Value() uint32 { return 0 }
|
||||
func (e errIterator) Err() error { return e.err }
|
||||
func (e errPostings) Next() bool { return false }
|
||||
func (e errPostings) Seek(uint32) bool { return false }
|
||||
func (e errPostings) Value() uint32 { return 0 }
|
||||
func (e errPostings) Err() error { return e.err }
|
||||
|
||||
// Intersect returns a new iterator over the intersection of the
|
||||
// input iterators.
|
||||
func Intersect(its ...Iterator) Iterator {
|
||||
// Intersect returns a new postings list over the intersection of the
|
||||
// input postings.
|
||||
func Intersect(its ...Postings) Postings {
|
||||
if len(its) == 0 {
|
||||
return errIterator{err: nil}
|
||||
return errPostings{err: nil}
|
||||
}
|
||||
a := its[0]
|
||||
|
||||
for _, b := range its[1:] {
|
||||
a = &intersectIterator{a: a, b: b}
|
||||
a = &intersectPostings{a: a, b: b}
|
||||
}
|
||||
return a
|
||||
}
|
||||
|
||||
type intersectIterator struct {
|
||||
a, b Iterator
|
||||
type intersectPostings struct {
|
||||
a, b Postings
|
||||
}
|
||||
|
||||
func (it *intersectIterator) Value() uint32 {
|
||||
func (it *intersectPostings) Value() uint32 {
|
||||
return 0
|
||||
}
|
||||
|
||||
func (it *intersectIterator) Next() bool {
|
||||
func (it *intersectPostings) Next() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (it *intersectIterator) Seek(id uint32) bool {
|
||||
func (it *intersectPostings) Seek(id uint32) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (it *intersectIterator) Err() error {
|
||||
func (it *intersectPostings) Err() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// 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 {
|
||||
return nil
|
||||
}
|
||||
a := its[0]
|
||||
|
||||
for _, b := range its[1:] {
|
||||
a = &mergeIterator{a: a, b: b}
|
||||
a = &mergePostings{a: a, b: b}
|
||||
}
|
||||
return a
|
||||
}
|
||||
|
||||
type mergeIterator struct {
|
||||
a, b Iterator
|
||||
type mergePostings struct {
|
||||
a, b Postings
|
||||
}
|
||||
|
||||
func (it *mergeIterator) Value() uint32 {
|
||||
func (it *mergePostings) Value() uint32 {
|
||||
return 0
|
||||
}
|
||||
|
||||
func (it *mergeIterator) Next() bool {
|
||||
func (it *mergePostings) Next() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (it *mergeIterator) Seek(id uint32) bool {
|
||||
func (it *mergePostings) Seek(id uint32) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (it *mergeIterator) Err() error {
|
||||
func (it *mergePostings) Err() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
26
querier.go
26
querier.go
|
@ -153,7 +153,7 @@ func newBlockQuerier(ix IndexReader, s SeriesReader, mint, maxt int64) *blockQue
|
|||
}
|
||||
|
||||
func (q *blockQuerier) Select(ms ...Matcher) SeriesSet {
|
||||
var its []Iterator
|
||||
var its []Postings
|
||||
for _, m := range ms {
|
||||
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())
|
||||
if err != nil {
|
||||
return errIterator{err: err}
|
||||
return errPostings{err: err}
|
||||
}
|
||||
// TODO(fabxc): use interface upgrading to provide fast solution
|
||||
// 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++ {
|
||||
vals, err := tpls.At(i)
|
||||
if err != nil {
|
||||
return errIterator{err: err}
|
||||
return errPostings{err: err}
|
||||
}
|
||||
if m.Match(vals[0]) {
|
||||
res = append(res, vals[0])
|
||||
|
@ -186,15 +186,15 @@ func (q *blockQuerier) selectSingle(m Matcher) Iterator {
|
|||
}
|
||||
|
||||
if len(res) == 0 {
|
||||
return errIterator{err: nil}
|
||||
return errPostings{err: nil}
|
||||
}
|
||||
|
||||
var rit []Iterator
|
||||
var rit []Postings
|
||||
|
||||
for _, v := range res {
|
||||
it, err := q.index.Postings(m.Name(), v)
|
||||
if err != nil {
|
||||
return errIterator{err: err}
|
||||
return errPostings{err: err}
|
||||
}
|
||||
rit = append(rit, it)
|
||||
}
|
||||
|
@ -379,7 +379,7 @@ func (s *shardSeriesSet) Next() bool {
|
|||
// blockSeriesSet is a set of series from an inverted index query.
|
||||
type blockSeriesSet struct {
|
||||
index IndexReader
|
||||
it Iterator
|
||||
it Postings
|
||||
|
||||
err error
|
||||
cur Series
|
||||
|
@ -655,7 +655,7 @@ func (r *sampleRing) last() (int64, float64, bool) {
|
|||
}
|
||||
|
||||
func (r *sampleRing) samples() []sample {
|
||||
res := make([]sample, 0, r.l)
|
||||
res := make([]sample, r.l)
|
||||
|
||||
var k = r.f + r.l
|
||||
var j int
|
||||
|
@ -664,12 +664,8 @@ func (r *sampleRing) samples() []sample {
|
|||
j = r.l - k + r.f
|
||||
}
|
||||
|
||||
for _, s := range r.buf[r.f:k] {
|
||||
res = append(res, s)
|
||||
}
|
||||
for _, s := range r.buf[:j] {
|
||||
res = append(res, s)
|
||||
}
|
||||
n := copy(res, r.buf[r.f:k])
|
||||
copy(res[n:], r.buf[:j])
|
||||
|
||||
return res
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ type IndexReader interface {
|
|||
LabelValues(names ...string) (StringTuples, error)
|
||||
|
||||
// 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(ref uint32) (Series, error)
|
||||
|
|
|
@ -25,6 +25,8 @@ func BenchmarkLabelMapAccess(b *testing.B) {
|
|||
}
|
||||
})
|
||||
}
|
||||
|
||||
_ = v
|
||||
}
|
||||
|
||||
func BenchmarkLabelSetAccess(b *testing.B) {
|
||||
|
@ -47,4 +49,6 @@ func BenchmarkLabelSetAccess(b *testing.B) {
|
|||
}
|
||||
})
|
||||
}
|
||||
|
||||
_ = v
|
||||
}
|
||||
|
|
|
@ -165,7 +165,7 @@ type IndexWriter interface {
|
|||
WriteLabelIndex(names []string, values []string) error
|
||||
|
||||
// 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() 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
|
||||
|
||||
w.postings = append(w.postings, hashEntry{
|
||||
|
|
Loading…
Reference in a new issue