mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
lib/storage: validate timestamps in the block only if they use encoding, which needs validation
This reduces CPU usage when there is no sense in validating timestamps.
This is a follow-up for 5fa9525498
Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/2998
Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3011
This commit is contained in:
parent
3f5959c053
commit
99d67ac8ad
2 changed files with 15 additions and 1 deletions
|
@ -42,6 +42,20 @@ const (
|
|||
MarshalTypeNearestDelta = MarshalType(6)
|
||||
)
|
||||
|
||||
// NeedsValidation returns true if mt may need additional validation for silent data corruption.
|
||||
func (mt MarshalType) NeedsValidation() bool {
|
||||
switch mt {
|
||||
case MarshalTypeNearestDelta2,
|
||||
MarshalTypeNearestDelta:
|
||||
return true
|
||||
default:
|
||||
// Other types do not need additional validation,
|
||||
// since they either already contain checksums (e.g. compressed data)
|
||||
// or they are trivial and cannot be validated (e.g. const or delta const)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// CheckMarshalType verifies whether the mt is valid.
|
||||
func CheckMarshalType(mt MarshalType) error {
|
||||
if mt < 0 || mt > 6 {
|
||||
|
|
|
@ -271,7 +271,7 @@ func (b *Block) UnmarshalData() error {
|
|||
if b.bh.PrecisionBits < 64 {
|
||||
// Recover timestamps order after lossy compression.
|
||||
encoding.EnsureNonDecreasingSequence(b.timestamps, b.bh.MinTimestamp, b.bh.MaxTimestamp)
|
||||
} else {
|
||||
} else if b.bh.TimestampsMarshalType.NeedsValidation() {
|
||||
// Ensure timestamps are in the range [MinTimestamp ... MaxTimestamps] and are ordered.
|
||||
if err := checkTimestampsBounds(b.timestamps, b.bh.MinTimestamp, b.bh.MaxTimestamp); err != nil {
|
||||
return err
|
||||
|
|
Loading…
Reference in a new issue