lib/storage: verify that blocks in a single part are sorted by TSID when reading sequential blocks from the part

This may help narrowing down the issue https://github.com/VictoriaMetrics/VictoriaMetrics/issues/2082
This commit is contained in:
Aliaksandr Valialkin 2022-01-20 20:36:33 +02:00
parent ea87f21e23
commit 00b7c97d2a
No known key found for this signature in database
GPG key ID: A72BEC6CD3D0DED1

View file

@ -175,7 +175,7 @@ func (bsr *blockStreamReader) InitFromFilePart(path string) error {
timestampsFile.MustClose()
valuesFile.MustClose()
indexFile.MustClose()
return fmt.Errorf("cannot unmarshal metaindex rows from inmemoryPart: %w", err)
return fmt.Errorf("cannot unmarshal metaindex rows from file part %q: %w", metaindexPath, err)
}
bsr.path = path
@ -213,16 +213,19 @@ func (bsr *blockStreamReader) NextBlock() bool {
if bsr.err != nil {
return false
}
tsidPrev := bsr.Block.bh.TSID
bsr.Block.Reset()
err := bsr.readBlock()
if err == nil {
if bsr.Block.bh.RowsCount > 0 {
return true
if bsr.Block.bh.TSID.Less(&tsidPrev) {
bsr.err = fmt.Errorf("possible data corruption: the next TSID=%v is smaller than the previous TSID=%v", &bsr.Block.bh.TSID, &tsidPrev)
return false
}
bsr.err = fmt.Errorf("invalid block read with zero rows; block=%+v", &bsr.Block)
return false
if bsr.Block.bh.RowsCount == 0 {
bsr.err = fmt.Errorf("invalid block read with zero rows; block=%+v", &bsr.Block)
return false
}
return true
}
if err == io.EOF {
bsr.err = io.EOF