Skip to content

fix: add kafka-go metadata compatibility mode#3460

Merged
superhx merged 1 commit into
mainfrom
backport/kafka-go-metadata-main
Jul 13, 2026
Merged

fix: add kafka-go metadata compatibility mode#3460
superhx merged 1 commit into
mainfrom
backport/kafka-go-metadata-main

Conversation

@superhx

@superhx superhx commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

Why

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.

What

Add a kafka-go Metadata compatibility mode, enabled by default through:

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.

Validation

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

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
@superhx

superhx commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator Author

cherry-pick #3459

@superhx superhx enabled auto-merge (squash) July 13, 2026 07:43
@superhx superhx merged commit 87b85a0 into main Jul 13, 2026
8 checks passed
@superhx superhx deleted the backport/kafka-go-metadata-main branch July 13, 2026 07:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants