RobertIndie commented on code in PR #1323:
URL: https://github.com/apache/pulsar-client-go/pull/1323#discussion_r1899527621


##########
pulsar/internal/connection_pool.go:
##########
@@ -141,6 +146,14 @@ func (p *connectionPool) GetConnections() 
map[string]Connection {
        return conns
 }
 
+func (p *connectionPool) GenerateRoundRobinIndex() int32 {
+       cnt := atomic.AddInt32(&p.roundRobinCnt, 1)
+       if cnt < 0 {
+               cnt = -cnt
+       }
+       return cnt % p.maxConnectionsPerHost
+}

Review Comment:
   
   
   `cnt = -cnt` is incorrect. I think you're trying to handle the case where 
`uint32` overflow results in a negative number. However, if `cnt` overflows to 
`math.MinInt32`, negating it will still result in a negative number.
   
   Could you make `roundRobinCnt` as uint32, so that we can simplify this 
method. as the following:
   ```suggestion
   func (p *connectionPool) GenerateRoundRobinIndex() int32 {
        return atomic.AddUint32(&p.roundRobinCnt, 1) % p.maxConnectionsPerHost
   }
   ```
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to