Skip to content

Commit 9235bba

Browse files
committed
transport: replace atomic.Value with atomic.Pointer[T]
Fixes #269
1 parent 655c377 commit 9235bba

File tree

6 files changed

+13
-13
lines changed

6 files changed

+13
-13
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/google/go-cmp v0.5.6
77
github.com/klauspost/compress v1.15.1
88
github.com/pierrec/lz4/v4 v4.1.14
9-
go.uber.org/atomic v1.9.0
9+
go.uber.org/atomic v1.10.0
1010
go.uber.org/goleak v1.1.12
1111
)
1212

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
2121
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
2222
go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE=
2323
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
24+
go.uber.org/atomic v1.10.0 h1:9qC72Qh0+3MqyJbAn8YU5xVq1frD8bn3JtD2oXtafVQ=
25+
go.uber.org/atomic v1.10.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
2426
go.uber.org/goleak v1.1.12 h1:gZAh5/EyT/HQwlpkCy6wTpqfH9H8Lz8zbm3dZh+OyzA=
2527
go.uber.org/goleak v1.1.12/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
2628
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=

transport/cluster.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ type (
2626
)
2727

2828
type Cluster struct {
29-
topology atomic.Value // *topology
29+
topology atomic.Pointer[topology]
3030
control *Conn
3131
cfg ConnConfig
3232
handledEvents []frame.EventType // This will probably be moved to config.
@@ -443,7 +443,7 @@ func parseTokensFromRow(n *Node, r frame.Row, ring *Ring) error {
443443
}
444444

445445
func (c *Cluster) Topology() *topology {
446-
return c.topology.Load().(*topology)
446+
return c.topology.Load()
447447
}
448448

449449
func (c *Cluster) setTopology(t *topology) {

transport/cluster_integration_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func TestClusterIntegration(t *testing.T) {
8080
}
8181

8282
// There should be at least system keyspaces present.
83-
if len(c.topology.Load().(*topology).keyspaces) == 0 {
83+
if len(c.Topology().keyspaces) == 0 {
8484
t.Fatalf("Keyspaces failed to load")
8585
}
8686

transport/export_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ package transport
22

33
func (p *ConnPool) AllConns() []*Conn {
44
var conns = make([]*Conn, len(p.conns))
5-
for i, v := range p.conns {
6-
conns[i], _ = v.Load().(*Conn)
5+
for i := range conns {
6+
conns[i] = p.loadConn(i)
77
}
88
return conns
99
}

transport/pool.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ type ConnPool struct {
1919
host string
2020
nrShards int
2121
msbIgnore uint8
22-
conns []atomic.Value
22+
conns []atomic.Pointer[Conn]
2323
connClosedCh chan int // notification channel for when connection is closed
2424
connObs ConnObserver
2525
}
@@ -99,13 +99,11 @@ func (p *ConnPool) storeConn(conn *Conn) {
9999
}
100100

101101
func (p *ConnPool) loadConn(shard int) *Conn {
102-
conn, _ := p.conns[shard].Load().(*Conn)
103-
return conn
102+
return p.conns[shard].Load()
104103
}
105104

106105
func (p *ConnPool) clearConn(shard int) bool {
107-
conn, _ := p.conns[shard].Swap((*Conn)(nil)).(*Conn)
108-
return conn != nil
106+
return p.conns[shard].Swap(nil) != nil
109107
}
110108

111109
func (p *ConnPool) Close() {
@@ -115,7 +113,7 @@ func (p *ConnPool) Close() {
115113
// closeAll is called by PoolRefiller.
116114
func (p *ConnPool) closeAll() {
117115
for i := range p.conns {
118-
if conn, ok := p.conns[i].Swap((*Conn)(nil)).(*Conn); ok {
116+
if conn := p.conns[i].Swap(nil); conn != nil {
119117
conn.Close()
120118
}
121119
}
@@ -168,7 +166,7 @@ func (r *PoolRefiller) init(ctx context.Context, host string) error {
168166
host: host,
169167
nrShards: int(ss.NrShards),
170168
msbIgnore: ss.MsbIgnore,
171-
conns: make([]atomic.Value, int(ss.NrShards)),
169+
conns: make([]atomic.Pointer[Conn], int(ss.NrShards)),
172170
connClosedCh: make(chan int, int(ss.NrShards)+1),
173171
connObs: r.cfg.ConnObserver,
174172
}

0 commit comments

Comments
 (0)