Repository navigation
feat(binding-kafka): connect an api request stream to the broker named by its affinity - #3198
Merged
jfallows merged 2 commits intoNov 13, 2026
Conversation
… request stream Learn the broker table from a metadata stream on the route, then send a raw api request whose affinity is a broker id, expecting the network stream to be opened to that broker's host and port: a non-zero id, id 0 when the table knows broker 0, the same with api version negotiation, and an id the table does not know, which must reset the stream. An affinity of 0 with no broker 0 in the table keeps connecting to the first bootstrap server. The spec scripts pair each network client with its server. The runtime tests fail while every api request stream connects to the first bootstrap server whatever its affinity. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SiHVoV39g7wrgVnLJ7j2nV
…d by its affinity Resolve the broker of a raw api request stream from its affinity as the fetch and produce clients do: look the affinity up as a broker id in the route's broker table, which the meta stream refreshes from the metadata brokers. An affinity of 0 resolves to broker 0 when the table knows it, and otherwise to the first bootstrap server as before. A non-zero affinity the table does not know resets the stream before a client is created, with no fallback to another broker. The address is resolved at every connect, so a reconnect follows a changed broker address and resets the pending streams when the broker has left the table. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SiHVoV39g7wrgVnLJ7j2nV
This was referenced Nov 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.
Description
KafkaClientApiFactoryserved every raw API request stream (KIND_API_REQUEST) by connecting to the first configured bootstrap server, whatever the stream's affinity; the affinity only chose which client instance was used. A raw API stream therefore could not reach a specific broker, so an API that must be sent to a particular broker got an error such as NOT_COORDINATOR (16) from any other broker.The affinity of a raw API request stream is now the broker id, as it already is for fetch and produce streams. The client resolves it against the route's broker table (
KafkaClientRoute.servers, which the meta stream rewrites from the MetadataBrokers[]) every time it opens the network stream:Because the id is resolved at each connect, a reconnect follows a changed broker address, and the pending streams are reset when the broker has left the table. There is one client (one connection, one learned API version table) per affinity, as before.
One behaviour change, accepted in the design: an affinity-0 stream used to always connect to the first bootstrap server; when the route's meta stream has already learned broker 0 it now connects to broker 0's advertised address. Routes with no table, or no broker 0 in it, behave as before. This relies on what fetch and produce already rely on, that the addresses in the broker table are reachable by the binding.
Design: #3195 (comment) (revised for broker id 0 in #3195 (comment)).
Stacked: this PR's base is
fix/3183-kafka-cache-api-passthrough(headb3bc4396062a60d6b9313b5f0c79b2c887ff8b80, #3185). The cache bindings already forward the caller's affinity to the exit of an API request stream, so they need no change here.Mirrored pattern
KafkaClientFetchFactoryandKafkaClientProduceFactory: the affinity is the broker id, resolved withclientRoute.servers.get(affinity), and the resolved server becomes the proxy begin extension of the network stream. The factory takessupplyClientRoutelike the meta, fetch and produce factories. No broker address is carried in a begin extension and no new table or refresh mechanism is added.Protocol text read
Read with curl from the Apache Kafka
4.0.0tag,clients/src/main/resources/common/message/:OffsetDeleteRequest.jsonandOffsetDeleteResponse.json(apiKey 47, valid version 0, no broker identity),FindCoordinatorResponse.json(apiKey 10,NodeId/Host/Portin v0-3,Coordinators[]from v4) andMetadataResponse.json(apiKey 3,Brokers[]withNodeIdas the map key,Host,Port). Only the API key, valid versions and those field names were checked.Fixes #3195
Test evidence
Test-first: commit
f9b27977holds only the scripts and IT methods; commit 2 holds the implementation.New scripts: network pairs
create.topics.v7.broker,.broker.bootstrap,.broker.zero,.broker.unknown,.broker.negotiatedunderstreams/network/api(each plays the metadata connection to the bootstrap server, then the API connection to the broker, asserting the proxy destination), and application clientscreate.topics.v7.broker,.broker.zero,.broker.unknownunderstreams/application/api(a meta stream, then the API stream with the affinity, a script propertyaffinityoverridable with@ScriptProperty). New IT methods, all in existing classes: five in the specnetwork/KafkaCreateTopicsITand five in the runtimeKafkaCreateTopicsIT.On the base (
b3bc4396) with unchanged production code:KafkaCreateTopicsIT, test commit only: 13 run, 4 failed.shouldCreateTopicsV3ToBrokerByAffinity,...ToBrokerZeroWhenKnownand...ToBrokerByAffinityNegotiatedfail because the API connection arrives with the proxy destinationlocalhost(the bootstrap server) where the script expectsbroker2.example.comorbroker0.example.com;shouldRejectCreateTopicsV3ToUnknownBrokerfails because the stream is accepted whereconnect abortedis expected. Each then times out on the rerun.shouldCreateTopicsV3ToBootstrapWhenBrokerZeroUnknownpasses before and after: it guards today's behaviour.Verification of the head:
clean verifyofspecs/binding-kafka.specandruntime/binding-kafkatogether, with checkstyle, license and notice checks on and the build cache skipped (-Dmaven.build.cache.skipCache=true), after installing upstream with-am -DskipTests -DskipITs -Dskip.checks=true: BUILD SUCCESS.specs/binding-kafka.spec: unit tests 226 run, 0 failures; ITs 472 run, 0 failures, 12 skipped.runtime/binding-kafka: unit tests 229 run, 0 failures; ITs 447 run, 0 failures, 67 skipped.What I did not run
runtime/engine(not touched).How it was built: the
mvnwwrapper could not download its jar (HTTP 429 from the egress proxy), so I used the systemmvn3.9.11 with-Dmaven.artifact.threads=1; two runs failed first only because the proxy refused downloads of the surefire provider, and passed unchanged when rerun with-U.Not delivered / follow-ups
clientsByAffinitystill never evicts entries; with the unknown-id check before a client is created, it is bounded by the size of the broker table.Generated by Claude Code