-
Notifications
You must be signed in to change notification settings - Fork 15.4k
KAFKA-17011: Fix a bug preventing features from supporting v0 #16421
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 3 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
1c1e556
KAFKA-17011: Fix a bug preventing features from supporting v0
cmccabe 6235178
pass through the ApiVersionsResponse version to ChannelBuilders
cmccabe 1dc5f99
Update NetworkClientTest
cmccabe c0e3c7c
Merge branch 'trunk' into KAFKA-17011
cmccabe 3e07a3b
Add BrokerRegistrationRequest v4
cmccabe ab1b566
Address review comments
cmccabe 234ea4b
address review feedback
cmccabe 04ecd25
Merge branch 'trunk' into KAFKA-17011
cmccabe 890c184
change approach to KAFKA-17011
cmccabe 6ad6749
fixes
cmccabe c1ba1f5
Merge branch 'trunk' into KAFKA-17011
cmccabe 85a827a
address comments
cmccabe d6eb186
fix tests
cmccabe f4bd3cc
fix tests etc.
cmccabe 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
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
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 |
|---|---|---|
|
|
@@ -35,6 +35,7 @@ | |
|
|
||
| import java.nio.ByteBuffer; | ||
| import java.util.Map; | ||
| import java.util.Objects; | ||
| import java.util.Optional; | ||
| import java.util.Set; | ||
|
|
||
|
|
@@ -49,6 +50,71 @@ public class ApiVersionsResponse extends AbstractResponse { | |
|
|
||
| private final ApiVersionsResponseData data; | ||
|
|
||
| public static class Builder { | ||
| private Errors error = Errors.NONE; | ||
| private int throttleTimeMs = 0; | ||
| private ApiVersionCollection apiVersions = null; | ||
| private Features<SupportedVersionRange> supportedFeatures = null; | ||
| private Map<String, Short> finalizedFeatures = null; | ||
| private long finalizedFeaturesEpoch = 0; | ||
| private boolean zkMigrationEnabled = false; | ||
| private boolean suppressFeatureLevel0 = false; | ||
|
|
||
| public Builder setError(Errors error) { | ||
| this.error = error; | ||
| return this; | ||
| } | ||
|
|
||
| public Builder setThrottleTimeMs(int throttleTimeMs) { | ||
| this.throttleTimeMs = throttleTimeMs; | ||
| return this; | ||
| } | ||
|
|
||
| public Builder setApiVersions(ApiVersionCollection apiVersions) { | ||
| this.apiVersions = apiVersions; | ||
| return this; | ||
| } | ||
|
|
||
| public Builder setSupportedFeatures(Features<SupportedVersionRange> supportedFeatures) { | ||
| this.supportedFeatures = supportedFeatures; | ||
| return this; | ||
| } | ||
|
|
||
| public Builder setFinalizedFeatures(Map<String, Short> finalizedFeatures) { | ||
| this.finalizedFeatures = finalizedFeatures; | ||
| return this; | ||
| } | ||
|
|
||
| public Builder setFinalizedFeaturesEpoch(long finalizedFeaturesEpoch) { | ||
| this.finalizedFeaturesEpoch = finalizedFeaturesEpoch; | ||
| return this; | ||
| } | ||
|
|
||
| public Builder setZkMigrationEnabled(boolean zkMigrationEnabled) { | ||
| this.zkMigrationEnabled = zkMigrationEnabled; | ||
| return this; | ||
| } | ||
|
|
||
| public Builder setSuppressFeatureLevel0(boolean suppressFeatureLevel0) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suppressFeatureLevel0 => alterFeatureLevel0 ? |
||
| this.suppressFeatureLevel0 = suppressFeatureLevel0; | ||
| return this; | ||
| } | ||
|
|
||
| public ApiVersionsResponse build() { | ||
| final ApiVersionsResponseData data = new ApiVersionsResponseData(); | ||
| data.setErrorCode(error.code()); | ||
| data.setApiKeys(Objects.requireNonNull(apiVersions)); | ||
| data.setThrottleTimeMs(throttleTimeMs); | ||
| data.setSupportedFeatures( | ||
| createSupportedFeatureKeys(Objects.requireNonNull(supportedFeatures), suppressFeatureLevel0)); | ||
| data.setFinalizedFeatures( | ||
| createFinalizedFeatureKeys(Objects.requireNonNull(finalizedFeatures))); | ||
| data.setFinalizedFeaturesEpoch(finalizedFeaturesEpoch); | ||
| data.setZkMigrationReady(zkMigrationEnabled); | ||
| return new ApiVersionsResponse(data); | ||
| } | ||
| } | ||
|
|
||
| public ApiVersionsResponse(ApiVersionsResponseData data) { | ||
| super(ApiKeys.API_VERSIONS); | ||
| this.data = data; | ||
|
|
@@ -105,65 +171,32 @@ public static ApiVersionsResponse parse(ByteBuffer buffer, short version) { | |
| } | ||
| } | ||
|
|
||
| public static ApiVersionsResponse createApiVersionsResponse( | ||
| int throttleTimeMs, | ||
| public static ApiVersionCollection controllerApiVersions( | ||
| RecordVersion minRecordVersion, | ||
| Features<SupportedVersionRange> latestSupportedFeatures, | ||
| Map<String, Short> finalizedFeatures, | ||
| long finalizedFeaturesEpoch, | ||
| NodeApiVersions controllerApiVersions, | ||
| ListenerType listenerType, | ||
| boolean enableUnstableLastVersion, | ||
| boolean zkMigrationEnabled, | ||
| boolean clientTelemetryEnabled | ||
| ) { | ||
| ApiVersionCollection apiKeys; | ||
| if (controllerApiVersions != null) { | ||
| apiKeys = intersectForwardableApis( | ||
| listenerType, | ||
| minRecordVersion, | ||
| controllerApiVersions.allSupportedApiVersions(), | ||
| enableUnstableLastVersion, | ||
| clientTelemetryEnabled | ||
| ); | ||
| } else { | ||
| apiKeys = filterApis( | ||
| minRecordVersion, | ||
| listenerType, | ||
| enableUnstableLastVersion, | ||
| clientTelemetryEnabled | ||
| ); | ||
| } | ||
|
|
||
| return createApiVersionsResponse( | ||
| throttleTimeMs, | ||
| apiKeys, | ||
| latestSupportedFeatures, | ||
| finalizedFeatures, | ||
| finalizedFeaturesEpoch, | ||
| zkMigrationEnabled | ||
| ); | ||
| return intersectForwardableApis( | ||
| listenerType, | ||
| minRecordVersion, | ||
| controllerApiVersions.allSupportedApiVersions(), | ||
| enableUnstableLastVersion, | ||
| clientTelemetryEnabled); | ||
| } | ||
|
|
||
| public static ApiVersionsResponse createApiVersionsResponse( | ||
| int throttleTimeMs, | ||
| ApiVersionCollection apiVersions, | ||
| Features<SupportedVersionRange> latestSupportedFeatures, | ||
| Map<String, Short> finalizedFeatures, | ||
| long finalizedFeaturesEpoch, | ||
| boolean zkMigrationEnabled | ||
| public static ApiVersionCollection brokerApiVersions( | ||
| RecordVersion minRecordVersion, | ||
| ListenerType listenerType, | ||
| boolean enableUnstableLastVersion, | ||
| boolean clientTelemetryEnabled | ||
| ) { | ||
| return new ApiVersionsResponse( | ||
| createApiVersionsResponseData( | ||
| throttleTimeMs, | ||
| Errors.NONE, | ||
| apiVersions, | ||
| latestSupportedFeatures, | ||
| finalizedFeatures, | ||
| finalizedFeaturesEpoch, | ||
| zkMigrationEnabled | ||
| ) | ||
| ); | ||
| return filterApis( | ||
| minRecordVersion, | ||
| listenerType, | ||
| enableUnstableLastVersion, | ||
| clientTelemetryEnabled); | ||
| } | ||
|
|
||
| public static ApiVersionCollection filterApis( | ||
|
|
@@ -249,37 +282,24 @@ public static ApiVersionCollection intersectForwardableApis( | |
| return apiKeys; | ||
| } | ||
|
|
||
| private static ApiVersionsResponseData createApiVersionsResponseData( | ||
| final int throttleTimeMs, | ||
| final Errors error, | ||
| final ApiVersionCollection apiKeys, | ||
| final Features<SupportedVersionRange> latestSupportedFeatures, | ||
| final Map<String, Short> finalizedFeatures, | ||
| final long finalizedFeaturesEpoch, | ||
| final boolean zkMigrationEnabled | ||
| ) { | ||
| final ApiVersionsResponseData data = new ApiVersionsResponseData(); | ||
| data.setThrottleTimeMs(throttleTimeMs); | ||
| data.setErrorCode(error.code()); | ||
| data.setApiKeys(apiKeys); | ||
| data.setSupportedFeatures(createSupportedFeatureKeys(latestSupportedFeatures)); | ||
| data.setFinalizedFeatures(createFinalizedFeatureKeys(finalizedFeatures)); | ||
| data.setFinalizedFeaturesEpoch(finalizedFeaturesEpoch); | ||
| data.setZkMigrationReady(zkMigrationEnabled); | ||
|
|
||
| return data; | ||
| } | ||
|
|
||
| private static SupportedFeatureKeyCollection createSupportedFeatureKeys( | ||
| Features<SupportedVersionRange> latestSupportedFeatures) { | ||
| Features<SupportedVersionRange> latestSupportedFeatures, | ||
|
cmccabe marked this conversation as resolved.
|
||
| boolean suppressV0 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suppressV0 => alterV0 ? |
||
| ) { | ||
| SupportedFeatureKeyCollection converted = new SupportedFeatureKeyCollection(); | ||
| for (Map.Entry<String, SupportedVersionRange> feature : latestSupportedFeatures.features().entrySet()) { | ||
| final SupportedFeatureKey key = new SupportedFeatureKey(); | ||
| final SupportedVersionRange versionRange = feature.getValue(); | ||
| key.setName(feature.getKey()); | ||
| key.setMinVersion(versionRange.min()); | ||
| key.setMaxVersion(versionRange.max()); | ||
| converted.add(key); | ||
| // Some older clients will have deserialization problems if a feature's | ||
| // minimum supported level is 0. Therefore, when preparing ApiVersionResponse | ||
| // at versions less than 4, we must leave those features out. See KAFKA-17011 | ||
| // for details. | ||
| if (!(suppressV0 && versionRange.min() == 0)) { | ||
| final SupportedFeatureKey key = new SupportedFeatureKey(); | ||
| key.setName(feature.getKey()); | ||
| key.setMinVersion(versionRange.min()); | ||
| key.setMaxVersion(versionRange.max()); | ||
| converted.add(key); | ||
| } | ||
| } | ||
|
|
||
| return converted; | ||
|
|
||
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
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
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
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
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suppressFeatureLevel0 => alterFeatureLevel0 ?