storage: Simplify evictChunkDesc method

This commit is contained in:
beorn7 2017-02-04 22:29:37 +01:00
parent 65dc8f44d3
commit 31e9db7f0c

View file

@ -277,24 +277,23 @@ func (s *memorySeries) maybeCloseHeadChunk() (bool, error) {
return false, nil return false, nil
} }
// evictChunkDescs evicts chunkDescs if the chunk is evicted. // evictChunkDescs evicts chunkDescs. lenToEvict is the index within the current
// iOldestNotEvicted is the index within the current chunkDescs of the oldest // chunkDescs of the oldest chunk that is not evicted.
// chunk that is not evicted. func (s *memorySeries) evictChunkDescs(lenToEvict int) {
func (s *memorySeries) evictChunkDescs(iOldestNotEvicted int) { if lenToEvict < 1 {
lenToKeep := len(s.chunkDescs) - iOldestNotEvicted return
if lenToKeep < len(s.chunkDescs) { }
lenToKeep := len(s.chunkDescs) - lenToEvict
s.savedFirstTime = s.firstTime() s.savedFirstTime = s.firstTime()
lenEvicted := len(s.chunkDescs) - lenToKeep s.chunkDescsOffset += lenToEvict
s.chunkDescsOffset += lenEvicted s.persistWatermark -= lenToEvict
s.persistWatermark -= lenEvicted chunk.DescOps.WithLabelValues(chunk.Evict).Add(float64(lenToEvict))
chunk.DescOps.WithLabelValues(chunk.Evict).Add(float64(lenEvicted)) chunk.NumMemDescs.Sub(float64(lenToEvict))
chunk.NumMemDescs.Sub(float64(lenEvicted))
s.chunkDescs = append( s.chunkDescs = append(
make([]*chunk.Desc, 0, lenToKeep), make([]*chunk.Desc, 0, lenToKeep),
s.chunkDescs[lenEvicted:]..., s.chunkDescs[lenToEvict:]...,
) )
s.dirty = true s.dirty = true
}
} }
// dropChunks removes chunkDescs older than t. The caller must have locked the // dropChunks removes chunkDescs older than t. The caller must have locked the