Skip to content

Commit

Permalink
lightning: check counter value to make code more robust (#37380) (#37398
Browse files Browse the repository at this point in the history
)

ref #37338
  • Loading branch information
ti-srebot authored Sep 8, 2022
1 parent 2d925f4 commit ec2e605
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion br/pkg/lightning/restore/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -2252,7 +2252,13 @@ func (cr *chunkRestore) deliverLoop(
cr.chunk.Chunk.Offset = currOffset
cr.chunk.Chunk.PrevRowIDMax = rowID

metric.BytesCounter.WithLabelValues(metric.BytesStateRestored).Add(float64(currOffset - startOffset))
// value of currOffset comes from parser.pos which increase monotonically. the init value of parser.pos
// comes from chunk.Chunk.Offset. so it shouldn't happen that currOffset - startOffset < 0.
// but we met it one time, but cannot reproduce it now, we add this check to make code more robust
// TODO: reproduce and find the root cause and fix it completely
if currOffset >= startOffset {
metric.BytesCounter.WithLabelValues(metric.BytesStateRestored).Add(float64(currOffset - startOffset))
}

if currOffset > lastOffset || dataChecksum.SumKVS() != 0 || indexChecksum.SumKVS() != 0 {
// No need to save checkpoint if nothing was delivered.
Expand Down

0 comments on commit ec2e605

Please sign in to comment.