fix: add kafka-go metadata compatibility mode#3460
Merged
Conversation
This issue was verified against kafka-go `v0.4.51`. A default `NewWriter` refreshes metadata every 15 seconds. Produce retries up to 10 attempts with quadratic backoff from 100 ms to 1 second and a default 10-second write timeout. However, when Metadata returns `LEADER_NOT_AVAILABLE`, kafka-go converts the missing leader to a local non-temporary no-leader error, which can stop Produce before the partition becomes available. During an AutoMQ partition reassignment, Metadata may briefly have no leader while `replicas[0]` is already the broker opening the partition. This timing can cause user-visible write failures. Add a kafka-go Metadata compatibility mode, enabled by default through: ```properties automq.kafka-go.metadata.compatibility.enabled=true ``` For likely kafka-go clients, AutoMQ rewrites partition-level `LEADER_NOT_AVAILABLE` to `NONE` and uses `replicas[0]` as the predictive leader when replicas are non-empty. The setting is dynamically configurable. This does not change kafka-go metadata refresh timing. Users should set `WriterConfig.RebalanceInterval` to 5 seconds to reduce stale routing during reassignment. Three-node devkit, 10 msg/s, reassignment every 30 seconds for 5 minutes, kafka-go `v0.4.51`, `RebalanceInterval=5s`: - compatibility disabled: 236 no-leader errors - compatibility enabled: 0 errors
Collaborator
Author
|
cherry-pick #3459 |
Gezi-lzq
approved these changes
Jul 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
This issue was verified against kafka-go
v0.4.51.A default
NewWriterrefreshes metadata every 15 seconds. Produce retries up to 10 attempts with quadratic backoff from 100 ms to 1 second and a default 10-second write timeout. However, when Metadata returnsLEADER_NOT_AVAILABLE, kafka-go converts the missing leader to a local non-temporary no-leader error, which can stop Produce before the partition becomes available.During an AutoMQ partition reassignment, Metadata may briefly have no leader while
replicas[0]is already the broker opening the partition. This timing can cause user-visible write failures.What
Add a kafka-go Metadata compatibility mode, enabled by default through:
automq.kafka-go.metadata.compatibility.enabled=trueFor likely kafka-go clients, AutoMQ rewrites partition-level
LEADER_NOT_AVAILABLEtoNONEand usesreplicas[0]as the predictive leader when replicas are non-empty. The setting is dynamically configurable.This does not change kafka-go metadata refresh timing. Users should set
WriterConfig.RebalanceIntervalto 5 seconds to reduce stale routing during reassignment.Validation
Three-node devkit, 10 msg/s, reassignment every 30 seconds for 5 minutes, kafka-go
v0.4.51,RebalanceInterval=5s: