diff --git a/executor/calibrate_resource.go b/executor/calibrate_resource.go index afa8dd587f281..a9a1f05b3e1be 100644 --- a/executor/calibrate_resource.go +++ b/executor/calibrate_resource.go @@ -168,10 +168,12 @@ func (e *calibrateResourceExec) parseCalibrateDuration(ctx context.Context) (sta } // check the duration dur = endTime.Sub(startTime) - if dur > maxDuration { + // add the buffer duration + if dur > maxDuration+time.Minute { err = errors.Errorf("the duration of calibration is too long, which could lead to inaccurate output. Please make the duration between %s and %s", minDuration.String(), maxDuration.String()) return } + // We only need to consider the case where the duration is slightly enlarged. if dur < minDuration { err = errors.Errorf("the duration of calibration is too short, which could lead to inaccurate output. Please make the duration between %s and %s", minDuration.String(), maxDuration.String()) } diff --git a/executor/calibrate_resource_test.go b/executor/calibrate_resource_test.go index 3aa85aa4b42d7..51380e0a29013 100644 --- a/executor/calibrate_resource_test.go +++ b/executor/calibrate_resource_test.go @@ -527,7 +527,7 @@ func TestCalibrateResource(t *testing.T) { types.MakeDatums(datetime("2020-02-12 10:45:00"), "tikv-2", "tikv", 0.281), } - rs, err = tk.Exec("CALIBRATE RESOURCE START_TIME '2020-02-12 10:35:00' END_TIME '2020-02-12 10:45:00'") + rs, err = tk.Exec("CALIBRATE RESOURCE START_TIME '2020-02-12 10:35:00' END_TIME '2020-02-13 10:35:01'") require.NoError(t, err) require.NotNil(t, rs) err = rs.Next(ctx, rs.NewChunk(nil))