You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kafka.apache.org by jy...@apache.org on 2026/09/12 07:02:45 UTC
(kafka) branch 4.3 updated: Revert "MINOR: Align consumer assignor loading with share and streams (#22929)"
This is an automated email from the ASF dual-hosted git repository.
m1a2st pushed a commit to branch 4.3
in repository https://gitbox.apache.org/repos/asf/kafka.git
The following commit(s) were added to refs/heads/4.3 by this push:
new 7cef3524ad2 Revert "MINOR: Align consumer assignor loading with share and streams (#22929)"
7cef3524ad2 is described below
commit 7cef3524ad29ee4a336a8f220c5fde30667b6fe3
Author: m1a2st <s7...@gmail.com>
AuthorDate: Sat Sep 12 15:02:09 2026 +0800
Revert "MINOR: Align consumer assignor loading with share and streams (#22929)"
This reverts commit 4c2e5ae3c580903fcc57024cfa2c7c0b885d0e8a.
---
.../coordinator/group/GroupCoordinatorConfig.java | 57 ++++++++---------
.../group/GroupCoordinatorConfigTest.java | 74 +++++++---------------
2 files changed, 48 insertions(+), 83 deletions(-)
diff --git a/group-coordinator/src/main/java/org/apache/kafka/coordinator/group/GroupCoordinatorConfig.java b/group-coordinator/src/main/java/org/apache/kafka/coordinator/group/GroupCoordinatorConfig.java
index 372311a7df8..b3c25dbfb88 100644
--- a/group-coordinator/src/main/java/org/apache/kafka/coordinator/group/GroupCoordinatorConfig.java
+++ b/group-coordinator/src/main/java/org/apache/kafka/coordinator/group/GroupCoordinatorConfig.java
@@ -20,7 +20,6 @@ import org.apache.kafka.common.Configurable;
import org.apache.kafka.common.KafkaException;
import org.apache.kafka.common.config.AbstractConfig;
import org.apache.kafka.common.config.ConfigDef;
-import org.apache.kafka.common.config.ConfigException;
import org.apache.kafka.common.record.internal.CompressionType;
import org.apache.kafka.common.record.internal.Records;
import org.apache.kafka.common.utils.Utils;
@@ -757,24 +756,28 @@ public class GroupCoordinatorConfig {
List<ConsumerGroupPartitionAssignor> assignors = new ArrayList<>();
try {
- // `configuredAssignor` is either the name of a built-in assignor,
- // or a fully qualified class name of a custom assignor
- for (String configuredAssignor : config.getList(GroupCoordinatorConfig.CONSUMER_GROUP_ASSIGNORS_CONFIG)) {
- ConsumerGroupPartitionAssignor assignor = defaultAssignors.get(configuredAssignor);
- if (assignor == null) {
- try {
- assignor = Utils.newInstance(configuredAssignor, ConsumerGroupPartitionAssignor.class);
- } catch (ClassNotFoundException e) {
- throw new ConfigException(CONSUMER_GROUP_ASSIGNORS_CONFIG, configuredAssignor,
- "Class cannot be found");
- } catch (ClassCastException e) {
- throw new ConfigException(CONSUMER_GROUP_ASSIGNORS_CONFIG, configuredAssignor,
- "Class is not an instance of " + ConsumerGroupPartitionAssignor.class.getName());
- } catch (KafkaException e) {
- // Utils#newInstance reports instantiation failures, for example a missing
- // public no-argument constructor, without naming the config that caused them.
- throw new ConfigException(CONSUMER_GROUP_ASSIGNORS_CONFIG, configuredAssignor, e.getMessage());
+ for (Object object : config.getList(GroupCoordinatorConfig.CONSUMER_GROUP_ASSIGNORS_CONFIG)) {
+ ConsumerGroupPartitionAssignor assignor;
+
+ if (object instanceof String klass) {
+ assignor = defaultAssignors.get(klass);
+ if (assignor == null) {
+ try {
+ assignor = Utils.newInstance(klass, ConsumerGroupPartitionAssignor.class);
+ } catch (ClassNotFoundException e) {
+ throw new KafkaException("Class " + klass + " cannot be found", e);
+ } catch (ClassCastException e) {
+ throw new KafkaException(klass + " is not an instance of " + ConsumerGroupPartitionAssignor.class.getName());
+ }
+ }
+ } else if (object instanceof Class<?> klass) {
+ Object o = Utils.newInstance((Class<?>) klass);
+ if (!(o instanceof ConsumerGroupPartitionAssignor)) {
+ throw new KafkaException(klass + " is not an instance of " + ConsumerGroupPartitionAssignor.class.getName());
}
+ assignor = (ConsumerGroupPartitionAssignor) o;
+ } else {
+ throw new KafkaException("Unexpected element of type " + object.getClass().getName() + ", expected String or Class");
}
assignors.add(assignor);
@@ -799,24 +802,16 @@ public class GroupCoordinatorConfig {
List<ShareGroupPartitionAssignor> assignors = new ArrayList<>();
try {
- // `configuredAssignor` is either the name of a built-in assignor,
- // or a fully qualified class name of a custom assignor
- for (String configuredAssignor : config.getList(GroupCoordinatorConfig.SHARE_GROUP_ASSIGNORS_CONFIG)) {
+ for (String kclass : config.getList(GroupCoordinatorConfig.SHARE_GROUP_ASSIGNORS_CONFIG)) {
ShareGroupPartitionAssignor assignor = SHARE_GROUP_BUILTIN_ASSIGNOR;
- if (!Objects.equals(configuredAssignor, SHARE_GROUP_ASSIGNORS_DEFAULT)) {
+ if (!Objects.equals(kclass, SHARE_GROUP_ASSIGNORS_DEFAULT)) {
try {
- assignor = Utils.newInstance(configuredAssignor, ShareGroupPartitionAssignor.class);
+ assignor = Utils.newInstance(kclass, ShareGroupPartitionAssignor.class);
} catch (ClassNotFoundException e) {
- throw new ConfigException(SHARE_GROUP_ASSIGNORS_CONFIG, configuredAssignor,
- "Class cannot be found");
+ throw new KafkaException("Class " + kclass + " cannot be found", e);
} catch (ClassCastException e) {
- throw new ConfigException(SHARE_GROUP_ASSIGNORS_CONFIG, configuredAssignor,
- "Class is not an instance of " + ShareGroupPartitionAssignor.class.getName());
- } catch (KafkaException e) {
- // Utils#newInstance reports instantiation failures, for example a missing
- // public no-argument constructor, without naming the config that caused them.
- throw new ConfigException(SHARE_GROUP_ASSIGNORS_CONFIG, configuredAssignor, e.getMessage());
+ throw new KafkaException(kclass + " is not an instance of " + ShareGroupPartitionAssignor.class.getName());
}
}
diff --git a/group-coordinator/src/test/java/org/apache/kafka/coordinator/group/GroupCoordinatorConfigTest.java b/group-coordinator/src/test/java/org/apache/kafka/coordinator/group/GroupCoordinatorConfigTest.java
index 67a229b151f..3444e7cd7c6 100644
--- a/group-coordinator/src/test/java/org/apache/kafka/coordinator/group/GroupCoordinatorConfigTest.java
+++ b/group-coordinator/src/test/java/org/apache/kafka/coordinator/group/GroupCoordinatorConfigTest.java
@@ -17,6 +17,7 @@
package org.apache.kafka.coordinator.group;
import org.apache.kafka.common.Configurable;
+import org.apache.kafka.common.KafkaException;
import org.apache.kafka.common.config.AbstractConfig;
import org.apache.kafka.common.config.ConfigException;
import org.apache.kafka.common.record.internal.CompressionType;
@@ -67,24 +68,6 @@ public class GroupCoordinatorConfigTest {
}
}
- public static class NoDefaultConstructorAssignor implements ConsumerGroupPartitionAssignor, ShareGroupPartitionAssignor {
- public NoDefaultConstructorAssignor(String unused) {
- }
-
- @Override
- public String name() {
- return "NoDefaultConstructorAssignor";
- }
-
- @Override
- public GroupAssignment assign(
- GroupSpec groupSpec,
- SubscribedTopicDescriber subscribedTopicDescriber
- ) throws PartitionAssignorException {
- return null;
- }
- }
-
@Test
public void testConsumerGroupAssignorFullClassNames() {
// The full class name of the assignors is part of our public api. Hence,
@@ -121,7 +104,15 @@ public class GroupCoordinatorConfigTest {
assertInstanceOf(CustomAssignor.class, assignors.get(0));
assertNotNull(((CustomAssignor) assignors.get(0)).configs);
- // Test combination of short name and class name as a comma-separated string.
+ // Test with classes.
+ configs.put(GroupCoordinatorConfig.CONSUMER_GROUP_ASSIGNORS_CONFIG, List.of(RangeAssignor.class, CustomAssignor.class));
+ config = createConfig(configs);
+ assignors = config.consumerGroupAssignors();
+ assertEquals(2, assignors.size());
+ assertInstanceOf(RangeAssignor.class, assignors.get(0));
+ assertInstanceOf(CustomAssignor.class, assignors.get(1));
+
+ // Test combination of short name and class.
configs.put(GroupCoordinatorConfig.CONSUMER_GROUP_ASSIGNORS_CONFIG, "uniform, " + CustomAssignor.class.getName());
config = createConfig(configs);
assignors = config.consumerGroupAssignors();
@@ -129,7 +120,7 @@ public class GroupCoordinatorConfigTest {
assertInstanceOf(UniformAssignor.class, assignors.get(0));
assertInstanceOf(CustomAssignor.class, assignors.get(1));
- // Test combination of short name and class name as a list of strings.
+ // Test combination of short name and class.
configs.put(GroupCoordinatorConfig.CONSUMER_GROUP_ASSIGNORS_CONFIG, List.of("uniform", CustomAssignor.class.getName()));
config = createConfig(configs);
assignors = config.consumerGroupAssignors();
@@ -178,24 +169,6 @@ public class GroupCoordinatorConfigTest {
configs.put(GroupCoordinatorConfig.SHARE_GROUP_ASSIGNORS_CONFIG, "simple, " + CustomAssignor.class.getName());
assertEquals("group.share.assignors must contain exactly one assignor, but found 2",
assertThrows(IllegalArgumentException.class, () -> createConfig(configs)).getMessage());
-
- // Test unknown class.
- configs.put(GroupCoordinatorConfig.SHARE_GROUP_ASSIGNORS_CONFIG, "foo");
- assertEquals("Invalid value foo for configuration group.share.assignors: Class cannot be found",
- assertThrows(ConfigException.class, () -> createConfig(configs)).getMessage());
-
- // Test class that is not an assignor.
- configs.put(GroupCoordinatorConfig.SHARE_GROUP_ASSIGNORS_CONFIG, Object.class.getName());
- assertEquals("Invalid value java.lang.Object for configuration group.share.assignors: " +
- "Class is not an instance of org.apache.kafka.coordinator.group.api.assignor.ShareGroupPartitionAssignor",
- assertThrows(ConfigException.class, () -> createConfig(configs)).getMessage());
-
- // Test class that cannot be instantiated.
- configs.put(GroupCoordinatorConfig.SHARE_GROUP_ASSIGNORS_CONFIG, NoDefaultConstructorAssignor.class.getName());
- assertEquals("Invalid value " + NoDefaultConstructorAssignor.class.getName() +
- " for configuration group.share.assignors: Could not find a public no-argument constructor for " +
- NoDefaultConstructorAssignor.class.getName(),
- assertThrows(ConfigException.class, () -> createConfig(configs)).getMessage());
}
@Test
@@ -207,7 +180,7 @@ public class GroupCoordinatorConfigTest {
configs.put(GroupCoordinatorConfig.CONSUMER_GROUP_SESSION_TIMEOUT_MS_CONFIG, 555);
configs.put(GroupCoordinatorConfig.CONSUMER_GROUP_HEARTBEAT_INTERVAL_MS_CONFIG, 200);
configs.put(GroupCoordinatorConfig.CONSUMER_GROUP_MAX_SIZE_CONFIG, 55);
- configs.put(GroupCoordinatorConfig.CONSUMER_GROUP_ASSIGNORS_CONFIG, List.of(RangeAssignor.class.getName()));
+ configs.put(GroupCoordinatorConfig.CONSUMER_GROUP_ASSIGNORS_CONFIG, List.of(RangeAssignor.class));
configs.put(GroupCoordinatorConfig.OFFSETS_TOPIC_SEGMENT_BYTES_CONFIG, 2222);
configs.put(GroupCoordinatorConfig.OFFSET_METADATA_MAX_SIZE_CONFIG, 3333);
configs.put(GroupCoordinatorConfig.GROUP_MAX_SIZE_CONFIG, 60);
@@ -331,22 +304,19 @@ public class GroupCoordinatorConfigTest {
assertThrows(ConfigException.class, () -> createConfig(configs)).getMessage());
configs.clear();
- configs.put(GroupCoordinatorConfig.CONSUMER_GROUP_ASSIGNORS_CONFIG, Object.class.getName());
- assertEquals("Invalid value java.lang.Object for configuration group.consumer.assignors: " +
- "Class is not an instance of org.apache.kafka.coordinator.group.api.assignor.ConsumerGroupPartitionAssignor",
- assertThrows(ConfigException.class, () -> createConfig(configs)).getMessage());
+ configs.put(GroupCoordinatorConfig.CONSUMER_GROUP_ASSIGNORS_CONFIG, List.of(Object.class));
+ assertEquals("class java.lang.Object is not an instance of org.apache.kafka.coordinator.group.api.assignor.ConsumerGroupPartitionAssignor",
+ assertThrows(KafkaException.class, () -> createConfig(configs)).getMessage());
configs.clear();
- configs.put(GroupCoordinatorConfig.CONSUMER_GROUP_ASSIGNORS_CONFIG, "foo");
- assertEquals("Invalid value foo for configuration group.consumer.assignors: Class cannot be found",
- assertThrows(ConfigException.class, () -> createConfig(configs)).getMessage());
+ configs.put(GroupCoordinatorConfig.CONSUMER_GROUP_ASSIGNORS_CONFIG, Object.class.getName());
+ assertEquals("java.lang.Object is not an instance of org.apache.kafka.coordinator.group.api.assignor.ConsumerGroupPartitionAssignor",
+ assertThrows(KafkaException.class, () -> createConfig(configs)).getMessage());
configs.clear();
- configs.put(GroupCoordinatorConfig.CONSUMER_GROUP_ASSIGNORS_CONFIG, NoDefaultConstructorAssignor.class.getName());
- assertEquals("Invalid value " + NoDefaultConstructorAssignor.class.getName() +
- " for configuration group.consumer.assignors: Could not find a public no-argument constructor for " +
- NoDefaultConstructorAssignor.class.getName(),
- assertThrows(ConfigException.class, () -> createConfig(configs)).getMessage());
+ configs.put(GroupCoordinatorConfig.CONSUMER_GROUP_ASSIGNORS_CONFIG, "foo");
+ assertEquals("Class foo cannot be found",
+ assertThrows(KafkaException.class, () -> createConfig(configs)).getMessage());
configs.clear();
configs.put(GroupCoordinatorConfig.CONSUMER_GROUP_MIGRATION_POLICY_CONFIG, "foobar");
@@ -654,7 +624,7 @@ public class GroupCoordinatorConfigTest {
configs.put(GroupCoordinatorConfig.CONSUMER_GROUP_HEARTBEAT_INTERVAL_MS_CONFIG, 5);
configs.put(GroupCoordinatorConfig.CONSUMER_GROUP_MIN_HEARTBEAT_INTERVAL_MS_CONFIG, 5);
configs.put(GroupCoordinatorConfig.CONSUMER_GROUP_MAX_SIZE_CONFIG, Integer.MAX_VALUE);
- configs.put(GroupCoordinatorConfig.CONSUMER_GROUP_ASSIGNORS_CONFIG, List.of(RangeAssignor.class.getName()));
+ configs.put(GroupCoordinatorConfig.CONSUMER_GROUP_ASSIGNORS_CONFIG, List.of(RangeAssignor.class));
configs.put(GroupCoordinatorConfig.OFFSETS_TOPIC_SEGMENT_BYTES_CONFIG, 1000);
configs.put(GroupCoordinatorConfig.OFFSET_METADATA_MAX_SIZE_CONFIG, offsetMetadataMaxSize);
configs.put(GroupCoordinatorConfig.GROUP_MAX_SIZE_CONFIG, Integer.MAX_VALUE);