-
Notifications
You must be signed in to change notification settings - Fork 14.8k
KAFKA-19802: Admin client changes for KIP-1226 #20771
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
Changes from all commits
798addc
6cf21cc
16f4b80
20715dc
4a0e582
2b44ac0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| /* | ||
| * 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; | ||
|
|
||
| import java.util.Objects; | ||
| import java.util.Optional; | ||
|
|
||
| /** | ||
| * This class is used to contain the offset and lag information for a share-partition. | ||
| */ | ||
| @InterfaceStability.Evolving | ||
| public class SharePartitionOffsetInfo { | ||
| private final long startOffset; | ||
| private final Optional<Integer> leaderEpoch; | ||
| private final Optional<Long> lag; | ||
|
|
||
| /** | ||
| * Construct a new SharePartitionOffsetInfo. | ||
| * | ||
| * @param startOffset The share-partition start offset | ||
| * @param leaderEpoch The optional leader epoch of the share-partition | ||
| * @param lag The optional lag for the share-partition | ||
| */ | ||
| public SharePartitionOffsetInfo(long startOffset, Optional<Integer> leaderEpoch, Optional<Long> lag) { | ||
| this.startOffset = startOffset; | ||
| this.leaderEpoch = leaderEpoch; | ||
| this.lag = lag; | ||
| } | ||
|
|
||
| public long startOffset() { | ||
| return startOffset; | ||
| } | ||
|
|
||
| public Optional<Integer> leaderEpoch() { | ||
| return leaderEpoch; | ||
| } | ||
|
|
||
| public Optional<Long> lag() { | ||
| return lag; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) return true; | ||
| if (o == null || getClass() != o.getClass()) return false; | ||
| SharePartitionOffsetInfo that = (SharePartitionOffsetInfo) o; | ||
| return startOffset == that.startOffset && | ||
| Objects.equals(leaderEpoch, that.leaderEpoch) && | ||
| Objects.equals(lag, that.lag); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(startOffset, leaderEpoch, lag); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "SharePartitionOffsetInfo{" + | ||
| "startOffset=" + startOffset + | ||
| ", leaderEpoch=" + leaderEpoch.orElse(null) + | ||
| ", lag=" + lag.orElse(null) + | ||
| '}'; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,7 +19,7 @@ | |
| import org.apache.kafka.clients.admin.KafkaAdminClient; | ||
| import org.apache.kafka.clients.admin.ListShareGroupOffsetsOptions; | ||
| import org.apache.kafka.clients.admin.ListShareGroupOffsetsSpec; | ||
| import org.apache.kafka.clients.consumer.OffsetAndMetadata; | ||
| import org.apache.kafka.clients.admin.SharePartitionOffsetInfo; | ||
| import org.apache.kafka.common.Node; | ||
| import org.apache.kafka.common.TopicPartition; | ||
| import org.apache.kafka.common.message.DescribeShareGroupOffsetsRequestData; | ||
|
|
@@ -47,7 +47,7 @@ | |
| /** | ||
| * This class is the handler for {@link KafkaAdminClient#listShareGroupOffsets(Map, ListShareGroupOffsetsOptions)} call | ||
| */ | ||
| public class ListShareGroupOffsetsHandler extends AdminApiHandler.Batched<CoordinatorKey, Map<TopicPartition, OffsetAndMetadata>> { | ||
| public class ListShareGroupOffsetsHandler extends AdminApiHandler.Batched<CoordinatorKey, Map<TopicPartition, SharePartitionOffsetInfo>> { | ||
|
|
||
| private final Map<String, ListShareGroupOffsetsSpec> groupSpecs; | ||
| private final Logger log; | ||
|
|
@@ -60,7 +60,7 @@ public ListShareGroupOffsetsHandler(Map<String, ListShareGroupOffsetsSpec> group | |
| this.lookupStrategy = new CoordinatorStrategy(CoordinatorType.GROUP, logContext); | ||
| } | ||
|
|
||
| public static AdminApiFuture.SimpleAdminApiFuture<CoordinatorKey, Map<TopicPartition, OffsetAndMetadata>> newFuture(Collection<String> groupIds) { | ||
| public static AdminApiFuture.SimpleAdminApiFuture<CoordinatorKey, Map<TopicPartition, SharePartitionOffsetInfo>> newFuture(Collection<String> groupIds) { | ||
| return AdminApiFuture.forKeys(coordinatorKeys(groupIds)); | ||
| } | ||
|
|
||
|
|
@@ -110,13 +110,13 @@ public DescribeShareGroupOffsetsRequest.Builder buildBatchedRequest(int coordina | |
| } | ||
|
|
||
| @Override | ||
| public ApiResult<CoordinatorKey, Map<TopicPartition, OffsetAndMetadata>> handleResponse(Node coordinator, | ||
| Set<CoordinatorKey> groupIds, | ||
| AbstractResponse abstractResponse) { | ||
| public ApiResult<CoordinatorKey, Map<TopicPartition, SharePartitionOffsetInfo>> handleResponse(Node coordinator, | ||
| Set<CoordinatorKey> groupIds, | ||
| AbstractResponse abstractResponse) { | ||
| validateKeys(groupIds); | ||
|
|
||
| final DescribeShareGroupOffsetsResponse response = (DescribeShareGroupOffsetsResponse) abstractResponse; | ||
| final Map<CoordinatorKey, Map<TopicPartition, OffsetAndMetadata>> completed = new HashMap<>(); | ||
| final Map<CoordinatorKey, Map<TopicPartition, SharePartitionOffsetInfo>> completed = new HashMap<>(); | ||
| final Map<CoordinatorKey, Throwable> failed = new HashMap<>(); | ||
| final List<CoordinatorKey> unmapped = new ArrayList<>(); | ||
|
|
||
|
|
@@ -125,7 +125,7 @@ public ApiResult<CoordinatorKey, Map<TopicPartition, OffsetAndMetadata>> handleR | |
| if (response.hasGroupError(groupId)) { | ||
| handleGroupError(coordinatorKey, response.groupError(groupId), failed, unmapped); | ||
| } else { | ||
| Map<TopicPartition, OffsetAndMetadata> groupOffsetsListing = new HashMap<>(); | ||
| Map<TopicPartition, SharePartitionOffsetInfo> groupOffsetsListing = new HashMap<>(); | ||
| response.data().groups().stream().filter(g -> g.groupId().equals(groupId)).forEach(groupResponse -> { | ||
| for (DescribeShareGroupOffsetsResponseData.DescribeShareGroupOffsetsResponseTopic topicResponse : groupResponse.topics()) { | ||
| for (DescribeShareGroupOffsetsResponseData.DescribeShareGroupOffsetsResponsePartition partitionResponse : topicResponse.partitions()) { | ||
|
|
@@ -137,7 +137,7 @@ public ApiResult<CoordinatorKey, Map<TopicPartition, OffsetAndMetadata>> handleR | |
| if (partitionResponse.startOffset() < 0) { | ||
| groupOffsetsListing.put(tp, null); | ||
| } else { | ||
| groupOffsetsListing.put(tp, new OffsetAndMetadata(startOffset, leaderEpoch, "")); | ||
| groupOffsetsListing.put(tp, new SharePartitionOffsetInfo(startOffset, leaderEpoch, Optional.empty())); | ||
|
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. Pardon me, will the 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. Yes. Very soon. https://issues.apache.org/jira/browse/KAFKA-19778 for the tasks we are implementing in parallel. |
||
| } | ||
| } else { | ||
| log.warn("Skipping return offset for {} due to error {}: {}.", tp, partitionResponse.errorCode(), partitionResponse.errorMessage()); | ||
|
|
||
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.
Sorry, I'm a bit confused by this "start offset". For example, If a partition has a latest offset of
23547540and a share consumer has a "start offset" of23541472, how do we explain the difference between those numbers?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.
The start offset is a little like the committed offset for a consumer group. The lag is the number of records to be delivered between the start offset and the latest offset.
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.
@AndrewJSchofield thanks for your response! I have a follow-up question.
Will the start offset eventually equal to the latest offset of the partition?
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.
When consumption catches up with production, yes.