From 85aeb3410d03c7546a44765d8baf0283eab42607 Mon Sep 17 00:00:00 2001 From: Aoang Date: Tue, 12 Mar 2024 17:12:33 +0800 Subject: [PATCH] Fix: transition to `math/rand/v2` for Improved Performance and Code Clarity (#15438) 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 {