From f8111cef0ecf6e778a15406a622687f8099c947d Mon Sep 17 00:00:00 2001 From: Fabian Reinartz Date: Mon, 26 Dec 2016 16:55:44 +0100 Subject: [PATCH] Fix chunk series iterator seeking --- db.go | 8 +++++--- querier.go | 16 +++++++++------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/db.go b/db.go index 90d944f23..e04bdd3c2 100644 --- a/db.go +++ b/db.go @@ -22,12 +22,14 @@ import ( // DefaultOptions used for the DB. They are sane for setups using // millisecond precision timestamps. var DefaultOptions = &Options{ - Retention: 15 * 24 * 3600 * 1000, // 15 days + Retention: 15 * 24 * 3600 * 1000, // 15 days + DisableWAL: false, } // Options of the DB storage. type Options struct { - Retention int64 + Retention int64 + DisableWAL bool } // DB is a time series storage. @@ -41,7 +43,7 @@ type DB struct { // TODO(fabxc): make configurable const ( - shardShift = 3 + shardShift = 0 numShards = 1 << shardShift maxChunkSize = 1024 ) diff --git a/querier.go b/querier.go index 4c6a877de..f92e3d1ae 100644 --- a/querier.go +++ b/querier.go @@ -72,7 +72,6 @@ func (q *querier) Select(ms ...labels.Matcher) SeriesSet { } func (q *querier) LabelValues(n string) ([]string, error) { - // TODO(fabxc): return returned merged result. res, err := q.shards[0].LabelValues(n) if err != nil { return nil, err @@ -570,15 +569,18 @@ func newChunkSeriesIterator(mints []int64, cs []chunks.Chunk) *chunkSeriesIterat } 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) { - return false + x-- } - if it.mints[x] == t { - if x == 0 { - return false - } + // Go to previous chunk if the chunk doesn't exactly start with t. + // If we are already at the first chunk, we use it as it's the best we have. + if x > 0 && it.mints[x] > t { x-- }