Skip to content

Commit

Permalink
store/tikv: remove use of fastrand (#22543)
Browse files Browse the repository at this point in the history
Signed-off-by: disksing <i@disksing.com>
  • Loading branch information
disksing authored Jan 27, 2021
1 parent d92e62c commit 415d14b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
8 changes: 4 additions & 4 deletions store/tikv/backoff.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"context"
"fmt"
"math"
"math/rand"
"strings"
"sync/atomic"
"time"
Expand All @@ -27,7 +28,6 @@ import (
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/metrics"
"github.com/pingcap/tidb/util/execdetails"
"github.com/pingcap/tidb/util/fastrand"
"github.com/pingcap/tidb/util/logutil"
"github.com/prometheus/client_golang/prometheus"
"go.uber.org/zap"
Expand Down Expand Up @@ -94,12 +94,12 @@ func NewBackoffFn(base, cap, jitter int) func(ctx context.Context, maxSleepMs in
sleep = expo(base, cap, attempts)
case FullJitter:
v := expo(base, cap, attempts)
sleep = int(fastrand.Uint32N(uint32(v)))
sleep = rand.Intn(v)
case EqualJitter:
v := expo(base, cap, attempts)
sleep = v/2 + int(fastrand.Uint32N(uint32(v/2)))
sleep = v/2 + rand.Intn(v/2)
case DecorrJitter:
sleep = int(math.Min(float64(cap), float64(base+int(fastrand.Uint32N(uint32(lastSleep*3-base))))))
sleep = int(math.Min(float64(cap), float64(base+rand.Intn(lastSleep*3-base))))
}
logutil.BgLogger().Debug("backoff",
zap.Int("base", base),
Expand Down
3 changes: 1 addition & 2 deletions store/tikv/kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import (
"github.com/pingcap/tidb/store/tikv/oracle/oracles"
"github.com/pingcap/tidb/store/tikv/tikvrpc"
"github.com/pingcap/tidb/util/execdetails"
"github.com/pingcap/tidb/util/fastrand"
"github.com/pingcap/tidb/util/logutil"
pd "github.com/tikv/pd/client"
"go.etcd.io/etcd/clientv3"
Expand Down Expand Up @@ -212,7 +211,7 @@ func newTikvStore(uuid string, pdClient pd.Client, spkv SafePointKV, client Clie
safePoint: 0,
spTime: time.Now(),
closed: make(chan struct{}),
replicaReadSeed: fastrand.Uint32(),
replicaReadSeed: rand.Uint32(),
memCache: kv.NewCacheDB(),
}
store.lockResolver = newLockResolver(store)
Expand Down

0 comments on commit 415d14b

Please sign in to comment.