mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
Fix chunk series iterator seeking
This commit is contained in:
parent
201d7687b6
commit
f8111cef0e
8
db.go
8
db.go
|
@ -22,12 +22,14 @@ import (
|
||||||
// DefaultOptions used for the DB. They are sane for setups using
|
// DefaultOptions used for the DB. They are sane for setups using
|
||||||
// millisecond precision timestamps.
|
// millisecond precision timestamps.
|
||||||
var DefaultOptions = &Options{
|
var DefaultOptions = &Options{
|
||||||
Retention: 15 * 24 * 3600 * 1000, // 15 days
|
Retention: 15 * 24 * 3600 * 1000, // 15 days
|
||||||
|
DisableWAL: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Options of the DB storage.
|
// Options of the DB storage.
|
||||||
type Options struct {
|
type Options struct {
|
||||||
Retention int64
|
Retention int64
|
||||||
|
DisableWAL bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// DB is a time series storage.
|
// DB is a time series storage.
|
||||||
|
@ -41,7 +43,7 @@ type DB struct {
|
||||||
|
|
||||||
// TODO(fabxc): make configurable
|
// TODO(fabxc): make configurable
|
||||||
const (
|
const (
|
||||||
shardShift = 3
|
shardShift = 0
|
||||||
numShards = 1 << shardShift
|
numShards = 1 << shardShift
|
||||||
maxChunkSize = 1024
|
maxChunkSize = 1024
|
||||||
)
|
)
|
||||||
|
|
16
querier.go
16
querier.go
|
@ -72,7 +72,6 @@ func (q *querier) Select(ms ...labels.Matcher) SeriesSet {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *querier) LabelValues(n string) ([]string, error) {
|
func (q *querier) LabelValues(n string) ([]string, error) {
|
||||||
// TODO(fabxc): return returned merged result.
|
|
||||||
res, err := q.shards[0].LabelValues(n)
|
res, err := q.shards[0].LabelValues(n)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -570,15 +569,18 @@ func newChunkSeriesIterator(mints []int64, cs []chunks.Chunk) *chunkSeriesIterat
|
||||||
}
|
}
|
||||||
|
|
||||||
func (it *chunkSeriesIterator) Seek(t int64) (ok bool) {
|
func (it *chunkSeriesIterator) Seek(t int64) (ok bool) {
|
||||||
x := sort.Search(len(it.mints), func(i int) bool { return it.mints[i] >= t })
|
// Only do binary search forward to stay in line with other iterators
|
||||||
|
// that can only move forward.
|
||||||
|
x := sort.Search(len(it.mints[it.i:]), func(i int) bool { return it.mints[i] >= t })
|
||||||
|
x += it.i
|
||||||
|
|
||||||
|
// If the timestamp was not found, it might be in the last chunk.
|
||||||
if x == len(it.mints) {
|
if x == len(it.mints) {
|
||||||
return false
|
x--
|
||||||
}
|
}
|
||||||
if it.mints[x] == t {
|
// Go to previous chunk if the chunk doesn't exactly start with t.
|
||||||
if x == 0 {
|
// If we are already at the first chunk, we use it as it's the best we have.
|
||||||
return false
|
if x > 0 && it.mints[x] > t {
|
||||||
}
|
|
||||||
x--
|
x--
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue