KAFKA-18907 Add suitable error message when the appended value is too larger (#19070)

In ZooKeeper mode, users can append configurations to create values larger than Short.MAX_VALUE. However, this behavior is disallowed in KRaft mode. Additionally, a server error is returned to users. Creating a value this large is rare, so we don't plan to fix it for KRaft. This PR aims to tweak the error message.

Reviewers: Ken Huang <s7133700@gmail.com>, TengYao Chi <kitingiao@gmail.com>, Chia-Ping Tsai <chia7712@gmail.com>
This commit is contained in:
ClarkChen 2025-03-03 03:23:01 +08:00 committed by GitHub
parent d460efb9c9
commit 42a200bd39
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 0 deletions

View File

@ -339,6 +339,10 @@ public class ConfigurationControlManager {
return DISALLOWED_CLUSTER_MIN_ISR_REMOVAL_ERROR;
} else if (configRecord.value() == null) {
allConfigs.remove(configRecord.name());
} else if (configRecord.value().length() > Short.MAX_VALUE) {
// 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 {
allConfigs.put(configRecord.name(), configRecord.value());
}
@ -385,6 +389,10 @@ public class ConfigurationControlManager {
new ApiError(INVALID_CONFIG, "Cluster-level " + MIN_IN_SYNC_REPLICAS_CONFIG +
" cannot be removed while ELR is enabled.");
private static final ApiError DISALLOWED_CONFIG_VALUE_SIZE_ERROR =
new ApiError(INVALID_CONFIG, "The configuration value cannot be added because " +
"it exceeds the maximum value size of " + Short.MAX_VALUE + " bytes.");
boolean isDisallowedBrokerMinIsrTransition(ConfigRecord configRecord) {
if (configRecord.name().equals(MIN_IN_SYNC_REPLICAS_CONFIG) &&
configRecord.resourceType() == BROKER.id() &&

View File

@ -210,6 +210,15 @@ public class ConfigurationControlManagerTest {
setName("abc").setValue(null), CONFIG_RECORD.highestSupportedVersion())),
ApiError.NONE),
manager.incrementalAlterConfig(MYTOPIC, toMap(entry("abc", entry(DELETE, "xyz"))), true));
// The configuration value exceeding the maximum size is not allowed to be added.
String largeValue = new String(new char[Short.MAX_VALUE - APPEND.id() - 1]);
Map<String, Entry<AlterConfigOp.OpType, String>> largeValueOfOps = toMap(entry("abc", entry(APPEND, largeValue)));
ControllerResult<ApiError> invalidConfigValueResult = manager.incrementalAlterConfig(MYTOPIC, largeValueOfOps, true);
assertEquals(Errors.INVALID_CONFIG, invalidConfigValueResult.response().error());
assertEquals("The configuration value cannot be added because it exceeds the maximum value size of " + Short.MAX_VALUE + " bytes.",
invalidConfigValueResult.response().message());
}
@Test