From 7b7cdfe495d2f3c743676846fbc5526ef404529e Mon Sep 17 00:00:00 2001 From: D3Hunter Date: Fri, 26 Aug 2022 11:36:21 +0800 Subject: [PATCH] cherry pick #37380 to release-6.1 Signed-off-by: ti-srebot --- br/pkg/lightning/restore/restore.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/br/pkg/lightning/restore/restore.go b/br/pkg/lightning/restore/restore.go index c776510ae3c9d..f7fa54d084222 100644 --- a/br/pkg/lightning/restore/restore.go +++ b/br/pkg/lightning/restore/restore.go @@ -2252,7 +2252,22 @@ func (cr *chunkRestore) deliverLoop( cr.chunk.Chunk.Offset = currOffset cr.chunk.Chunk.PrevRowIDMax = rowID +<<<<<<< HEAD metric.BytesCounter.WithLabelValues(metric.BytesStateRestored).Add(float64(currOffset - startOffset)) +======= + if m, ok := metric.FromContext(ctx); ok { + // 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)) + } + } +>>>>>>> b99aebee3... lightning: check counter value to make code more robust (#37380) if currOffset > lastOffset || dataChecksum.SumKVS() != 0 || indexChecksum.SumKVS() != 0 { // No need to save checkpoint if nothing was delivered.