mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2025-01-20 23:39:48 +01:00
lib/storage: do not change timestamps to constant rate if values are constant or have constant delta
This breaks the original timestamps, which results in issues like https://github.com/VictoriaMetrics/VictoriaMetrics/issues/120 and https://github.com/VictoriaMetrics/VictoriaMetrics/issues/141 .
This commit is contained in:
parent
f56c1298ad
commit
4fb635b0c9
@ -205,19 +205,6 @@ func (b *Block) MarshalData(timestampsBlockOffset, valuesBlockOffset uint64) ([]
|
|||||||
b.bh.ValuesBlockSize = uint32(len(b.valuesData))
|
b.bh.ValuesBlockSize = uint32(len(b.valuesData))
|
||||||
b.values = b.values[:0]
|
b.values = b.values[:0]
|
||||||
|
|
||||||
if len(timestamps) > 1 && (b.bh.ValuesMarshalType == encoding.MarshalTypeConst || b.bh.ValuesMarshalType == encoding.MarshalTypeDeltaConst) {
|
|
||||||
// Special case - values are constant or are changed with constant rate.
|
|
||||||
// In this case we may 'cheat' by assuming timestamps are changed
|
|
||||||
// at ideal constant rate. This improves timestamps' compression rate.
|
|
||||||
minTimestamp := timestamps[0]
|
|
||||||
maxTimestamp := timestamps[len(timestamps)-1]
|
|
||||||
delta := (maxTimestamp - minTimestamp) / int64(len(timestamps)-1)
|
|
||||||
ts := minTimestamp
|
|
||||||
for i := 1; i < len(timestamps); i++ {
|
|
||||||
ts += delta
|
|
||||||
timestamps[i] = ts
|
|
||||||
}
|
|
||||||
}
|
|
||||||
b.timestampsData, b.bh.TimestampsMarshalType, b.bh.MinTimestamp = encoding.MarshalTimestamps(b.timestampsData[:0], timestamps, b.bh.PrecisionBits)
|
b.timestampsData, b.bh.TimestampsMarshalType, b.bh.MinTimestamp = encoding.MarshalTimestamps(b.timestampsData[:0], timestamps, b.bh.PrecisionBits)
|
||||||
b.bh.TimestampsBlockOffset = timestampsBlockOffset
|
b.bh.TimestampsBlockOffset = timestampsBlockOffset
|
||||||
b.bh.TimestampsBlockSize = uint32(len(b.timestampsData))
|
b.bh.TimestampsBlockSize = uint32(len(b.timestampsData))
|
||||||
|
Loading…
Reference in New Issue
Block a user