Repository navigation
fix(inkless:controller): reject a topic type flag that isn't true or false - #899
giuseppelillo wants to merge 2 commits into
Conversation
…false `ConfigDef` trims a boolean before it parses it, so a create or an alter accepts `diskless.enable=" true"`. The controller stores the raw string and reads it with `Boolean.parseBoolean`, which doesn't trim. The validation then reads the topic as diskless, and the controller reads it as classic. The brokers fail the requests that read the flag while the value is stored. The controller makes two wrong decisions from that value: - An alter that corrects the value to `true` looks like a classic-to-diskless switch. The controller marks the partitions of a born-diskless topic as switch-pending, and the leader runs the switch on them. - The check that keeps diskless enabled reads the stored value as `false`, so it doesn't stop an alter to `false`. The controller now rejects a topic `diskless.enable` or `remote.storage.enable` value that isn't `true` or `false`, in any case, with `INVALID_CONFIG`. `validateAlterConfig` runs the check. A create, an incremental alter, and a legacy alter all pass through it, so a rejected request writes no records. The controller also rejects such a `remote.storage.enable` value for a classic topic. ## Testing - `ConfigurationControlManagerTest`: `testRejectPaddedTopicTypeFlag` and `testAcceptTopicTypeFlagInAnyCase`, for both keys. - `ReplicationControlManagerInklessTest`: a value with surrounding whitespace followed by `true` or by `false` on a born-diskless topic, through the incremental and the legacy alter, on a classic topic with the switch allowed, for `remote.storage.enable`, and at topic creation. - Both classes pass with the change: 284 tests. Without the change to `ConfigurationControlManager`, the 9 new tests that expect a rejection fail. Assisted-by: Claude Opus 5.5 Assisted-by: Claude Fable 5.2
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are identified for the change to reject malformed topic-type flags.
No open issues 🎉
What changed in this PR
This PR prevents inconsistent interpretation of topic type flags by rejecting malformed values before the controller stores them, avoiding unintended classic-to-diskless switches.
Changes:
- Rejects
diskless.enableandremote.storage.enablevalues other than case-insensitivetrueorfalseduring topic creation and config alterations. - Adds regression tests for rejected values, accepted casing, and preservation of diskless state without switch markers.
- Updates a broker-side comment to clarify how older controllers can store whitespace-padded values.
| File | Description |
|---|---|
metadata/src/test/java/org/apache/kafka/controller/ReplicationControlManagerInklessTest.java |
Adds create and alter regression tests for malformed flags and unintended state transitions. |
metadata/src/test/java/org/apache/kafka/controller/ConfigurationControlManagerTest.java |
Tests rejection of padded values and acceptance of valid mixed-case booleans. |
metadata/src/main/java/org/apache/kafka/controller/ConfigurationControlManager.java |
Validates topic type flags and returns INVALID_CONFIG for malformed values. |
core/src/main/scala/kafka/server/metadata/InklessMetadataView.scala |
Clarifies the existing warning comment; no behavior change. |
Review effort: Balanced
| // In KRaft mode, large config values cannot be created by appending. | ||
| // If the size exceeds Short.MAX_VALUE, this error will be thrown to notify the user. | ||
| return DISALLOWED_CONFIG_VALUE_SIZE_ERROR; | ||
| } else if (isNonCanonicalTopicTypeFlag(configRecord)) { |
There was a problem hiding this comment.
Is that a problem only for inkless? Why doesn't that happen with upstream kafka too?
There was a problem hiding this comment.
Upstream has the same mismatch for unclean.leader.election.enable: uncleanLeaderElectionEnabledForTopic reads the stored value with Boolean.parseBoolean, so the controller reads " true" as false and only skips the unclean election. For these two keys the controller writes the switch and consolidation markers of the partitions from the value, so it rejects it. I extended the comment on the check to say that (ceda6fd).
🤖 Addressed by Claude Code
…ic type flags A reviewer asked whether the mismatch between `ConfigDef` and the stored value exists in upstream Kafka too. It does, for `unclean.leader.election.enable`: `uncleanLeaderElectionEnabledForTopic` reads the stored value with `Boolean.parseBoolean`, so the controller reads a value with surrounding whitespace as false and skips the unclean election. For `diskless.enable` and `remote.storage.enable` the controller writes the switch and consolidation markers of the partitions from the value, which is why it rejects the value for these two keys. The comment on the check now says so. Assisted-by: Claude Fable 5.2
A
diskless.enablevalue with surrounding whitespace, such as" true", makes the controller run the classic-to-diskless switch on a topic that was born diskless. With this change the controller rejects such a value.Problem
ConfigDeftrims a boolean before it parses it, so a create or an alter acceptsdiskless.enable=" true". The controller stores the raw string and reads it withBoolean.parseBoolean, which doesn't trim. The validation inLogConfigthen reads the topic as diskless, and the controller reads it as classic.InklessMetadataView.warnIfNotBooleanalready logs that the brokers fail the requests that read the flag while the value is stored.The controller makes two wrong decisions from that value:
truelooks like a classic-to-diskless switch.markClassicToDisklessSwitchStartedmarks the partitions of a born-diskless topic as switch-pending, and the leader runs the switch on them.LogConfigHelper.wasDisklessEnabledreads the stored value asfalse, so the check "It is invalid to disable diskless" doesn't stop an alter tofalse.Example before this change
On a 3-broker cluster with consolidation on and
diskless.allow.from.classic.enable=true:classicToDisklessStartOffset=-1.IncrementalAlterConfigssetsdiskless.enable=" true". The controller accepts it.DescribeTopicPartitionsfor the topic then fails withUNKNOWN_SERVER_ERROR.IncrementalAlterConfigssetsdiskless.enable="true". The controller accepts it and starts the switch. The partition ends with a committed seal (0 in one run, 5 in another),initialDisklessLeaderEpoch=1, andclassicPrefixInRemoteStorage=true.Fix
ConfigurationControlManager.validateAlterConfigrejects a topicdiskless.enableorremote.storage.enablevalue that isn'ttrueorfalse, in any case, withINVALID_CONFIG. A create, an incremental alter, and a legacy alter all pass through that method, so a rejected request writes no records and gets no switch or consolidation markers.The check also covers
remote.storage.enable, becausemarkConsolidationStartedandwarnIfNotBooleanread it the same way. The controller therefore rejects such aremote.storage.enablevalue for a classic topic too.The check doesn't handle a value that a metadata log already stores.
Test plan
ConfigurationControlManagerTest:testRejectPaddedTopicTypeFlagandtestAcceptTopicTypeFlagInAnyCase, for both keys.ReplicationControlManagerInklessTestcovers a value with surrounding whitespace in these cases:trueon a born-diskless topic, through the incremental and the legacy alter. The controller writes no switch-pending marker.falseon a born-diskless topic, through the incremental and the legacy alter. Diskless stays enabled.remote.storage.enableon a diskless topic.ConfigurationControlManager, the 9 new tests that expect a rejection fail.:metadata:checkstyleMain,:metadata:checkstyleTest, and:metadata:spotbugsMainpass.make valereports no inkless-owned prose to lint.🤖 Generated with Claude Code