From 9e0f6ab92f954060d80742d4db37cbe1d845fd12 Mon Sep 17 00:00:00 2001 From: disksing Date: Wed, 27 Jan 2021 04:28:43 +0800 Subject: [PATCH 1/2] store/tikv: remove use of fastrand Signed-off-by: disksing --- store/tikv/backoff.go | 8 ++++---- store/tikv/kv.go | 3 +-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/store/tikv/backoff.go b/store/tikv/backoff.go index 256322641f1e7..1b0389140219a 100644 --- a/store/tikv/backoff.go +++ b/store/tikv/backoff.go @@ -17,6 +17,7 @@ import ( "context" "fmt" "math" + "math/rand" "strings" "sync/atomic" "time" @@ -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" @@ -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(int(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), diff --git a/store/tikv/kv.go b/store/tikv/kv.go index de05e05840395..1d4b78cee6541 100644 --- a/store/tikv/kv.go +++ b/store/tikv/kv.go @@ -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" @@ -213,7 +212,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) From 8ccb51bfabb2e5cdcd98938844b9d4777ab73436 Mon Sep 17 00:00:00 2001 From: disksing Date: Wed, 27 Jan 2021 04:36:26 +0800 Subject: [PATCH 2/2] fix lint Signed-off-by: disksing --- store/tikv/backoff.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/store/tikv/backoff.go b/store/tikv/backoff.go index 1b0389140219a..f3830c4d99f33 100644 --- a/store/tikv/backoff.go +++ b/store/tikv/backoff.go @@ -94,7 +94,7 @@ 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 = rand.Intn(int(v)) + sleep = rand.Intn(v) case EqualJitter: v := expo(base, cap, attempts) sleep = v/2 + rand.Intn(v/2)