-
Notifications
You must be signed in to change notification settings - Fork 15.1k
KAFKA-10028: Implement write path for feature versioning system (KIP-584) #9001
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
824e2f7
Implement KIP-584 write path
kowshik cc23765
Fix checkstyle issues
kowshik 114e24d
Minor: Improved comment
kowshik 9af2a01
Minor: cosmetics
kowshik afa3ab9
Fix small bug
kowshik 59d8038
Minor: improve one of the tests slightly to handle +1 case
kowshik 9cdfc31
Address comments from Boyang
kowshik 08f064b
Minor: add missing header in UpdateFeaturesTest.scala
kowshik 6b9e237
Minor cosmetic changes
kowshik c2772a1
Address comments from Boyang
kowshik 7620c88
Minor: Remove newline
kowshik 89372ba
Minor: cosmetics
kowshik 78bfc4c
Minor: Remove unused imports to fix checkstyle issues
kowshik c3201a1
Minor cosmetics to fix checkstyle issue
kowshik 7a7f716
Minor cosmetics
kowshik 7afd81b
Minor: improve code slightly in KafkaController
kowshik cec2505
Address review comments from Boyang
kowshik 3b4b370
Minor cosmetics
kowshik 2a1dee2
Minor cosmetics
kowshik a7c32a0
Address latest review comments
kowshik 4729737
Fix checkstyle issues for CI
kowshik deaad42
Small improvements
kowshik 21491b2
Rebase on latest AK trunk
kowshik 8ec01e7
Fix checkstyle issue
kowshik 436d816
Remove unused code
kowshik 1150a1f
Reinstante timeoutMs & change FinalizedFeaturesEpoch to long data type
kowshik 45372f3
Minor improvements
kowshik 389b7aa
Cosmetics
kowshik 5f3af18
Small improvement
kowshik 4d067f9
Implement firstActiveVersion
kowshik 3342f14
Small doc change
kowshik 3c59a17
Address comments from Jun
kowshik cc378c6
Address comments from Boyang
kowshik 116352b
Address comments from Jun
kowshik 50f53dd
Address comment from Jun: Revert firstActiveVersion change
kowshik 0ba831d
Minor change to code format
kowshik c821e85
Fix ControllerIntegrationTest
kowshik 5e3fc96
Minor cosmetic changes
kowshik 3c5c04f
Address comments from Jun
kowshik b69f7fe
Minor formatting change
kowshik e1c79ce
Address comments from Jun
kowshik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
clients/src/main/java/org/apache/kafka/clients/admin/DescribeFeaturesOptions.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.kafka.clients.admin; | ||
|
|
||
| import org.apache.kafka.common.annotation.InterfaceStability; | ||
|
|
||
| /** | ||
| * Options for {@link AdminClient#describeFeatures(DescribeFeaturesOptions)}. | ||
| * | ||
| * The API of this class is evolving. See {@link Admin} for details. | ||
| */ | ||
| @InterfaceStability.Evolving | ||
| public class DescribeFeaturesOptions extends AbstractOptions<DescribeFeaturesOptions> { | ||
|
kowshik marked this conversation as resolved.
Outdated
kowshik marked this conversation as resolved.
Outdated
|
||
|
|
||
| /** | ||
| * - True means the {@link Admin#describeFeatures(DescribeFeaturesOptions)} request must be | ||
| * issued only to the controller. | ||
| * - False means the {@link Admin#describeFeatures(DescribeFeaturesOptions)} request can be | ||
|
kowshik marked this conversation as resolved.
Outdated
|
||
| * issued to any random broker. | ||
| */ | ||
| private boolean sendRequestToController = false; | ||
|
|
||
| /** | ||
| * Sets a flag indicating that the describe features request must be issued only to the controller. | ||
| */ | ||
| public DescribeFeaturesOptions sendRequestToController(boolean sendRequestToController) { | ||
| this.sendRequestToController = sendRequestToController; | ||
| return this; | ||
| } | ||
|
|
||
| public boolean sendRequestToController() { | ||
| return sendRequestToController; | ||
| } | ||
| } | ||
37 changes: 37 additions & 0 deletions
37
clients/src/main/java/org/apache/kafka/clients/admin/DescribeFeaturesResult.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.kafka.clients.admin; | ||
|
|
||
| import org.apache.kafka.common.KafkaFuture; | ||
|
|
||
| /** | ||
| * The result of the {@link Admin#describeFeatures(DescribeFeaturesOptions)} call. | ||
| * | ||
| * The API of this class is evolving, see {@link Admin} for details. | ||
| */ | ||
| public class DescribeFeaturesResult { | ||
|
|
||
| private final KafkaFuture<FeatureMetadata> future; | ||
|
|
||
| DescribeFeaturesResult(KafkaFuture<FeatureMetadata> future) { | ||
| this.future = future; | ||
| } | ||
|
|
||
| public KafkaFuture<FeatureMetadata> featureMetadata() { | ||
| return future; | ||
| } | ||
| } |
111 changes: 111 additions & 0 deletions
111
clients/src/main/java/org/apache/kafka/clients/admin/FeatureMetadata.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.kafka.clients.admin; | ||
|
|
||
| import static java.util.stream.Collectors.joining; | ||
|
|
||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
| import java.util.Objects; | ||
| import java.util.Optional; | ||
|
|
||
| /** | ||
| * Encapsulates details about finalized as well as supported features. This is particularly useful | ||
| * to hold the result returned by the {@link Admin#describeFeatures(DescribeFeaturesOptions)} API. | ||
|
kowshik marked this conversation as resolved.
Outdated
|
||
| */ | ||
| public class FeatureMetadata { | ||
|
kowshik marked this conversation as resolved.
Outdated
|
||
|
|
||
| private final Map<String, FinalizedVersionRange> finalizedFeatures; | ||
|
|
||
| private final Optional<Long> finalizedFeaturesEpoch; | ||
|
|
||
| private final Map<String, SupportedVersionRange> supportedFeatures; | ||
|
|
||
| FeatureMetadata(final Map<String, FinalizedVersionRange> finalizedFeatures, | ||
| final Optional<Long> finalizedFeaturesEpoch, | ||
| final Map<String, SupportedVersionRange> supportedFeatures) { | ||
| this.finalizedFeatures = new HashMap<>(finalizedFeatures); | ||
| this.finalizedFeaturesEpoch = finalizedFeaturesEpoch; | ||
| this.supportedFeatures = new HashMap<>(supportedFeatures); | ||
| } | ||
|
|
||
| /** | ||
| * Returns a map of finalized feature versions. Each entry in the map contains a key being a | ||
| * feature name and the value being a range of version levels supported by every broker in the | ||
| * cluster. | ||
| */ | ||
| public Map<String, FinalizedVersionRange> finalizedFeatures() { | ||
| return new HashMap<>(finalizedFeatures); | ||
| } | ||
|
|
||
| /** | ||
| * The epoch for the finalized features. | ||
| * If the returned value is empty, it means the finalized features are absent/unavailable. | ||
| */ | ||
| public Optional<Long> finalizedFeaturesEpoch() { | ||
| return finalizedFeaturesEpoch; | ||
| } | ||
|
|
||
| /** | ||
| * Returns a map of supported feature versions. Each entry in the map contains a key being a | ||
| * feature name and the value being a range of versions supported by a particular broker in the | ||
| * cluster. | ||
| */ | ||
| public Map<String, SupportedVersionRange> supportedFeatures() { | ||
| return new HashMap<>(supportedFeatures); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object other) { | ||
| if (this == other) { | ||
| return true; | ||
| } | ||
| if (!(other instanceof FeatureMetadata)) { | ||
| return false; | ||
| } | ||
|
|
||
| final FeatureMetadata that = (FeatureMetadata) other; | ||
| return Objects.equals(this.finalizedFeatures, that.finalizedFeatures) && | ||
| Objects.equals(this.finalizedFeaturesEpoch, that.finalizedFeaturesEpoch) && | ||
| Objects.equals(this.supportedFeatures, that.supportedFeatures); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(finalizedFeatures, finalizedFeaturesEpoch, supportedFeatures); | ||
| } | ||
|
|
||
| private static <ValueType> String mapToString(final Map<String, ValueType> featureVersionsMap) { | ||
| return String.format( | ||
| "{%s}", | ||
| featureVersionsMap | ||
| .entrySet() | ||
| .stream() | ||
| .map(entry -> String.format("(%s -> %s)", entry.getKey(), entry.getValue())) | ||
| .collect(joining(", ")) | ||
| ); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return String.format( | ||
| "FeatureMetadata{finalizedFeatures:%s, finalizedFeaturesEpoch:%s, supportedFeatures:%s}", | ||
| mapToString(finalizedFeatures), | ||
| finalizedFeaturesEpoch.map(Object::toString).orElse("<none>"), | ||
| mapToString(supportedFeatures)); | ||
| } | ||
| } | ||
78 changes: 78 additions & 0 deletions
78
clients/src/main/java/org/apache/kafka/clients/admin/FeatureUpdate.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.kafka.clients.admin; | ||
|
|
||
| import java.util.Objects; | ||
|
|
||
| /** | ||
| * Encapsulates details about an update to a finalized feature. | ||
| */ | ||
| public class FeatureUpdate { | ||
|
kowshik marked this conversation as resolved.
Outdated
|
||
| private final short maxVersionLevel; | ||
| private final boolean allowDowngrade; | ||
|
|
||
| /** | ||
| * @param maxVersionLevel the new maximum version level for the finalized feature. | ||
| * a value < 1 is special and indicates that the update is intended to | ||
| * delete the finalized feature, and should be accompanied by setting | ||
| * the allowDowngrade flag to true. | ||
| * @param allowDowngrade - true, if this feature update was meant to downgrade the existing | ||
| * maximum version level of the finalized feature. | ||
| * - false, otherwise. | ||
| */ | ||
| public FeatureUpdate(final short maxVersionLevel, final boolean allowDowngrade) { | ||
| if (maxVersionLevel < 1 && !allowDowngrade) { | ||
| throw new IllegalArgumentException(String.format( | ||
| "The allowDowngrade flag should be set when the provided maxVersionLevel:%d is < 1.", | ||
| maxVersionLevel)); | ||
| } | ||
| this.maxVersionLevel = maxVersionLevel; | ||
| this.allowDowngrade = allowDowngrade; | ||
| } | ||
|
|
||
| public short maxVersionLevel() { | ||
| return maxVersionLevel; | ||
| } | ||
|
|
||
| public boolean allowDowngrade() { | ||
| return allowDowngrade; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object other) { | ||
| if (this == other) { | ||
| return true; | ||
| } | ||
|
|
||
| if (!(other instanceof FeatureUpdate)) { | ||
| return false; | ||
| } | ||
|
|
||
| final FeatureUpdate that = (FeatureUpdate) other; | ||
| return this.maxVersionLevel == that.maxVersionLevel && this.allowDowngrade == that.allowDowngrade; | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(maxVersionLevel, allowDowngrade); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return String.format("FeatureUpdate{maxVersionLevel:%d, allowDowngrade:%s}", maxVersionLevel, allowDowngrade); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.