@@ -80,7 +80,7 @@ func (bb) Name() string {
80
80
}
81
81
82
82
func (bb ) Build (cc balancer.ClientConn , bOpts balancer.BuildOptions ) balancer.Balancer {
83
- b := & leastRequestBalancer {scRPCCounts : make (map [balancer.SubConn ]* int32 )}
83
+ b := & leastRequestBalancer {scRPCCounts : make (map [balancer.SubConn ]* atomic. Int32 )}
84
84
baseBuilder := base .NewBalancerBuilder (Name , b , base.Config {HealthCheck : true })
85
85
b .Balancer = baseBuilder .Build (cc , bOpts )
86
86
return b
@@ -92,7 +92,7 @@ type leastRequestBalancer struct {
92
92
balancer.Balancer
93
93
94
94
choiceCount uint32
95
- scRPCCounts map [balancer.SubConn ]* int32 // Hold onto RPC counts to keep track for subsequent picker updates.
95
+ scRPCCounts map [balancer.SubConn ]* atomic. Int32 // Hold onto RPC counts to keep track for subsequent picker updates.
96
96
}
97
97
98
98
func (lrb * leastRequestBalancer ) UpdateClientConnState (s balancer.ClientConnState ) error {
@@ -108,7 +108,7 @@ func (lrb *leastRequestBalancer) UpdateClientConnState(s balancer.ClientConnStat
108
108
109
109
type scWithRPCCount struct {
110
110
sc balancer.SubConn
111
- numRPCs * int32
111
+ numRPCs * atomic. Int32
112
112
}
113
113
114
114
func (lrb * leastRequestBalancer ) Build (info base.PickerBuildInfo ) balancer.Picker {
@@ -126,7 +126,7 @@ func (lrb *leastRequestBalancer) Build(info base.PickerBuildInfo) balancer.Picke
126
126
// Create new refs if needed.
127
127
for sc := range info .ReadySCs {
128
128
if _ , ok := lrb .scRPCCounts [sc ]; ! ok {
129
- lrb .scRPCCounts [sc ] = new (int32 )
129
+ lrb .scRPCCounts [sc ] = new (atomic. Int32 )
130
130
}
131
131
}
132
132
@@ -162,18 +162,18 @@ func (p *picker) Pick(balancer.PickInfo) (balancer.PickResult, error) {
162
162
pickedSC = & sc
163
163
continue
164
164
}
165
- if * sc .numRPCs < * pickedSC .numRPCs {
165
+ if sc .numRPCs . Load () < pickedSC .numRPCs . Load () {
166
166
pickedSC = & sc
167
167
}
168
168
}
169
169
// "The counter for a subchannel should be atomically incremented by one
170
170
// after it has been successfully picked by the picker." - A48
171
- atomic . AddInt32 ( pickedSC .numRPCs , 1 )
171
+ pickedSC .numRPCs . Add ( 1 )
172
172
// "the picker should add a callback for atomically decrementing the
173
173
// subchannel counter once the RPC finishes (regardless of Status code)." -
174
174
// A48.
175
175
done := func (balancer.DoneInfo ) {
176
- atomic . AddInt32 ( pickedSC .numRPCs , - 1 )
176
+ pickedSC .numRPCs . Add ( - 1 )
177
177
}
178
178
return balancer.PickResult {
179
179
SubConn : pickedSC .sc ,
0 commit comments