mirror of
https://github.com/prometheus/prometheus.git
synced 2025-02-02 08:31:11 -08:00
parent
f85d89abc0
commit
efb0dfe1be
17
index.go
17
index.go
|
@ -698,20 +698,11 @@ func (r *indexReader) Postings(name, value string) (Postings, error) {
|
||||||
return nil, errors.Wrapf(errInvalidFlag, "section at %d", off)
|
return nil, errors.Wrapf(errInvalidFlag, "section at %d", off)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(fabxc): just read into memory as an intermediate solution.
|
// Add iterator over the bytes.
|
||||||
// Add iterator over serialized data.
|
if len(b)%4 != 0 {
|
||||||
var l []uint32
|
return nil, errors.Wrap(errInvalidSize, "plain postings entry")
|
||||||
|
|
||||||
for len(b) > 0 {
|
|
||||||
if len(b) < 4 {
|
|
||||||
return nil, errors.Wrap(errInvalidSize, "plain postings entry")
|
|
||||||
}
|
|
||||||
l = append(l, binary.BigEndian.Uint32(b[:4]))
|
|
||||||
|
|
||||||
b = b[4:]
|
|
||||||
}
|
}
|
||||||
|
return newBytePostings(b), nil
|
||||||
return &listPostings{list: l, idx: -1}, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type stringTuples struct {
|
type stringTuples struct {
|
||||||
|
|
35
postings.go
35
postings.go
|
@ -1,6 +1,7 @@
|
||||||
package tsdb
|
package tsdb
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/binary"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
@ -240,6 +241,40 @@ func (it *listPostings) Err() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type bytePostings struct {
|
||||||
|
list []byte
|
||||||
|
idx int
|
||||||
|
}
|
||||||
|
|
||||||
|
func newBytePostings(list []byte) *bytePostings {
|
||||||
|
return &bytePostings{list: list, idx: -1}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (it *bytePostings) At() uint32 {
|
||||||
|
idx := 4 * it.idx
|
||||||
|
return binary.BigEndian.Uint32(it.list[idx : idx+4])
|
||||||
|
}
|
||||||
|
|
||||||
|
func (it *bytePostings) Next() bool {
|
||||||
|
it.idx++
|
||||||
|
return it.idx*4 < len(it.list)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (it *bytePostings) Seek(x uint32) bool {
|
||||||
|
num := len(it.list) / 4
|
||||||
|
// Do binary search between current position and end.
|
||||||
|
it.idx += sort.Search(num-it.idx, func(i int) bool {
|
||||||
|
idx := 4 * (it.idx + i)
|
||||||
|
val := binary.BigEndian.Uint32(it.list[idx : idx+4])
|
||||||
|
return val >= x
|
||||||
|
})
|
||||||
|
return it.idx*4 < len(it.list)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (it *bytePostings) Err() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
type stringset map[string]struct{}
|
type stringset map[string]struct{}
|
||||||
|
|
||||||
func (ss stringset) set(s string) {
|
func (ss stringset) set(s string) {
|
||||||
|
|
Loading…
Reference in a new issue