-
Notifications
You must be signed in to change notification settings - Fork 30
Prefer replicas over leader for consumer connections #446
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
Prefer replicas over leader for consumer connections #446
Conversation
bbb7210 to
b7f721a
Compare
45e7c74 to
502140e
Compare
|
Uh! Good catch @lukebakken! Thank you! |
|
Thank @samuelmasse! He's been extensively comparing the behavior of stream clients and found this particular issue 😺 |
|
@lukebakken, can you please execute the tests? There is a problem with the @samuelmasse, if you need info with stream clients, let me know Thank you both! :)! |
c24c566 to
90271f5
Compare
|
@Gsantomaggio working on it now. I must have missed the email saying CI failed. |
6403433 to
a5f372e
Compare
|
Turns out CI didn't run because it's not configured to on a PR. Anyway, everything passes now on my machine. I'll see what's up in CI. I'll follow-up with another PR to do the following:
UPDATE: I can't re-run the tests, and I don't think the one failure is due to these changes. |
|
Once #447 is merged, I'll rebase this branch. |
a5f372e to
bf02ddc
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #446 +/- ##
==========================================
- Coverage 84.50% 83.40% -1.11%
==========================================
Files 26 28 +2
Lines 3756 4206 +450
==========================================
+ Hits 3174 3508 +334
- Misses 411 473 +62
- Partials 171 225 +54
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
bf02ddc to
091b19f
Compare
The Go client currently uses equal probability distribution for consumer placement, including the leader node in the candidate pool alongside replicas. This results in consumers connecting to the leader ~33% of the time (with 2 replicas), which violates RabbitMQ Streams best practices that recommend consumers connect to replicas rather than leaders. This change modifies `BrokerForConsumerWithResolver` to only include the leader in the candidate pool when no replicas are available. When replicas exist, consumers randomly select from replicas only, guaranteeing zero probability of leader placement. This matches the .NET client behavior and follows RabbitMQ Streams best practices for consumer placement. The leader is used as a fallback when `availableReplicas == 0`, ensuring consumers can still connect when replicas are unavailable. Use same retry delay as .NET stream client Includes `golangci-lint` fixups
091b19f to
042f6b5
Compare
|
@Gsantomaggio OK I'm sure the latest failures are unrelated to these changes. Thanks for the review! |
Signed-off-by: Gabriele Santomaggio <G.santomaggio@gmail.com>
Signed-off-by: Gabriele Santomaggio <G.santomaggio@gmail.com>
The method does not indicate the last message stored, but the last stored in memory. Signed-off-by: Gabriele Santomaggio <G.santomaggio@gmail.com>
|
@lukebakken Thanks again for the PR. It was not a flaky test, but it was a bug. I deprecated the function There is an edge case in which multiple clients use the same consumer name, and the last stored offset in memory is not the one the user expects.
The bug was in |
The Go client currently uses equal probability distribution for consumer placement, including the leader node in the candidate pool alongside replicas. This results in consumers connecting to the leader ~33% of the time (with 2 replicas), which violates RabbitMQ Streams best practices that recommend consumers connect to replicas rather than leaders.
This change modifies
BrokerForConsumerWithResolverto only include the leader in the candidate pool when no replicas are available. When replicas exist, consumers randomly select from replicas only, guaranteeing zero probability of leader placement. This matches the .NET client behavior and follows RabbitMQ Streams best practices for consumer placement.The leader is used as a fallback when
availableReplicas == 0, ensuring consumers can still connect when replicas are unavailable.(this PR builds on #445, just FYI)