From 427c8d53a56c75b87aaa6631cf87f9013a6f1d37 Mon Sep 17 00:00:00 2001 From: Bjoern Rabenstein Date: Tue, 14 Oct 2014 18:23:32 +0200 Subject: [PATCH] Fix handling of empty chunkDescs while preloading chunks. Change-Id: I73ce89fe0ef90c6eda78218e5be2cbfa0207c364 --- storage/local/series.go | 27 +++++++++++++-------------- storage/local/storage.go | 2 +- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/storage/local/series.go b/storage/local/series.go index 1481eb51a7..7d9d8cbcda 100644 --- a/storage/local/series.go +++ b/storage/local/series.go @@ -431,24 +431,23 @@ func (s *memorySeries) preloadChunksAtTime(t clientmodel.Timestamp, p *persisten } */ -// loadChunkDescs is an internal helper method. -func (s *memorySeries) loadChunkDescs(p *persistence) error { - cds, err := p.loadChunkDescs(s.metric.Fingerprint(), s.chunkDescs[0].firstTime()) - if err != nil { - return err - } - s.chunkDescs = append(cds, s.chunkDescs...) - s.chunkDescsLoaded = true - return nil -} - // preloadChunksForRange loads chunks for the given range from the persistence. // The caller must have locked the fingerprint of the series. -func (s *memorySeries) preloadChunksForRange(from clientmodel.Timestamp, through clientmodel.Timestamp, p *persistence) (chunkDescs, error) { - if !s.chunkDescsLoaded && (len(s.chunkDescs) == 0 || from.Before(s.chunkDescs[0].firstTime())) { - if err := s.loadChunkDescs(p); err != nil { +func (s *memorySeries) preloadChunksForRange( + from clientmodel.Timestamp, through clientmodel.Timestamp, + fp clientmodel.Fingerprint, p *persistence, +) (chunkDescs, error) { + firstChunkDescTime := through + if len(s.chunkDescs) > 0 { + firstChunkDescTime = s.chunkDescs[0].firstTime() + } + if !s.chunkDescsLoaded && from.Before(firstChunkDescTime) { + cds, err := p.loadChunkDescs(fp, firstChunkDescTime) + if err != nil { return nil, err } + s.chunkDescs = append(cds, s.chunkDescs...) + s.chunkDescsLoaded = true } if len(s.chunkDescs) == 0 { diff --git a/storage/local/storage.go b/storage/local/storage.go index 60a58d7260..80b49f3078 100644 --- a/storage/local/storage.go +++ b/storage/local/storage.go @@ -175,7 +175,7 @@ func (s *memorySeriesStorage) preloadChunksForRange(fp clientmodel.Fingerprint, return nil, nil } } - return series.preloadChunksForRange(from, through, s.persistence) + return series.preloadChunksForRange(from, through, fp, s.persistence) } // NewIterator implements storage.