From 1e0aa22d719571bea0bdcf832b512f681f3325cb Mon Sep 17 00:00:00 2001 From: Aoang Date: Mon, 11 Mar 2024 20:56:04 +0800 Subject: [PATCH] Switch to use math/rand/v2.Uint32N and clean runtime.fastrand Signed-off-by: Aoang --- go/hack/runtime.go | 3 --- go/pools/smartconnpool/pool.go | 5 ++--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/go/hack/runtime.go b/go/hack/runtime.go index 83428504818..74bce583a84 100644 --- a/go/hack/runtime.go +++ b/go/hack/runtime.go @@ -46,6 +46,3 @@ func Atof64(s string) (float64, int, error) //go:linkname Atof32 strconv.atof32 func Atof32(s string) (float32, int, error) - -//go:linkname FastRand runtime.fastrand -func FastRand() uint32 diff --git a/go/pools/smartconnpool/pool.go b/go/pools/smartconnpool/pool.go index 7c10d6ba4b0..a4317dc8447 100644 --- a/go/pools/smartconnpool/pool.go +++ b/go/pools/smartconnpool/pool.go @@ -18,12 +18,12 @@ package smartconnpool import ( "context" + "math/rand/v2" "slices" "sync" "sync/atomic" "time" - "vitess.io/vitess/go/hack" "vitess.io/vitess/go/vt/log" vtrpcpb "vitess.io/vitess/go/vt/proto/vtrpc" "vitess.io/vitess/go/vt/servenv" @@ -373,8 +373,7 @@ func (pool *ConnPool[D]) extendedMaxLifetime() time.Duration { if maxLifetime == 0 { return 0 } - extended := hack.FastRand() % uint32(maxLifetime) - return time.Duration(maxLifetime) + time.Duration(extended) + return time.Duration(maxLifetime) + time.Duration(rand.Uint32N(uint32(maxLifetime))) } func (pool *ConnPool[C]) connReopen(ctx context.Context, dbconn *Pooled[C], now time.Time) error {