@ -845,12 +845,14 @@ func (p *persistence) loadSeriesMapAndHeads() (sm *seriesMap, chunksToPersist in
// dropAndPersistChunks deletes all chunks from a series file whose last sample
// dropAndPersistChunks deletes all chunks from a series file whose last sample
// time is before beforeTime, and then appends the provided chunks, leaving out
// time is before beforeTime, and then appends the provided chunks, leaving out
// those whose last sample time is before beforeTime. It returns the timestamp
// those whose last sample time is before beforeTime. It returns the timestamp
// of the first sample in the oldest chunk _not_ dropped, the offset within the
// of the first sample in the oldest chunk _not_ dropped, the chunk offset
// series file of the first chunk persisted (out of the provided chunks), the
// within the series file of the first chunk persisted (out of the provided
// number of deleted chunks, and true if all chunks of the series have been
// chunks, or - if no chunks were provided - the chunk offset where chunks would
// deleted (in which case the returned timestamp will be 0 and must be ignored).
// have been persisted, i.e. the end of the file), the number of deleted chunks,
// It is the caller's responsibility to make sure nothing is persisted or loaded
// and true if all chunks of the series have been deleted (in which case the
// for the same fingerprint concurrently.
// returned timestamp will be 0 and must be ignored). It is the caller's
// responsibility to make sure nothing is persisted or loaded for the same
// fingerprint concurrently.
//
//
// Returning an error signals problems with the series file. In this case, the
// Returning an error signals problems with the series file. In this case, the
// caller should quarantine the series.
// caller should quarantine the series.
@ -966,13 +968,16 @@ func (p *persistence) dropAndPersistChunks(
if err != nil {
if err != nil {
return
return
}
}
totalChunks := int ( fi . Size ( ) ) / chunkLenWithHeader + len ( chunks )
chunksInFile := int ( fi . Size ( ) ) / chunkLenWithHeader
totalChunks := chunksInFile + len ( chunks )
if numDropped == 0 || float64 ( numDropped ) / float64 ( totalChunks ) < p . minShrinkRatio {
if numDropped == 0 || float64 ( numDropped ) / float64 ( totalChunks ) < p . minShrinkRatio {
// Nothing to drop. Just adjust the return values and append the chunks (if any).
// Nothing to drop. Just adjust the return values and append the chunks (if any).
numDropped = 0
numDropped = 0
firstTimeNotDropped = firstTimeInFile
firstTimeNotDropped = firstTimeInFile
if len ( chunks ) > 0 {
if len ( chunks ) > 0 {
offset , err = p . persistChunks ( fp , chunks )
offset , err = p . persistChunks ( fp , chunks )
} else {
offset = chunksInFile
}
}
return
return
}
}