-
Notifications
You must be signed in to change notification settings - Fork 15.4k
KAFKA-2632: move fetchable check ahead in handleFetchResponse #295
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 2 commits
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 |
|---|---|---|
|
|
@@ -303,7 +303,14 @@ public Map<TopicPartition, List<ConsumerRecord<K, V>>> fetchedRecords() { | |
|
|
||
| for (PartitionRecords<K, V> part : this.records) { | ||
| if (!subscriptions.isFetchable(part.partition)) { | ||
| log.debug("Ignoring fetched records for {} since it is no longer fetchable", part.partition); | ||
| // this can happen when a rebalance happened or a partition consumption paused | ||
| // before fetched records are returned to the consumer's poll call | ||
| log.debug("Not returning fetched records for partition {} since it is no longer fetchable", part.partition); | ||
|
|
||
| // we also need to reset the fetch positions to pretend we did not fetch | ||
| // this partition in the previous request at all | ||
| subscriptions.fetched(part.partition, part.records.get(0).offset()); | ||
|
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. Isn't it a little dangerous to assume that the fetch position in the returned record is still relevant? Suppose we have the following sequence:
Maybe instead we should reset the fetched position to the consumed position?
Contributor
Author
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. @hachikuji I thought about this, but consumed() may return null for the first time so we cannot rely on that value either. Maybe we should just combine these two? I.e.: If consumed() != null, set to consumed; |
||
|
|
||
| continue; | ||
| } | ||
|
|
||
|
|
@@ -445,8 +452,10 @@ private void handleFetchResponse(ClientResponse resp, FetchRequest request) { | |
| for (Map.Entry<TopicPartition, FetchResponse.PartitionData> entry : response.responseData().entrySet()) { | ||
| TopicPartition tp = entry.getKey(); | ||
| FetchResponse.PartitionData partition = entry.getValue(); | ||
| if (!subscriptions.assignedPartitions().contains(tp)) { | ||
| log.debug("Ignoring fetched data for partition {} which is no longer assigned.", tp); | ||
| if (!subscriptions.isFetchable(tp)) { | ||
| // this can happen when a rebalance happened or a partition consumption paused | ||
| // while fetch is still in-flight | ||
| log.debug("Ignoring fetched records for partition {} since it is no longer fetchable", tp); | ||
| } else if (partition.errorCode == Errors.NONE.code()) { | ||
| long fetchOffset = request.fetchData().get(tp).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.
I think we still need this check. There may be a rebalance between the time a fetch response is handled and the time it is returned to the user.