-
Notifications
You must be signed in to change notification settings - Fork 15.4k
KAFKA-9724 Newer clients not always sending fetch request to older brokers #8376
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 6 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
c7ba8d5
AWAITING_VALIDATION state causing clients to skip sending fetches to …
mumrah 4a461ec
Don't overwrite a partition's last seen epoch if it wasn't set already
mumrah 349d7e4
Actually implement the new logic
mumrah 8433abb
Add some tests
mumrah 567dc2d
Simply logic for completing validation in prepareFetchRequests
mumrah 48605dc
Feedback from PR
mumrah ce38b74
checkstyle
mumrah 45c20d8
Merge remote-tracking branch 'apache-github/trunk' into KAFKA-9724
mumrah c8d4a8c
Add unit test for epoch updates in MetadataTest
mumrah 7a1d6e6
Merge remote-tracking branch 'apache-github/trunk' into KAFKA-9724
mumrah e05d8ad
Update javadoc for updateLastSeenEpochIfNewer
mumrah aa87a4b
Push logic into maybeValidatePositionForCurrentLeader
mumrah 37bb3a5
Checkstyle
mumrah 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -156,14 +156,31 @@ public synchronized int requestUpdateForNewTopics() { | |
| } | ||
|
|
||
| /** | ||
| * Request an update for the partition metadata iff the given leader epoch is newer than the last seen leader epoch | ||
| * Request an update for the partition metadata iff we encounter a leader epoch that is newer than the last seen leader epoch | ||
| */ | ||
| public synchronized boolean updateLastSeenEpochIfNewer(TopicPartition topicPartition, int leaderEpoch) { | ||
| Objects.requireNonNull(topicPartition, "TopicPartition cannot be null"); | ||
| if (leaderEpoch < 0) | ||
| throw new IllegalArgumentException("Invalid leader epoch " + leaderEpoch + " (must be non-negative)"); | ||
|
|
||
| boolean updated = updateLastSeenEpoch(topicPartition, leaderEpoch, oldEpoch -> leaderEpoch > oldEpoch); | ||
| Integer oldEpoch = lastSeenLeaderEpochs.get(topicPartition); | ||
| log.trace("Determining if we should replace existing epoch {} with new epoch {}", oldEpoch, leaderEpoch); | ||
|
mumrah marked this conversation as resolved.
Outdated
|
||
|
|
||
| final boolean updated; | ||
| if (oldEpoch == null) { | ||
| log.debug("Not replacing null epoch with new epoch {} for partition {}", leaderEpoch, topicPartition); | ||
| updated = false; | ||
| } else { | ||
| if (leaderEpoch > oldEpoch) { | ||
|
mumrah marked this conversation as resolved.
Outdated
|
||
| log.debug("Updating last seen epoch from {} to {} for partition {}", oldEpoch, leaderEpoch, topicPartition); | ||
| lastSeenLeaderEpochs.put(topicPartition, leaderEpoch); | ||
| updated = true; | ||
| } else { | ||
| log.debug("Not replacing existing epoch {} with new epoch {} for partition {}", oldEpoch, leaderEpoch, topicPartition); | ||
| updated = false; | ||
| } | ||
| } | ||
|
|
||
| this.needFullUpdate = this.needFullUpdate || updated; | ||
| return updated; | ||
| } | ||
|
|
@@ -172,29 +189,6 @@ public Optional<Integer> lastSeenLeaderEpoch(TopicPartition topicPartition) { | |
| return Optional.ofNullable(lastSeenLeaderEpochs.get(topicPartition)); | ||
| } | ||
|
|
||
| /** | ||
| * Conditionally update the leader epoch for a partition | ||
| * | ||
| * @param topicPartition topic+partition to update the epoch for | ||
| * @param epoch the new epoch | ||
| * @param epochTest a predicate to determine if the old epoch should be replaced | ||
| * @return true if the epoch was updated, false otherwise | ||
| */ | ||
| private synchronized boolean updateLastSeenEpoch(TopicPartition topicPartition, | ||
|
Member
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. I removed this since at this point the two callers have different needs for updating the epoch and adding a flag felt pretty kludgy |
||
| int epoch, | ||
| Predicate<Integer> epochTest) { | ||
| Integer oldEpoch = lastSeenLeaderEpochs.get(topicPartition); | ||
| log.trace("Determining if we should replace existing epoch {} with new epoch {}", oldEpoch, epoch); | ||
| if (oldEpoch == null || epochTest.test(oldEpoch)) { | ||
| log.debug("Updating last seen epoch from {} to {} for partition {}", oldEpoch, epoch, topicPartition); | ||
| lastSeenLeaderEpochs.put(topicPartition, epoch); | ||
| return true; | ||
| } else { | ||
| log.debug("Not replacing existing epoch {} with new epoch {} for partition {}", oldEpoch, epoch, topicPartition); | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Check whether an update has been explicitly requested. | ||
| * | ||
|
|
@@ -373,10 +367,14 @@ private Optional<MetadataResponse.PartitionMetadata> updateLatestMetadata( | |
| if (hasReliableLeaderEpoch && partitionMetadata.leaderEpoch.isPresent()) { | ||
| int newEpoch = partitionMetadata.leaderEpoch.get(); | ||
| // If the received leader epoch is at least the same as the previous one, update the metadata | ||
| if (updateLastSeenEpoch(tp, newEpoch, oldEpoch -> newEpoch >= oldEpoch)) { | ||
| Integer currentEpoch = lastSeenLeaderEpochs.get(tp); | ||
| if (currentEpoch == null || newEpoch >= currentEpoch) { | ||
| log.debug("Updating last seen epoch for partition {} from {} to epoch {} from new metadata", tp, currentEpoch, newEpoch); | ||
| lastSeenLeaderEpochs.put(tp, newEpoch); | ||
| return Optional.of(partitionMetadata); | ||
| } else { | ||
| // Otherwise ignore the new metadata and use the previously cached info | ||
| log.debug("Got metadata for an older epoch {} (current is {}) for partition {}, not updating", newEpoch, currentEpoch, tp); | ||
| return cache.partitionMetadata(tp); | ||
| } | ||
| } else { | ||
|
|
||
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
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.
Uh oh!
There was an error while loading. Please reload this page.