-
Notifications
You must be signed in to change notification settings - Fork 15.4k
KAFKA-7044: Fix Fetcher.fetchOffsetsByTimes and NPE in describe consumer group #5627
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 4 commits
474bfb4
3306849
4f1a6a0
aec7385
e71e6f4
1f8fbd8
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 |
|---|---|---|
|
|
@@ -88,6 +88,7 @@ | |
| import java.util.concurrent.ConcurrentLinkedQueue; | ||
| import java.util.concurrent.atomic.AtomicInteger; | ||
| import java.util.concurrent.atomic.AtomicReference; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| import static java.util.Collections.emptyList; | ||
| import static org.apache.kafka.common.serialization.ExtendedDeserializer.Wrapper.ensureExtended; | ||
|
|
@@ -414,7 +415,9 @@ private ListOffsetResult fetchOffsetsByTimes(Map<TopicPartition, Long> timestamp | |
| if (value.partitionsToRetry.isEmpty()) | ||
| return result; | ||
|
|
||
| remainingToSearch.keySet().removeAll(result.fetchedOffsets.keySet()); | ||
| remainingToSearch = timestampsToSearch.entrySet().stream() | ||
| .filter(entry -> value.partitionsToRetry.contains(entry.getKey())) | ||
| .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); | ||
| } else if (!future.isRetriable()) { | ||
| throw future.exception(); | ||
| } | ||
|
|
@@ -632,9 +635,11 @@ private RequestFuture<ListOffsetResult> sendListOffsetsRequests(final Map<TopicP | |
| final RequestFuture<ListOffsetResult> listOffsetRequestsFuture = new RequestFuture<>(); | ||
| final Map<TopicPartition, OffsetData> fetchedTimestampOffsets = new HashMap<>(); | ||
| final Set<TopicPartition> partitionsToRetry = new HashSet<>(); | ||
| final Set<TopicPartition> partitionsRequireMetadataUpdate = new HashSet<>(timestampsToSearch.keySet()); | ||
|
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. Another idea might be to pass |
||
| final AtomicInteger remainingResponses = new AtomicInteger(timestampsToSearchByNode.size()); | ||
|
|
||
| for (Map.Entry<Node, Map<TopicPartition, ListOffsetRequest.PartitionData>> entry : timestampsToSearchByNode.entrySet()) { | ||
| partitionsRequireMetadataUpdate.removeAll(entry.getValue().keySet()); | ||
| RequestFuture<ListOffsetResult> future = | ||
| sendListOffsetRequest(entry.getKey(), entry.getValue(), requireTimestamps); | ||
| future.addListener(new RequestFutureListener<ListOffsetResult>() { | ||
|
|
@@ -645,6 +650,7 @@ public void onSuccess(ListOffsetResult partialResult) { | |
| partitionsToRetry.addAll(partialResult.partitionsToRetry); | ||
|
|
||
| if (remainingResponses.decrementAndGet() == 0 && !listOffsetRequestsFuture.isDone()) { | ||
| partitionsToRetry.addAll(partitionsRequireMetadataUpdate); | ||
| ListOffsetResult result = new ListOffsetResult(fetchedTimestampOffsets, partitionsToRetry); | ||
| listOffsetRequestsFuture.complete(result); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -292,12 +292,8 @@ object ConsumerGroupCommand extends Logging { | |
| } | ||
|
|
||
| getLogEndOffsets(topicPartitions).map { | ||
| logEndOffsetResult => | ||
| logEndOffsetResult._2 match { | ||
| case LogOffsetResult.LogOffset(logEndOffset) => getDescribePartitionResult(logEndOffsetResult._1, Some(logEndOffset)) | ||
| case LogOffsetResult.Unknown => getDescribePartitionResult(logEndOffsetResult._1, None) | ||
| case LogOffsetResult.Ignore => null | ||
|
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. As far as I can tell, this was the only use of If we did that, then we could probably also get rid of |
||
| } | ||
| case (topicPartition, LogOffsetResult.LogOffset(offset)) => getDescribePartitionResult(topicPartition, Some(offset)) | ||
| case (topicPartition, _) => getDescribePartitionResult(topicPartition, None) | ||
| }.toArray | ||
| } | ||
|
|
||
|
|
@@ -399,16 +395,20 @@ object ConsumerGroupCommand extends Logging { | |
| private def getLogEndOffsets(topicPartitions: Seq[TopicPartition]): Map[TopicPartition, LogOffsetResult] = { | ||
| val offsets = getConsumer.endOffsets(topicPartitions.asJava) | ||
| topicPartitions.map { topicPartition => | ||
| val logEndOffset = offsets.get(topicPartition) | ||
| topicPartition -> LogOffsetResult.LogOffset(logEndOffset) | ||
| Option(offsets.get(topicPartition)) match { | ||
| case Some(logEndOffset) => topicPartition -> LogOffsetResult.LogOffset(logEndOffset) | ||
| case _ => topicPartition -> LogOffsetResult.Unknown | ||
| } | ||
| }.toMap | ||
| } | ||
|
|
||
| private def getLogStartOffsets(topicPartitions: Seq[TopicPartition]): Map[TopicPartition, LogOffsetResult] = { | ||
| val offsets = getConsumer.beginningOffsets(topicPartitions.asJava) | ||
| topicPartitions.map { topicPartition => | ||
| val logStartOffset = offsets.get(topicPartition) | ||
| topicPartition -> LogOffsetResult.LogOffset(logStartOffset) | ||
| Option(offsets.get(topicPartition)) match { | ||
| case Some(logStartOffset) => topicPartition -> LogOffsetResult.LogOffset(logStartOffset) | ||
| case _ => topicPartition -> LogOffsetResult.Unknown | ||
| } | ||
| }.toMap | ||
| } | ||
|
|
||
|
|
||
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.
I think this can be replaced with
remainingToSearch.keySet().retainAll(value.partitionsToRetry).