From 681c940eb3838f125b859909fb71cf7830de348b Mon Sep 17 00:00:00 2001 From: WangXiangUSTC Date: Mon, 30 Sep 2019 16:56:28 +0800 Subject: [PATCH] pump.Storage: fix possible panic if start ts is greater than max commit ts when pull binlog --- pump/storage/storage.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/pump/storage/storage.go b/pump/storage/storage.go index 77d1bffa7..a50ee5ea7 100644 --- a/pump/storage/storage.go +++ b/pump/storage/storage.go @@ -1014,14 +1014,28 @@ func (a *Append) PullCommitBinlog(ctx context.Context, last int64) <-chan []byte Limit: encodeTSKey(math.MaxInt64), } + pLog := pkgutil.NewLog() + labelWrongRange := "wrong range" + pLog.Add(labelWrongRange, 10*time.Second) + go func() { defer close(values) for { startTS := last + 1 + limitTS := atomic.LoadInt64(&a.maxCommitTS) + 1 + if startTS > limitTS { + // if range's start is greater than limit, may cause panic, see https://github.com/syndtr/goleveldb/issues/224 for detail. + pLog.Print(labelWrongRange, func() { + log.Warnf("last ts %d is greater than pump's max commit ts %d", startTS-1, limitTS-1) + }) + time.Sleep(time.Second) + continue + } + irange.Start = encodeTSKey(startTS) - irange.Limit = encodeTSKey(atomic.LoadInt64(&a.maxCommitTS) + 1) + irange.Limit = encodeTSKey(limitTS) iter := a.metadata.NewIterator(irange, nil) // log.Debugf("try to get range [%d,%d)", startTS, atomic.LoadInt64(&a.maxCommitTS)+1)