fixbug: divided by zero

This commit is contained in:
chenxiaobin
2021-04-25 10:15:03 +08:00
parent b0d23d9d84
commit d1028fd621

View File

@ -5493,7 +5493,8 @@ static void CalCatchupRate() {
SpinLockRelease(&walsnd->mutex);
return;
}
if (TimestampDifferenceExceeds(walsnd->lastCalTime, now, CALCULATE_CATCHUP_RATE_TIME)) {
if (TimestampDifferenceExceeds(walsnd->lastCalTime, now, CALCULATE_CATCHUP_RATE_TIME) &&
XLByteLT(walsnd->lastCalWrite, write)) {
double tempRate = (double)(now - walsnd->lastCalTime) /
(double)XLByteDifference(write, walsnd->lastCalWrite);
walsnd->catchupRate = walsnd->catchupRate == 0 ? tempRate : (walsnd->catchupRate + tempRate) / 2;