Fix accidental publishing of memorySeries.firstTime()

This commit is contained in:
Julius Volz 2016-09-26 13:06:06 +02:00
parent ab80ced756
commit d30a3c7c0f
3 changed files with 8 additions and 8 deletions

View file

@ -288,7 +288,7 @@ func (s *memorySeries) maybeCloseHeadChunk() bool {
func (s *memorySeries) evictChunkDescs(iOldestNotEvicted int) {
lenToKeep := chunkDescEvictionFactor * (len(s.chunkDescs) - iOldestNotEvicted)
if lenToKeep < len(s.chunkDescs) {
s.savedFirstTime = s.FirstTime()
s.savedFirstTime = s.firstTime()
lenEvicted := len(s.chunkDescs) - lenToKeep
s.chunkDescsOffset += lenEvicted
s.persistWatermark -= lenEvicted
@ -514,7 +514,7 @@ func (s *memorySeries) head() *chunk.Desc {
// firstTime returns the timestamp of the first sample in the series.
//
// The caller must have locked the fingerprint of the memorySeries.
func (s *memorySeries) FirstTime() model.Time {
func (s *memorySeries) firstTime() model.Time {
if s.chunkDescsOffset == 0 && len(s.chunkDescs) > 0 {
return s.chunkDescs[0].FirstTime()
}

View file

@ -657,7 +657,7 @@ func (s *MemorySeriesStorage) metricForRange(
) (model.Metric, *memorySeries, bool) {
series, ok := s.fpToSeries.get(fp)
if ok {
if series.lastTime.Before(from) || series.FirstTime().After(through) {
if series.lastTime.Before(from) || series.firstTime().After(through) {
return nil, nil, false
}
return series.metric, series, true
@ -1264,7 +1264,7 @@ func (s *MemorySeriesStorage) maintainMemorySeries(
if iOldestNotEvicted == -1 && model.Now().Sub(series.lastTime) > headChunkTimeout {
s.fpToSeries.del(fp)
s.numSeries.Dec()
s.persistence.archiveMetric(fp, series.metric, series.FirstTime(), series.lastTime)
s.persistence.archiveMetric(fp, series.metric, series.firstTime(), series.lastTime)
s.seriesOps.WithLabelValues(archive).Inc()
oldWatermark := atomic.LoadInt64((*int64)(&s.archiveHighWatermark))
if oldWatermark < int64(series.lastTime) {
@ -1325,7 +1325,7 @@ func (s *MemorySeriesStorage) writeMemorySeries(
chunks[i] = cd.C
}
if !series.FirstTime().Before(beforeTime) {
if !series.firstTime().Before(beforeTime) {
// Oldest sample not old enough, just append chunks, if any.
if len(cds) == 0 {
return false

View file

@ -69,7 +69,7 @@ func TestMatches(t *testing.T) {
t.Fatal("could not retrieve series for fp", fp)
}
storage.fpLocker.Lock(fp)
storage.persistence.archiveMetric(fp, s.metric, s.FirstTime(), s.lastTime)
storage.persistence.archiveMetric(fp, s.metric, s.firstTime(), s.lastTime)
storage.fpLocker.Unlock(fp)
}
@ -1276,7 +1276,7 @@ func testEvictAndPurgeSeries(t *testing.T, encoding chunk.Encoding) {
if err != nil {
t.Fatal(err)
}
s.persistence.archiveMetric(fp, series.metric, series.FirstTime(), lastTime)
s.persistence.archiveMetric(fp, series.metric, series.firstTime(), lastTime)
archived, _, _ := s.persistence.hasArchivedMetric(fp)
if !archived {
t.Fatal("not archived")
@ -1317,7 +1317,7 @@ func testEvictAndPurgeSeries(t *testing.T, encoding chunk.Encoding) {
if err != nil {
t.Fatal(err)
}
s.persistence.archiveMetric(fp, series.metric, series.FirstTime(), lastTime)
s.persistence.archiveMetric(fp, series.metric, series.firstTime(), lastTime)
archived, _, _ = s.persistence.hasArchivedMetric(fp)
if !archived {
t.Fatal("not archived")