lib/storage: do not append headerData to bsw.indexData if its size exceeds maxBlockSize

This is a follow-up optimization after 3c246cdf00
This commit is contained in:
Aliaksandr Valialkin 2024-02-12 18:03:19 +02:00
parent 7eb5c187b3
commit 2eb967231b
No known key found for this signature in database
GPG key ID: 52C003EE2BCDB9EB

View file

@ -135,6 +135,7 @@ func (bsw *blockStreamWriter) WriteExternalBlock(b *Block, ph *partHeader, rowsM
atomic.AddUint64(rowsMerged, uint64(b.rowsCount()))
b.deduplicateSamplesDuringMerge()
headerData, timestampsData, valuesData := b.MarshalData(bsw.timestampsBlockOffset, bsw.valuesBlockOffset)
usePrevTimestamps := len(bsw.prevTimestampsData) > 0 && bytes.Equal(timestampsData, bsw.prevTimestampsData)
if usePrevTimestamps {
// The current timestamps block equals to the previous timestamps block.
@ -143,14 +144,13 @@ func (bsw *blockStreamWriter) WriteExternalBlock(b *Block, ph *partHeader, rowsM
atomic.AddUint64(&timestampsBlocksMerged, 1)
atomic.AddUint64(&timestampsBytesSaved, uint64(len(timestampsData)))
}
indexDataLen := len(bsw.indexData)
bsw.indexData = append(bsw.indexData, headerData...)
if len(bsw.indexData) > maxBlockSize {
bsw.indexData = bsw.indexData[:indexDataLen]
if len(bsw.indexData)+len(headerData) > maxBlockSize {
bsw.flushIndexData()
bsw.indexData = append(bsw.indexData, headerData...)
}
bsw.indexData = append(bsw.indexData, headerData...)
bsw.mr.RegisterBlockHeader(&b.bh)
if !usePrevTimestamps {
bsw.prevTimestampsData = append(bsw.prevTimestampsData[:0], timestampsData...)
bsw.prevTimestampsBlockOffset = bsw.timestampsBlockOffset