Skip to content

KAFKA-20364: Remove control records reads from metadata module#22164

Open
xxxxxxjun wants to merge 2 commits intoapache:trunkfrom
xxxxxxjun:KAFKA-20364-remove-control-records-from-metadata
Open

KAFKA-20364: Remove control records reads from metadata module#22164
xxxxxxjun wants to merge 2 commits intoapache:trunkfrom
xxxxxxjun:KAFKA-20364-remove-control-records-from-metadata

Conversation

@xxxxxxjun
Copy link
Copy Markdown
Contributor

@xxxxxxjun xxxxxxjun commented Apr 28, 2026

MetadataLoader.loadControlRecords() parsed KRAFT_VERSION control records
to update the kraftVersion metric, which leaked raft's internal control
record format into the metadata module. Source the value from the raft
client through a Supplier on MetadataLoader.Builder, and
record it in maybePublishMetadata() with the other feature levels.

The update moves from the per-batch path to the publish path, so
kraftVersion is gated on catch-up like the other feature levels. The
metric name is unchanged.

KRAFT_VOTERS, mentioned in the JIRA description, isn't read in the
metadata module, so this PR only changes KRAFT_VERSION.
testKRaftVersionFinalizedLevelMetric now uses a mutable supplier to
drive the metric instead of injecting control records.

@github-actions github-actions Bot added triage PRs from the community core Kafka Broker kraft small Small PRs labels Apr 28, 2026
Comment on lines -535 to -538
assertThrows(
NullPointerException.class,
() -> loader.metrics().finalizedFeatureLevel(KRaftVersion.FEATURE_NAME)
);
Copy link
Copy Markdown
Contributor Author

@xxxxxxjun xxxxxxjun Apr 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This no longer holds — kraft.version is registered on every publish, regardless of control records.

setThreadNamePrefix(s"kafka-${sharedServerConfig.nodeId}-").
setFaultHandler(metadataLoaderFaultHandler).
setHighWaterMarkAccessor(() => _raftManager.client.highWatermark()).
setKraftVersionSupplier(() => _raftManager.client.kraftVersion()).
Copy link
Copy Markdown
Contributor Author

@xxxxxxjun xxxxxxjun Apr 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This lambda runs at publish time, after _raftManager.startup() above has initialized the client.

Comment on lines +401 to +407
// kraft.version is intentionally excluded from FeaturesImage (KAFKA-18979),
// so source it from the raft client instead of reading the control record directly.
metrics.recordFinalizedFeatureLevel(
KRaftVersion.FEATURE_NAME,
kraftVersionSupplier.get().featureLevel()
);

Copy link
Copy Markdown
Contributor Author

@xxxxxxjun xxxxxxjun Apr 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The early return above skips this during catch-up, same as the other feature levels.

setThreadNamePrefix(s"kafka-${sharedServerConfig.nodeId}-").
setFaultHandler(metadataLoaderFaultHandler).
setHighWaterMarkAccessor(() => _raftManager.client.highWatermark()).
setKraftVersionSupplier(() => _raftManager.client.kraftVersion()).
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RaftClient.kraftVersion() can return the requested (uncommitted) version on the leader during a kraft.version upgrade (FeatureControlManager uses the same source). A strict finalized source would need a new raft API. Should I address this here?

@github-actions github-actions Bot removed the triage PRs from the community label Apr 29, 2026
xxxxxxjun added 2 commits May 4, 2026 10:52
MetadataLoader.loadControlRecords() parsed KRAFT_VERSION control records
to update the kraftVersion metric. This coupled the metadata module to
raft's internal control record format. Source the value from the raft
client through a Supplier<KRaftVersion> on MetadataLoader.Builder and
record it in maybePublishMetadata() with the other feature levels.

The update happens at publish time instead of per batch, so kraftVersion
is gated on catch-up like the others. The metric name and value are
unchanged.
@xxxxxxjun xxxxxxjun force-pushed the KAFKA-20364-remove-control-records-from-metadata branch from 8ebb8f3 to 83416fc Compare May 4, 2026 01:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Kafka Broker kraft small Small PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant