Skip to content

Commit ee6f425

Browse files
authored
feat(bigtable): switch to rand v2 (#14008)
1 parent 1bce843 commit ee6f425

2 files changed

Lines changed: 5 additions & 7 deletions

File tree

bigtable/internal/transport/conn_recycler.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ package internal
1616

1717
import (
1818
"context"
19-
"math/rand"
19+
"math/rand/v2"
2020
"sync"
2121
"time"
2222

@@ -33,7 +33,6 @@ type ConnectionRecycler struct {
3333
ticker *time.Ticker
3434
done chan struct{}
3535
stopOnce sync.Once
36-
rng *rand.Rand
3736
}
3837

3938
// NewConnectionRecycler creates a new recycler with the provided configuration.
@@ -42,7 +41,6 @@ func NewConnectionRecycler(config btopt.ConnectionRecycleConfig, pool *BigtableC
4241
pool: pool,
4342
config: config,
4443
done: make(chan struct{}),
45-
rng: rand.New(rand.NewSource(time.Now().UnixNano())),
4644
}
4745
}
4846

@@ -103,7 +101,7 @@ func (cr *ConnectionRecycler) checkRecycle() {
103101

104102
var currentJitter time.Duration
105103
if hasJitter {
106-
currentJitter = time.Duration(cr.rng.Int63n(jitterVal))
104+
currentJitter = time.Duration(rand.Int64N(jitterVal))
107105
}
108106

109107
if age > cr.config.MaxAge+currentJitter {

bigtable/internal/transport/connpool.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"io"
2222
"log"
2323
"math"
24-
"math/rand"
24+
"math/rand/v2"
2525
"net"
2626
"net/url"
2727
"slices"
@@ -731,8 +731,8 @@ func (p *BigtableChannelPool) selectLeastLoadedRandomOfTwo() (*connEntry, error)
731731

732732
// Retry numConns * 2 times in worst case.
733733
for i := 0; i < numConns*2 && numConns > 1; i++ {
734-
idx1 := rand.Intn(numConns)
735-
idx2 := rand.Intn(numConns)
734+
idx1 := rand.IntN(numConns)
735+
idx2 := rand.IntN(numConns)
736736

737737
entry1 := conns[idx1]
738738
entry2 := conns[idx2]

0 commit comments

Comments
 (0)