From 4e4aa7cf2b94fb52dc8db494d7ee6c53b47cfdc3 Mon Sep 17 00:00:00 2001 From: Ben Ye Date: Wed, 7 Jun 2023 12:55:52 -0700 Subject: [PATCH] index stats: fix chunk size calculation Signed-off-by: Ben Ye --- pkg/block/index.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/block/index.go b/pkg/block/index.go index 0aa7a74a75..afbc9653d9 100644 --- a/pkg/block/index.go +++ b/pkg/block/index.go @@ -293,7 +293,12 @@ func GatherIndexHealthStats(logger log.Logger, fn string, minTime, maxTime int64 // Approximate size. if i < len(chks)-2 { - chunkSize.Add(int64(chks[i+1].Ref - c.Ref)) + sgmIndex, chkStart := chunks.BlockChunkRef(c.Ref).Unpack() + sgmIndex2, chkStart2 := chunks.BlockChunkRef(chks[i+1].Ref).Unpack() + // Skip the case where two chunks are spread into 2 files. + if sgmIndex == sgmIndex2 { + chunkSize.Add(int64(chkStart2 - chkStart)) + } } // Chunk vs the block ranges.