Skip to content

Commit

Permalink
tikv: fix backoff stop early (#10809) (#10821)
Browse files Browse the repository at this point in the history
  • Loading branch information
lysu authored and jackysp committed Jun 18, 2019
1 parent b2578dc commit 3c2ee56
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion store/tikv/backoff.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func NewBackoffFn(base, cap, jitter int) func(ctx context.Context, maxSleepMs in
case <-time.After(time.Duration(realSleep) * time.Millisecond):
attempts++
lastSleep = sleep
return lastSleep
return realSleep
case <-ctx.Done():
return 0
}
Expand Down
42 changes: 42 additions & 0 deletions store/tikv/backoff_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright 2019 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.

package tikv

import (
"context"
"errors"
. "github.com/pingcap/check"
)

type testBackoffSuite struct {
OneByOneSuite
store *tikvStore
}

var _ = Suite(&testLockSuite{})

func (s *testBackoffSuite) SetUpTest(c *C) {
s.store = NewTestStore(c).(*tikvStore)
}

func (s *testBackoffSuite) TearDownTest(c *C) {
s.store.Close()
}

func (s *testBackoffSuite) TestBackoffWithMax(c *C) {
b := NewBackoffer(context.TODO(), 2000)
err := b.BackoffWithMaxSleep(boTxnLockFast, 30, errors.New("test"))
c.Assert(err, NotNil)
c.Assert(b.totalSleep, Equals, 30)
}

0 comments on commit 3c2ee56

Please sign in to comment.