Skip to content

fix(runtime): give each target cluster its own bootstrap selection strategy - #1

Closed
k-wall wants to merge 1 commit into
AzazelSensei:fix-4840-cluster-definition-bootstrap-selectionfrom
k-wall:kwall-4891-review-followups
Closed

k-wall wants to merge 1 commit into
AzazelSensei:fix-4840-cluster-definition-bootstrap-selectionfrom
k-wall:kwall-4891-review-followups

Conversation

@k-wall

@k-wall k-wall commented Sep 15, 2026

Copy link
Copy Markdown

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 — yamlDeserializesBootstrapServerSelection was a config-parsing test living in ClusterDefinitionTest. Moved to ConfigParserTest as shouldSupportClusterDefinitionWithConfiguredBootstrapServerSelectionStrategy, parameterised over both strategies via @MethodSource so it mirrors the existing shouldSupportTargetClusterWithConfiguredBootstrapServerSelectionStrategy.

Also added a yamlDeserializeSerializeFidelity case for clusterDefinitions + bootstrapServerSelection, since round-trip fidelity is the other thing ConfigParserTest owns and the new property had no coverage there.

2. Shared mutable selection strategy

ClusterDefinition.toTargetCluster() passed the definition's own BootstrapSelectionStrategy instance straight through:

return new TargetCluster(bootstrapServers, Optional.ofNullable(tls), selectionStrategy);

A named cluster definition exists precisely to be referenced by many virtual clusters and routes, and toTargetCluster() is called once per reference (Configuration.java:303 and :338). So every derived TargetCluster shared one RoundRobinBootstrapSelectionStrategy, and therefore one counter.

That breaks the contract the strategy's own Javadoc states:

each server selection for each VirtualCluster will start from 0

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, ClusterDefinition has no strategy field, so a configured strategy could only come from a virtual cluster's inline targetCluster, 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 derived TargetCluster gets its own strategy. Implementations that are immutable and hold no selection state may return this (as FixedBootstrapSelectionStrategy does).

The null branch also goes away. It called the two-arg TargetCluster constructor, which attaches the shared static DEFAULT_SELECTION_STRATEGY; because that field is then non-null, the resulting TargetCluster serializes bootstrapServerSelection: {strategy: round-robin} even when the user wrote nothing — contrary to the stated intent in TargetCluster ("we don't apply this to the field itself so that we can maintain fidelity between the fluent API and the yaml config"). Passing null through preserves that.

ClusterDefinitionTest.toTargetClusterPassesSelectionStrategy asserted isSameAs, i.e. it pinned the unwanted behaviour, so it is inverted. shouldGetIndependentBootstrapServerStrategies is added as the regression guard; without the fix it fails with expected: 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.yaml already covers it.

Verification

ClusterDefinitionTest, ConfigParserTest, RoutingGraphChangeDetectorTest and the three strategy tests pass; -Pci formatter and checkstyle validation is clean.

🤖 Generated with Claude Code

…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]>
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.

1 participant