Skip to content

Commit

Permalink
lightning: check counter value to make code more robust (#37380)
Browse files Browse the repository at this point in the history
ref #37338
  • Loading branch information
D3Hunter authored Aug 26, 2022
1 parent 8036777 commit b99aebe
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion br/pkg/lightning/restore/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -2330,7 +2330,16 @@ func (cr *chunkRestore) deliverLoop(
cr.chunk.Chunk.PrevRowIDMax = rowID

if m, ok := metric.FromContext(ctx); ok {
m.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 {
m.BytesCounter.WithLabelValues(metric.BytesStateRestored).Add(float64(currOffset - startOffset))
} else {
deliverLogger.Warn("offset go back", zap.Int64("curr", currOffset),
zap.Int64("start", startOffset))
}
}

if currOffset > lastOffset || dataChecksum.SumKVS() != 0 || indexChecksum.SumKVS() != 0 {
Expand Down

0 comments on commit b99aebe

Please sign in to comment.