Skip to content

Commit

Permalink
Switch to use math/rand/v2.Uint32N and clean runtime.fastrand
Browse files Browse the repository at this point in the history
Signed-off-by: Aoang <[email protected]>
  • Loading branch information
Aoang committed Mar 11, 2024
1 parent fbaed97 commit 1e0aa22
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 6 deletions.
3 changes: 0 additions & 3 deletions go/hack/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 2 additions & 3 deletions go/pools/smartconnpool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 1e0aa22

Please sign in to comment.