Skip to content

Commit 21a080f

Browse files
KAFKA-16894: Define feature to enable share groups (#19293)
This PR proposes a switch to enable share groups for 4.1 (preview) and 4.2 (GA). * `share.version=1` to indicate that share groups are enabled. This is used as the switch for turning share groups on and off. In 4.1, the default will be `share.version=0`. Then a user wanting to evaluate the preview of KIP-932 would use `bin/kafka-features.sh --bootstrap.server xxxx upgrade --feature share.version=1`. In 4.2, the default will be `share.version=1`. Reviewers: Jun Rao <[email protected]>
1 parent 3e0276e commit 21a080f

File tree

10 files changed

+121
-13
lines changed

10 files changed

+121
-13
lines changed

core/src/test/scala/unit/kafka/server/AbstractApiVersionsRequestTest.scala

+6-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import org.apache.kafka.common.protocol.ApiKeys
2525
import org.apache.kafka.common.requests.{ApiVersionsRequest, ApiVersionsResponse, RequestUtils}
2626
import org.apache.kafka.common.test.ClusterInstance
2727
import org.apache.kafka.common.utils.Utils
28-
import org.apache.kafka.server.common.{EligibleLeaderReplicasVersion, GroupVersion, MetadataVersion, TransactionVersion}
28+
import org.apache.kafka.server.common.{EligibleLeaderReplicasVersion, GroupVersion, MetadataVersion, ShareVersion, TransactionVersion}
2929
import org.apache.kafka.test.TestUtils
3030
import org.junit.jupiter.api.Assertions._
3131
import org.junit.jupiter.api.Tag
@@ -64,11 +64,11 @@ abstract class AbstractApiVersionsRequestTest(cluster: ClusterInstance) {
6464
apiVersion: Short = ApiKeys.API_VERSIONS.latestVersion
6565
): Unit = {
6666
if (apiVersion >= 3) {
67-
assertEquals(4, apiVersionsResponse.data().finalizedFeatures().size())
67+
assertEquals(5, apiVersionsResponse.data().finalizedFeatures().size())
6868
assertEquals(MetadataVersion.latestTesting().featureLevel(), apiVersionsResponse.data().finalizedFeatures().find(MetadataVersion.FEATURE_NAME).minVersionLevel())
6969
assertEquals(MetadataVersion.latestTesting().featureLevel(), apiVersionsResponse.data().finalizedFeatures().find(MetadataVersion.FEATURE_NAME).maxVersionLevel())
7070

71-
assertEquals(5, apiVersionsResponse.data().supportedFeatures().size())
71+
assertEquals(6, apiVersionsResponse.data().supportedFeatures().size())
7272
assertEquals(MetadataVersion.MINIMUM_VERSION.featureLevel(), apiVersionsResponse.data().supportedFeatures().find(MetadataVersion.FEATURE_NAME).minVersion())
7373
if (apiVersion < 4) {
7474
assertEquals(1, apiVersionsResponse.data().supportedFeatures().find("kraft.version").minVersion())
@@ -85,6 +85,9 @@ abstract class AbstractApiVersionsRequestTest(cluster: ClusterInstance) {
8585

8686
assertEquals(0, apiVersionsResponse.data().supportedFeatures().find(EligibleLeaderReplicasVersion.FEATURE_NAME).minVersion())
8787
assertEquals(EligibleLeaderReplicasVersion.ELRV_1.featureLevel(), apiVersionsResponse.data().supportedFeatures().find(EligibleLeaderReplicasVersion.FEATURE_NAME).maxVersion())
88+
89+
assertEquals(0, apiVersionsResponse.data().supportedFeatures().find(ShareVersion.FEATURE_NAME).minVersion())
90+
assertEquals(ShareVersion.SV_1.featureLevel(), apiVersionsResponse.data().supportedFeatures().find(ShareVersion.FEATURE_NAME).maxVersion())
8891
}
8992
val expectedApis = if (cluster.controllerListenerName().toScala.contains(listenerName)) {
9093
ApiVersionsResponse.collectApis(

core/src/test/scala/unit/kafka/tools/StorageToolTest.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ Found problem:
325325
properties.putAll(defaultStaticQuorumProperties)
326326
properties.setProperty("log.dirs", availableDirs.mkString(","))
327327
assertEquals("Unsupported feature: non.existent.feature. Supported features are: " +
328-
"eligible.leader.replicas.version, group.version, kraft.version, transaction.version",
328+
"eligible.leader.replicas.version, group.version, kraft.version, share.version, transaction.version",
329329
assertThrows(classOf[FormatterException], () =>
330330
runFormatCommand(new ByteArrayOutputStream(), properties,
331331
Seq("--feature", "non.existent.feature=20"))).getMessage)

metadata/src/test/java/org/apache/kafka/controller/FeatureControlManagerTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ public void testCannotDowngradeBeforeMinimumKraftVersion() {
387387
build();
388388
manager.replay(new FeatureLevelRecord().setName(MetadataVersion.FEATURE_NAME).setFeatureLevel(MetadataVersion.MINIMUM_VERSION.featureLevel()));
389389
assertEquals(ControllerResult.of(List.of(), new ApiError(Errors.INVALID_UPDATE_VERSION,
390-
"Invalid update version 6 for feature metadata.version. Local controller 0 only supports versions 7-26")),
390+
"Invalid update version 6 for feature metadata.version. Local controller 0 only supports versions 7-28")),
391391
manager.updateFeatures(
392392
Map.of(MetadataVersion.FEATURE_NAME, MetadataVersionTestUtils.IBP_3_3_IV2_FEATURE_LEVEL),
393393
Map.of(MetadataVersion.FEATURE_NAME, FeatureUpdate.UpgradeType.UNSAFE_DOWNGRADE),

metadata/src/test/java/org/apache/kafka/metadata/storage/FormatterTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ public void testInvalidFeatureFlag() throws Exception {
368368
formatter1.formatter.setFeatureLevel("nonexistent.feature", (short) 1);
369369
assertEquals("Unsupported feature: nonexistent.feature. Supported features " +
370370
"are: eligible.leader.replicas.version, group.version, kraft.version, " +
371-
"test.feature.version, transaction.version",
371+
"share.version, test.feature.version, transaction.version",
372372
assertThrows(FormatterException.class,
373373
() -> formatter1.formatter.run()).
374374
getMessage());

server-common/src/main/java/org/apache/kafka/server/common/Feature.java

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public enum Feature {
4747
TRANSACTION_VERSION(TransactionVersion.FEATURE_NAME, TransactionVersion.values(), TransactionVersion.LATEST_PRODUCTION),
4848
GROUP_VERSION(GroupVersion.FEATURE_NAME, GroupVersion.values(), GroupVersion.LATEST_PRODUCTION),
4949
ELIGIBLE_LEADER_REPLICAS_VERSION(EligibleLeaderReplicasVersion.FEATURE_NAME, EligibleLeaderReplicasVersion.values(), EligibleLeaderReplicasVersion.LATEST_PRODUCTION),
50+
SHARE_VERSION(ShareVersion.FEATURE_NAME, ShareVersion.values(), ShareVersion.LATEST_PRODUCTION),
5051

5152
/**
5253
* Features defined only for unit tests and are not used in production.

server-common/src/main/java/org/apache/kafka/server/common/MetadataVersion.java

+16-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,22 @@ public enum MetadataVersion {
112112
//
113113

114114
// Enables ELR by default for new clusters (KIP-966).
115-
IBP_4_1_IV0(26, "4.1", "IV0", false);
115+
IBP_4_1_IV0(26, "4.1", "IV0", false),
116+
117+
// Enables share groups. Note, share groups are for preview only in 4.1. (KIP-932).
118+
IBP_4_1_IV1(27, "4.1", "IV1", false),
119+
120+
// Insert any additional IBP_4_1_IVx versions above this comment, and bump the feature level of
121+
// IBP_4_2_IV0 accordingly. When 4.2 development begins, IBP_4_2_IV0 will cease to be
122+
// a placeholder.
123+
124+
// Enables share groups by default for new clusters (KIP-932).
125+
//
126+
// *** THIS IS A PLACEHOLDER UNSTABLE VERSION WHICH IS USED TO DEFINE THE POINT AT WHICH ***
127+
// *** SHARE GROUPS BECOME PRODUCTION-READY IN THE FUTURE. ITS DEFINITION ALLOWS A SHARE ***
128+
// *** GROUPS FEATURE TO BE DEFINED IN 4.1 BUT TURNED OFF BY DEFAULT, ABLE TO BE TURNED ON ***
129+
// *** DYNAMICALLY TO TRY OUT THE PREVIEW CAPABILITY. ***
130+
IBP_4_2_IV0(28, "4.2", "IV0", false);
116131

117132
// NOTES when adding a new version:
118133
// Update the default version in @ClusterTest annotation to point to the latest version
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.kafka.server.common;
18+
19+
import java.util.Map;
20+
21+
public enum ShareVersion implements FeatureVersion {
22+
23+
// Version 0 does not enable share groups.
24+
SV_0(0, MetadataVersion.MINIMUM_VERSION, Map.of()),
25+
26+
// Version 1 enables share groups (KIP-932).
27+
// This is a preview in 4.1, and production-ready in 4.2.
28+
SV_1(1, MetadataVersion.IBP_4_2_IV0, Map.of(MetadataVersion.FEATURE_NAME, MetadataVersion.IBP_4_1_IV1.featureLevel()));
29+
30+
public static final String FEATURE_NAME = "share.version";
31+
32+
public static final ShareVersion LATEST_PRODUCTION = SV_0;
33+
34+
private final short featureLevel;
35+
private final MetadataVersion bootstrapMetadataVersion;
36+
private final Map<String, Short> dependencies;
37+
38+
ShareVersion(
39+
int featureLevel,
40+
MetadataVersion bootstrapMetadataVersion,
41+
Map<String, Short> dependencies
42+
) {
43+
this.featureLevel = (short) featureLevel;
44+
this.bootstrapMetadataVersion = bootstrapMetadataVersion;
45+
this.dependencies = dependencies;
46+
}
47+
48+
@Override
49+
public short featureLevel() {
50+
return featureLevel;
51+
}
52+
53+
@Override
54+
public String featureName() {
55+
return FEATURE_NAME;
56+
}
57+
58+
@Override
59+
public MetadataVersion bootstrapMetadataVersion() {
60+
return bootstrapMetadataVersion;
61+
}
62+
63+
@Override
64+
public Map<String, Short> dependencies() {
65+
return dependencies;
66+
}
67+
68+
public boolean supportsShareGroups() {
69+
return featureLevel >= SV_1.featureLevel;
70+
}
71+
72+
public static ShareVersion fromFeatureLevel(short version) {
73+
switch (version) {
74+
case 0:
75+
return SV_0;
76+
case 1:
77+
return SV_1;
78+
default:
79+
throw new RuntimeException("Unknown share feature level: " + (int) version);
80+
}
81+
}
82+
}

server/src/test/java/org/apache/kafka/server/BrokerFeaturesTest.java

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
import static org.apache.kafka.server.common.Feature.ELIGIBLE_LEADER_REPLICAS_VERSION;
3131
import static org.apache.kafka.server.common.Feature.GROUP_VERSION;
32+
import static org.apache.kafka.server.common.Feature.SHARE_VERSION;
3233
import static org.apache.kafka.server.common.Feature.TRANSACTION_VERSION;
3334
import static org.junit.jupiter.api.Assertions.assertEquals;
3435
import static org.junit.jupiter.api.Assertions.assertFalse;
@@ -97,6 +98,7 @@ public void testDefaultFinalizedFeatures() {
9798
TRANSACTION_VERSION.featureName(), TRANSACTION_VERSION.latestTesting(),
9899
GROUP_VERSION.featureName(), GROUP_VERSION.latestTesting(),
99100
ELIGIBLE_LEADER_REPLICAS_VERSION.featureName(), ELIGIBLE_LEADER_REPLICAS_VERSION.latestTesting(),
101+
SHARE_VERSION.featureName(), SHARE_VERSION.latestTesting(),
100102
"kraft.version", (short) 0,
101103
"test_feature_1", (short) 4,
102104
"test_feature_2", (short) 3,

test-common/test-common-internal-api/src/main/java/org/apache/kafka/common/test/api/ClusterTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
String brokerListener() default DEFAULT_BROKER_LISTENER_NAME;
5353
SecurityProtocol controllerSecurityProtocol() default SecurityProtocol.PLAINTEXT;
5454
String controllerListener() default DEFAULT_CONTROLLER_LISTENER_NAME;
55-
MetadataVersion metadataVersion() default MetadataVersion.IBP_4_1_IV0;
55+
MetadataVersion metadataVersion() default MetadataVersion.IBP_4_2_IV0;
5656
ClusterConfigProperty[] serverProperties() default {};
5757
// users can add tags that they want to display in test
5858
String[] tags() default {};

tools/src/test/java/org/apache/kafka/tools/FeatureCommandTest.java

+10-5
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,11 @@ public void testDescribeWithKRaft(ClusterInstance cluster) {
6464
assertEquals("Feature: kraft.version\tSupportedMinVersion: 0\t" +
6565
"SupportedMaxVersion: 1\tFinalizedVersionLevel: 0\t", outputWithoutEpoch(features.get(2)));
6666
assertEquals("Feature: metadata.version\tSupportedMinVersion: 3.3-IV3\t" +
67-
"SupportedMaxVersion: 4.1-IV0\tFinalizedVersionLevel: 3.3-IV3\t", outputWithoutEpoch(features.get(3)));
67+
"SupportedMaxVersion: 4.2-IV0\tFinalizedVersionLevel: 3.3-IV3\t", outputWithoutEpoch(features.get(3)));
68+
assertEquals("Feature: share.version\tSupportedMinVersion: 0\t" +
69+
"SupportedMaxVersion: 1\tFinalizedVersionLevel: 0\t", outputWithoutEpoch(features.get(4)));
6870
assertEquals("Feature: transaction.version\tSupportedMinVersion: 0\t" +
69-
"SupportedMaxVersion: 2\tFinalizedVersionLevel: 0\t", outputWithoutEpoch(features.get(4)));
71+
"SupportedMaxVersion: 2\tFinalizedVersionLevel: 0\t", outputWithoutEpoch(features.get(5)));
7072
}
7173

7274
// Use the first MetadataVersion that supports KIP-919
@@ -86,9 +88,11 @@ public void testDescribeWithKRaftAndBootstrapControllers(ClusterInstance cluster
8688
assertEquals("Feature: kraft.version\tSupportedMinVersion: 0\t" +
8789
"SupportedMaxVersion: 1\tFinalizedVersionLevel: 0\t", outputWithoutEpoch(features.get(2)));
8890
assertEquals("Feature: metadata.version\tSupportedMinVersion: 3.3-IV3\t" +
89-
"SupportedMaxVersion: 4.1-IV0\tFinalizedVersionLevel: 3.7-IV0\t", outputWithoutEpoch(features.get(3)));
91+
"SupportedMaxVersion: 4.2-IV0\tFinalizedVersionLevel: 3.7-IV0\t", outputWithoutEpoch(features.get(3)));
92+
assertEquals("Feature: share.version\tSupportedMinVersion: 0\t" +
93+
"SupportedMaxVersion: 1\tFinalizedVersionLevel: 0\t", outputWithoutEpoch(features.get(4)));
9094
assertEquals("Feature: transaction.version\tSupportedMinVersion: 0\t" +
91-
"SupportedMaxVersion: 2\tFinalizedVersionLevel: 0\t", outputWithoutEpoch(features.get(4)));
95+
"SupportedMaxVersion: 2\tFinalizedVersionLevel: 0\t", outputWithoutEpoch(features.get(5)));
9296
}
9397

9498
@ClusterTest(types = {Type.KRAFT}, metadataVersion = MetadataVersion.IBP_3_3_IV3)
@@ -114,7 +118,7 @@ public void testDowngradeMetadataVersionWithKRaft(ClusterInstance cluster) {
114118
);
115119
// Change expected message to reflect possible MetadataVersion range 1-N (N increases when adding a new version)
116120
assertEquals("Could not disable metadata.version. The update failed for all features since the following " +
117-
"feature had an error: Invalid update version 0 for feature metadata.version. Local controller 3000 only supports versions 7-26", commandOutput);
121+
"feature had an error: Invalid update version 0 for feature metadata.version. Local controller 3000 only supports versions 7-28", commandOutput);
118122

119123
commandOutput = ToolsTestUtils.captureStandardOut(() ->
120124
assertEquals(1, FeatureCommand.mainNoExit("--bootstrap-server", cluster.bootstrapServers(),
@@ -177,6 +181,7 @@ public void testDowngradeWithReleaseVersion(ClusterInstance cluster) {
177181
"group.version was downgraded to 0.\n" +
178182
"kraft.version was downgraded to 0.\n" +
179183
"metadata.version was downgraded to 18.\n" +
184+
"share.version was downgraded to 0.\n" +
180185
"transaction.version was downgraded to 0.", commandOutput);
181186
}
182187

0 commit comments

Comments
 (0)