mirror of https://github.com/apache/kafka.git
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:
parent
d460efb9c9
commit
42a200bd39
|
@ -339,6 +339,10 @@ public class ConfigurationControlManager {
|
||||||
return DISALLOWED_CLUSTER_MIN_ISR_REMOVAL_ERROR;
|
return DISALLOWED_CLUSTER_MIN_ISR_REMOVAL_ERROR;
|
||||||
} else if (configRecord.value() == null) {
|
} else if (configRecord.value() == null) {
|
||||||
allConfigs.remove(configRecord.name());
|
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 {
|
} else {
|
||||||
allConfigs.put(configRecord.name(), configRecord.value());
|
allConfigs.put(configRecord.name(), configRecord.value());
|
||||||
}
|
}
|
||||||
|
@ -385,6 +389,10 @@ public class ConfigurationControlManager {
|
||||||
new ApiError(INVALID_CONFIG, "Cluster-level " + MIN_IN_SYNC_REPLICAS_CONFIG +
|
new ApiError(INVALID_CONFIG, "Cluster-level " + MIN_IN_SYNC_REPLICAS_CONFIG +
|
||||||
" cannot be removed while ELR is enabled.");
|
" 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) {
|
boolean isDisallowedBrokerMinIsrTransition(ConfigRecord configRecord) {
|
||||||
if (configRecord.name().equals(MIN_IN_SYNC_REPLICAS_CONFIG) &&
|
if (configRecord.name().equals(MIN_IN_SYNC_REPLICAS_CONFIG) &&
|
||||||
configRecord.resourceType() == BROKER.id() &&
|
configRecord.resourceType() == BROKER.id() &&
|
||||||
|
|
|
@ -210,6 +210,15 @@ public class ConfigurationControlManagerTest {
|
||||||
setName("abc").setValue(null), CONFIG_RECORD.highestSupportedVersion())),
|
setName("abc").setValue(null), CONFIG_RECORD.highestSupportedVersion())),
|
||||||
ApiError.NONE),
|
ApiError.NONE),
|
||||||
manager.incrementalAlterConfig(MYTOPIC, toMap(entry("abc", entry(DELETE, "xyz"))), true));
|
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
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue