-
Notifications
You must be signed in to change notification settings - Fork 341
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[fix] [client] fix same producer/consumer use more than one connection per broker #1323
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see the ACK requests still use pc._getConn()
and RequestOnCnx
or RequestOnCnxNoWait
in some places, should they use RequestWithCnxKeySuffix
as well?
Or at least should we call _setConn(nil)
when the consumer unregisters itself from the connection? For example, https://github.com/apache/pulsar/blob/5a3a1f169a7f90181bd5c213c8e9f479bc74f0f2/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConnectionHandler.java#L194
No need, in grabConn will reset conx |
pulsar/internal/connection_pool.go
Outdated
func (p *connectionPool) GenerateRoundRobinIndex() int32 { | ||
cnt := atomic.AddInt32(&p.roundRobinCnt, 1) | ||
if cnt < 0 { | ||
cnt = -cnt | ||
} | ||
return cnt % p.maxConnectionsPerHost | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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:
func (p *connectionPool) GenerateRoundRobinIndex() int32 { | |
cnt := atomic.AddInt32(&p.roundRobinCnt, 1) | |
if cnt < 0 { | |
cnt = -cnt | |
} | |
return cnt % p.maxConnectionsPerHost | |
} | |
func (p *connectionPool) GenerateRoundRobinIndex() int32 { | |
return atomic.AddUint32(&p.roundRobinCnt, 1) % p.maxConnectionsPerHost | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering why not just generate a random integer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you make roundRobinCnt as uint32, so that we can simplify this method. as the following:
Done
I'm wondering why not just generate a random integer?
Here just keep original logic:
pulsar-client-go/pulsar/internal/connection_pool.go
Lines 154 to 161 in ffba2a8
func (p *connectionPool) getMapKey(logicalAddr *url.URL, physicalAddr *url.URL) string { | |
cnt := atomic.AddInt32(&p.roundRobinCnt, 1) | |
if cnt < 0 { | |
cnt = -cnt | |
} | |
idx := cnt % p.maxConnectionsPerHost | |
return fmt.Sprint(logicalAddr.Host, "-", physicalAddr.Host, "-", idx) | |
} |
Yes, the consumer's connection is called after the Subscribe RPC is done. When a partition consumer (
What I have concern is, before the There is another possible case that Ideally, I think the best solution is to call |
Co-authored-by: Zike Yang <zike@apache.org>
hi, @BewareMyPower
In this PR, I will throw an error when the connection is null. In a future PR, I will implement the retry logic. |
Motivation
This is a catch up for apache/pulsar#21144
When a producer or consumer reconnects, a random number will be generated as the key suffix in
ConnectionPool
to create or get theConnection
object from the pool.pulsar-client-go/pulsar/internal/connection_pool.go
Lines 159 to 160 in ffba2a8
Modifications
Verifying this change