Skip to content

fix(inkless:controller): reject a topic type flag that isn't true or false - #899

Open
giuseppelillo wants to merge 2 commits into
mainfrom
giuseppelillo/padded-diskless-enable
Open

giuseppelillo wants to merge 2 commits into
mainfrom
giuseppelillo/padded-diskless-enable

Conversation

@giuseppelillo

Copy link
Copy Markdown
Contributor

A diskless.enable value 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

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 in LogConfig then reads the topic as diskless, and the controller reads it as classic. InklessMetadataView.warnIfNotBoolean already 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:

  • An alter that corrects the value to true looks like a classic-to-diskless switch. markClassicToDisklessSwitchStarted marks the partitions of a born-diskless topic as switch-pending, and the leader runs the switch on them.
  • LogConfigHelper.wasDisklessEnabled reads the stored value as false, so the check "It is invalid to disable diskless" doesn't stop an alter to false.

Example before this change

On a 3-broker cluster with consolidation on and diskless.allow.from.classic.enable=true:

  1. A born-diskless topic has 5 records, and its partition has classicToDisklessStartOffset=-1.
  2. IncrementalAlterConfigs sets diskless.enable=" true". The controller accepts it. DescribeTopicPartitions for the topic then fails with UNKNOWN_SERVER_ERROR.
  3. IncrementalAlterConfigs sets diskless.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, and classicPrefixInRemoteStorage=true.

Fix

ConfigurationControlManager.validateAlterConfig rejects a topic diskless.enable or remote.storage.enable value that isn't true or false, in any case, with INVALID_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, because markConsolidationStarted and warnIfNotBoolean read it the same way. The controller therefore rejects such a remote.storage.enable value for a classic topic too.

The check doesn't handle a value that a metadata log already stores.

Test plan

  • ConfigurationControlManagerTest: testRejectPaddedTopicTypeFlag and testAcceptTopicTypeFlagInAnyCase, for both keys.
  • ReplicationControlManagerInklessTest covers a value with surrounding whitespace in these cases:
    • Followed by true on a born-diskless topic, through the incremental and the legacy alter. The controller writes no switch-pending marker.
    • Followed by false on a born-diskless topic, through the incremental and the legacy alter. Diskless stays enabled.
    • On a classic topic with the switch allowed.
    • For remote.storage.enable on a diskless topic.
    • 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.
  • :metadata:checkstyleMain, :metadata:checkstyleTest, and :metadata:spotbugsMain pass.
  • make vale reports no inkless-owned prose to lint.

🤖 Generated with Claude Code

…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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 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.enable and remote.storage.enable values other than case-insensitive true or false during 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)) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is that a problem only for inkless? Why doesn't that happen with upstream kafka too?

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.

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

3 participants