Fix iterator behavior in view.GetSampleAtTime()

This commit is contained in:
Julius Volz 2013-03-16 01:26:56 -07:00 committed by Matt T. Proud
parent bb9c5ed7aa
commit 4e7db57e76

View file

@ -126,18 +126,22 @@ func (v view) Close() {
} }
func (v view) GetValueAtTime(f model.Fingerprint, t time.Time) (s []model.SamplePair) { func (v view) GetValueAtTime(f model.Fingerprint, t time.Time) (s []model.SamplePair) {
var ( series, ok := v.fingerprintToSeries[f]
series, ok = v.fingerprintToSeries[f]
)
if !ok { if !ok {
return return
} }
var ( iterator := series.values.Seek(skipListTime(t))
iterator = series.values.Seek(skipListTime(t))
)
if iterator == nil { if iterator == nil {
return // If the iterator is nil, it means we seeked past the end of the series,
// so we seek to the last value instead. Due to the reverse ordering
// defined on skipListTime, this corresponds to the sample with the
// earliest timestamp.
iterator = series.values.SeekToLast()
if iterator == nil {
// The list is empty.
return
}
} }
defer iterator.Close() defer iterator.Close()