From 2581648f70912f6af93a162b543e76749ce29b4a Mon Sep 17 00:00:00 2001 From: beorn7 Date: Wed, 2 Mar 2016 13:45:17 +0100 Subject: [PATCH] Separate iterators by offset Add test that exposes the problem. --- promql/analyzer.go | 12 +++++++----- storage/local/chunk.go | 6 +++--- storage/local/interface.go | 2 +- storage/local/preload.go | 2 +- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/promql/analyzer.go b/promql/analyzer.go index 3bc46bb8f..6e052656d 100644 --- a/promql/analyzer.go +++ b/promql/analyzer.go @@ -125,8 +125,10 @@ func (a *Analyzer) Prepare(ctx context.Context) (local.Preloader, error) { }() // Preload all analyzed ranges. - iters := map[model.Fingerprint]local.SeriesIterator{} + iters := map[time.Duration]map[model.Fingerprint]local.SeriesIterator{} for offset, pt := range a.offsetPreloadTimes { + itersForDuration := map[model.Fingerprint]local.SeriesIterator{} + iters[offset] = itersForDuration start := a.Start.Add(-offset) end := a.End.Add(-offset) for fp, rangeDuration := range pt.ranges { @@ -148,7 +150,7 @@ func (a *Analyzer) Prepare(ctx context.Context) (local.Preloader, error) { if err != nil { return nil, err } - iters[fp] = iter + itersForDuration[fp] = iter } for fp := range pt.instants { if err = contextDone(ctx, env); err != nil { @@ -161,7 +163,7 @@ func (a *Analyzer) Prepare(ctx context.Context) (local.Preloader, error) { if err != nil { return nil, err } - iters[fp] = iter + itersForDuration[fp] = iter } } @@ -170,11 +172,11 @@ func (a *Analyzer) Prepare(ctx context.Context) (local.Preloader, error) { switch n := node.(type) { case *VectorSelector: for fp := range n.metrics { - n.iterators[fp] = iters[fp] + n.iterators[fp] = iters[n.Offset][fp] } case *MatrixSelector: for fp := range n.metrics { - n.iterators[fp] = iters[fp] + n.iterators[fp] = iters[n.Offset][fp] } } return true diff --git a/storage/local/chunk.go b/storage/local/chunk.go index ac54a5dc1..e0be10b14 100644 --- a/storage/local/chunk.go +++ b/storage/local/chunk.go @@ -54,7 +54,7 @@ const ( ) // chunkDesc contains meta-data for a chunk. Pay special attention to the -// documented requirements for calling its method concurrently (WRT pinning and +// documented requirements for calling its methods concurrently (WRT pinning and // locking). The doc comments spell out the requirements for each method, but // here is an overview and general explanation: // @@ -71,7 +71,7 @@ const ( // or creation) or by locking the fingerprint of the series the chunkDesc // belongs to. The affected methods are: add, maybePopulateLastTime, setChunk. // -// Finally, there is the special cases firstTime and lastTime. lastTime requires +// Finally, there are the special cases firstTime and lastTime. lastTime requires // to have locked the fingerprint of the series but the chunk does not need to // be pinned. That's because the chunkLastTime field in chunkDesc gets populated // upon completion of the chunk (when it is still pinned, and which happens @@ -292,7 +292,7 @@ type chunkIterator interface { // Gets the last sample value in the chunk. lastSampleValue() model.SampleValue // Gets the value that is closest before the given time. In case a value - // exist at precisely the given time, that value is returned. If no + // exists at precisely the given time, that value is returned. If no // applicable value exists, a SamplePair with timestamp model.Earliest // and value 0.0 is returned. valueAtOrBeforeTime(model.Time) model.SamplePair diff --git a/storage/local/interface.go b/storage/local/interface.go index a62a13b19..005b39726 100644 --- a/storage/local/interface.go +++ b/storage/local/interface.go @@ -72,7 +72,7 @@ type Storage interface { // of the series prior the modification. type SeriesIterator interface { // Gets the value that is closest before the given time. In case a value - // exist at precisely the given time, that value is returned. If no + // exists at precisely the given time, that value is returned. If no // applicable value exists, a SamplePair with timestamp model.Earliest // and value 0.0 is returned. ValueAtOrBeforeTime(model.Time) model.SamplePair diff --git a/storage/local/preload.go b/storage/local/preload.go index cda04a864..08a88875f 100644 --- a/storage/local/preload.go +++ b/storage/local/preload.go @@ -28,7 +28,7 @@ func (p *memorySeriesPreloader) PreloadRange( ) (SeriesIterator, error) { cds, iter, err := p.storage.preloadChunksForRange(fp, from, through) if err != nil { - return iter, err + return nil, err } p.pinnedChunkDescs = append(p.pinnedChunkDescs, cds...) return iter, nil