Repository navigation
fix(runtime): give each target cluster its own bootstrap selection strategy - #1
Closed
k-wall wants to merge 1 commit into
Conversation
…rategy ClusterDefinition.toTargetCluster() handed out the definition's own BootstrapSelectionStrategy instance to every TargetCluster derived from it. A named cluster definition is referenced by many virtual clusters and routes, and the method is called once per reference, so unrelated virtual clusters ended up sharing a single RoundRobinBootstrapSelectionStrategy counter. That contradicts the documented contract that selection starts from 0 for each virtual cluster, and means a virtual cluster no longer cycles through its own bootstrap servers. Add BootstrapSelectionStrategy.newInstance() so a configuration object acts as a prototype, and have toTargetCluster() mint a strategy per call. Implementations that are immutable and hold no selection state may return this. This also stops the null case routing through the two-arg TargetCluster constructor, which attached the shared static default and made the resulting TargetCluster serialize a bootstrapServerSelection the user never wrote. Move the clusterDefinitions YAML parsing test from ClusterDefinitionTest to ConfigParserTest, and add a round-trip fidelity case for the new property. Assisted-by: Claude Opus 5 <[email protected]> Signed-off-by: Keith Wall <[email protected]>
k-wall
force-pushed
the
kwall-4891-review-followups
branch
from
September 15, 2026 16:13
0081907 to
eeefe75
Compare
Merged
4 of 7 tasks
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.
Follow-ups to review of kroxylicious#4891, targeted at that PR's branch so they land as part of it.
1. Review comment: test in the wrong place
Review comment —
yamlDeserializesBootstrapServerSelectionwas a config-parsing test living inClusterDefinitionTest. Moved toConfigParserTestasshouldSupportClusterDefinitionWithConfiguredBootstrapServerSelectionStrategy, parameterised over both strategies via@MethodSourceso it mirrors the existingshouldSupportTargetClusterWithConfiguredBootstrapServerSelectionStrategy.Also added a
yamlDeserializeSerializeFidelitycase forclusterDefinitions+bootstrapServerSelection, since round-trip fidelity is the other thingConfigParserTestowns and the new property had no coverage there.2. Shared mutable selection strategy
ClusterDefinition.toTargetCluster()passed the definition's ownBootstrapSelectionStrategyinstance straight through:A named cluster definition exists precisely to be referenced by many virtual clusters and routes, and
toTargetCluster()is called once per reference (Configuration.java:303and:338). So every derivedTargetClustershared oneRoundRobinBootstrapSelectionStrategy, and therefore onecounter.That breaks the contract the strategy's own Javadoc states:
With three virtual clusters pointing at one definition listing three brokers, none of them walks 0,1,2 — they interleave on a shared counter, so one virtual cluster can draw the same broker repeatedly while another is never tried. That defeats the purpose of round-robin, which is spreading initial connection load.
This is new to this PR. On
main,ClusterDefinitionhas no strategy field, so a configured strategy could only come from a virtual cluster's inlinetargetCluster, which Jackson instantiates per virtual cluster. Moving the setting up to a shared, top-level construct is what introduces the sharing.Fix
Added
BootstrapSelectionStrategy.newInstance(), so a configuration object acts as a prototype and each derivedTargetClustergets its own strategy. Implementations that are immutable and hold no selection state may returnthis(asFixedBootstrapSelectionStrategydoes).The null branch also goes away. It called the two-arg
TargetClusterconstructor, which attaches the shared staticDEFAULT_SELECTION_STRATEGY; because that field is then non-null, the resultingTargetClusterserializesbootstrapServerSelection: {strategy: round-robin}even when the user wrote nothing — contrary to the stated intent inTargetCluster("we don't apply this to the field itself so that we can maintain fidelity between the fluent API and the yaml config"). Passingnullthrough preserves that.ClusterDefinitionTest.toTargetClusterPassesSelectionStrategyassertedisSameAs, i.e. it pinned the unwanted behaviour, so it is inverted.shouldGetIndependentBootstrapServerStrategiesis added as the regression guard; without the fix it fails withexpected: broker1:9092 but was: broker2:9092, which is the shared counter showing through.No changelog entry: the feature is unreleased and
changelog/unreleased/04840-cluster-definition-bootstrap-selection.yamlalready covers it.Verification
ClusterDefinitionTest,ConfigParserTest,RoutingGraphChangeDetectorTestand the three strategy tests pass;-Pciformatter and checkstyle validation is clean.🤖 Generated with Claude Code