-
Notifications
You must be signed in to change notification settings - Fork 15.4k
KAFKA-9435: DescribeLogDirs automated protocol #7972
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
mimaison
merged 7 commits into
apache:trunk
from
tombentley:KAFKA-9435-DescribeLogDirs-automated-protocol
Mar 19, 2020
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4f5c42f
Fix KAFKA-9435, using automated protocol for DescribeLogDirs
tombentley 5214f4b
Per KIP-482, use flexible versions for DescribeLogDirs
tombentley b81c6c6
Review comments
tombentley 39fb997
Review comments
tombentley a7f72cb
More minor improvements
tombentley f72902e
Review comments
tombentley e756433
Review comments
tombentley 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
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 |
|---|---|---|
|
|
@@ -17,21 +17,15 @@ | |
|
|
||
| package org.apache.kafka.common.requests; | ||
|
|
||
| import org.apache.kafka.common.TopicPartition; | ||
| import org.apache.kafka.common.message.DescribeLogDirsRequestData; | ||
| import org.apache.kafka.common.message.DescribeLogDirsResponseData; | ||
| import org.apache.kafka.common.protocol.ApiKeys; | ||
| import org.apache.kafka.common.protocol.types.ArrayOf; | ||
| import org.apache.kafka.common.protocol.types.Field; | ||
| import org.apache.kafka.common.protocol.types.Schema; | ||
| import org.apache.kafka.common.protocol.types.Struct; | ||
| import org.apache.kafka.common.requests.DescribeLogDirsResponse.LogDirInfo; | ||
|
|
||
| import java.nio.ByteBuffer; | ||
| import java.util.ArrayList; | ||
| import java.util.HashMap; | ||
| import java.util.HashSet; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Set; | ||
|
|
||
| import static org.apache.kafka.common.protocol.CommonFields.TOPIC_NAME; | ||
| import static org.apache.kafka.common.protocol.types.Type.INT32; | ||
|
|
@@ -49,105 +43,54 @@ public class DescribeLogDirsRequest extends AbstractRequest { | |
| TOPIC_NAME, | ||
| new Field(PARTITIONS_KEY_NAME, new ArrayOf(INT32), "List of partition ids of the topic."))))); | ||
|
|
||
| /** | ||
| * The version number is bumped to indicate that on quota violation brokers send out responses before throttling. | ||
| */ | ||
| private static final Schema DESCRIBE_LOG_DIRS_REQUEST_V1 = DESCRIBE_LOG_DIRS_REQUEST_V0; | ||
|
|
||
| public static Schema[] schemaVersions() { | ||
| return new Schema[]{DESCRIBE_LOG_DIRS_REQUEST_V0, DESCRIBE_LOG_DIRS_REQUEST_V1}; | ||
| } | ||
|
|
||
| private final Set<TopicPartition> topicPartitions; | ||
| private final DescribeLogDirsRequestData data; | ||
|
|
||
| public static class Builder extends AbstractRequest.Builder<DescribeLogDirsRequest> { | ||
| private final Set<TopicPartition> topicPartitions; | ||
| private final DescribeLogDirsRequestData data; | ||
|
|
||
| // topicPartitions == null indicates requesting all partitions, and an empty list indicates requesting no partitions. | ||
| public Builder(Set<TopicPartition> partitions) { | ||
| public Builder(DescribeLogDirsRequestData data) { | ||
| super(ApiKeys.DESCRIBE_LOG_DIRS); | ||
| this.topicPartitions = partitions; | ||
| this.data = data; | ||
| } | ||
|
|
||
| @Override | ||
| public DescribeLogDirsRequest build(short version) { | ||
| return new DescribeLogDirsRequest(topicPartitions, version); | ||
| return new DescribeLogDirsRequest(data, version); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| StringBuilder builder = new StringBuilder(); | ||
| builder.append("(type=DescribeLogDirsRequest") | ||
| .append(", topicPartitions=") | ||
| .append(topicPartitions) | ||
| .append(")"); | ||
| return builder.toString(); | ||
| return data.toString(); | ||
| } | ||
| } | ||
|
|
||
| public DescribeLogDirsRequest(Struct struct, short version) { | ||
| super(ApiKeys.DESCRIBE_LOG_DIRS, version); | ||
|
|
||
| if (struct.getArray(TOPICS_KEY_NAME) == null) { | ||
| topicPartitions = null; | ||
| } else { | ||
| topicPartitions = new HashSet<>(); | ||
| for (Object topicStructObj : struct.getArray(TOPICS_KEY_NAME)) { | ||
| Struct topicStruct = (Struct) topicStructObj; | ||
| String topic = topicStruct.get(TOPIC_NAME); | ||
| for (Object partitionObj : topicStruct.getArray(PARTITIONS_KEY_NAME)) { | ||
| int partition = (Integer) partitionObj; | ||
| topicPartitions.add(new TopicPartition(topic, partition)); | ||
| } | ||
| } | ||
| } | ||
| this.data = new DescribeLogDirsRequestData(struct, version); | ||
| } | ||
|
|
||
| // topicPartitions == null indicates requesting all partitions, and an empty list indicates requesting no partitions. | ||
|
Member
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. This comment can now be removed |
||
| public DescribeLogDirsRequest(Set<TopicPartition> topicPartitions, short version) { | ||
| public DescribeLogDirsRequest(DescribeLogDirsRequestData data, short version) { | ||
|
Member
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. The comment above is out of date |
||
| super(ApiKeys.DESCRIBE_LOG_DIRS, version); | ||
| this.topicPartitions = topicPartitions; | ||
| this.data = data; | ||
| } | ||
|
|
||
| public DescribeLogDirsRequestData data() { | ||
| return data; | ||
| } | ||
|
|
||
| @Override | ||
| protected Struct toStruct() { | ||
| Struct struct = new Struct(ApiKeys.DESCRIBE_LOG_DIRS.requestSchema(version())); | ||
| if (topicPartitions == null) { | ||
| struct.set(TOPICS_KEY_NAME, null); | ||
| return struct; | ||
| } | ||
|
|
||
| Map<String, List<Integer>> partitionsByTopic = new HashMap<>(); | ||
| for (TopicPartition tp : topicPartitions) { | ||
| if (!partitionsByTopic.containsKey(tp.topic())) { | ||
| partitionsByTopic.put(tp.topic(), new ArrayList<Integer>()); | ||
| } | ||
| partitionsByTopic.get(tp.topic()).add(tp.partition()); | ||
| } | ||
|
|
||
| List<Struct> topicStructArray = new ArrayList<>(); | ||
| for (Map.Entry<String, List<Integer>> partitionsByTopicEntry : partitionsByTopic.entrySet()) { | ||
| Struct topicStruct = struct.instance(TOPICS_KEY_NAME); | ||
| topicStruct.set(TOPIC_NAME, partitionsByTopicEntry.getKey()); | ||
| topicStruct.set(PARTITIONS_KEY_NAME, partitionsByTopicEntry.getValue().toArray()); | ||
| topicStructArray.add(topicStruct); | ||
| } | ||
| struct.set(TOPICS_KEY_NAME, topicStructArray.toArray()); | ||
|
|
||
| return struct; | ||
| return data.toStruct(version()); | ||
| } | ||
|
|
||
| @Override | ||
| public AbstractResponse getErrorResponse(int throttleTimeMs, Throwable e) { | ||
| return new DescribeLogDirsResponse(throttleTimeMs, new HashMap<String, LogDirInfo>()); | ||
| return new DescribeLogDirsResponse(new DescribeLogDirsResponseData().setThrottleTimeMs(throttleTimeMs)); | ||
| } | ||
|
|
||
| public boolean isAllTopicPartitions() { | ||
| return topicPartitions == null; | ||
| } | ||
|
|
||
| public Set<TopicPartition> topicPartitions() { | ||
| return topicPartitions; | ||
| return data.topics() == null; | ||
| } | ||
|
|
||
| public static DescribeLogDirsRequest parse(ByteBuffer buffer, short version) { | ||
|
|
||
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.
This V0 schema should be deleted too