Merge pull request #678 from pingcap/shenli/change-retry-backoff-unit

kv: Change backoff time from Microseconds to Milliseconds
This commit is contained in:
Shen Li
2015-12-05 21:27:28 +08:00
2 changed files with 4 additions and 2 deletions

View File

@ -92,7 +92,7 @@ var (
// See: http://www.awsarchitectureblog.com/2015/03/backoff.html.
func BackOff(attempts int) int {
upper := int(math.Min(float64(retryBackOffCap), float64(retryBackOffBase)*math.Pow(2.0, float64(attempts))))
sleep := time.Duration(rand.Intn(upper)) * time.Microsecond
sleep := time.Duration(rand.Intn(upper)) * time.Millisecond
time.Sleep(sleep)
return int(sleep)
}

View File

@ -14,6 +14,8 @@
package kv
import (
"time"
. "github.com/pingcap/check"
)
@ -36,5 +38,5 @@ func (s *testTxnSuite) TestBackOff(c *C) {
}
func mustBackOff(c *C, cnt, sleep int) {
c.Assert(BackOff(cnt), LessEqual, sleep*1000)
c.Assert(BackOff(cnt), LessEqual, sleep*int(time.Millisecond))
}