-
Notifications
You must be signed in to change notification settings - Fork 15.4k
KAFKA-2334 Guard against non-monotonic offsets in the client #5991
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 22 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
c08b21e
Add guard against returning offsets when HW has not caught up
mumrah 4f1722d
Don't do the HW check when in unclean leader election mode
mumrah 2767f70
Unit tests passing
mumrah 3e75fdf
Make broker and client behavior the same
mumrah eb068a0
Merge remote-tracking branch 'origin/trunk' into KAFKA-2334
mumrah 3d2f66a
Merge remote-tracking branch 'apache/trunk' into KAFKA-2334
mumrah 70d43d7
Revert "Make broker and client behavior the same"
mumrah 1a0a8c5
Add ASL to new class
mumrah b76c543
Feedback from PR
mumrah 048b1f7
New protocol version (KAFKA_2_2_IV1)
mumrah ae075e7
Merge remote-tracking branch 'apache/trunk' into KAFKA-2334
mumrah 8f0e8f4
high-water mark -> high watermark
mumrah c7336cb
Reverse the logic for the error case (oops)
mumrah 1b42863
Add unit test for offset errors
mumrah ce40782
Fix scala compile error
mumrah ea49519
Fix another scala compile error
mumrah 47cf1c7
Fix some comments
mumrah 6a56493
Only do the check for "latest" offset requests
mumrah 31de57b
Throw the new error instead of return None in one case, code reorg
mumrah ad61063
Style feedback from PR
mumrah ca36eba
More unit tests, cover an additional error case
mumrah 53dd98b
Clean up some comments
mumrah 9e7a667
Remove LSO reference
mumrah 54d8dd5
Another LSO reference
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
29 changes: 29 additions & 0 deletions
29
clients/src/main/java/org/apache/kafka/common/errors/OffsetNotAvailableException.java
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 |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| /* | ||
| * 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.common.errors; | ||
|
|
||
| /** | ||
| * Indicates that the leader is not able to guarantee monotonically increasing offsets | ||
| * due to the high watermark lagging behind the epoch start offset after a recent leader election | ||
| */ | ||
| public class OffsetNotAvailableException extends RetriableException { | ||
| private static final long serialVersionUID = 1L; | ||
|
|
||
| public OffsetNotAvailableException(String message) { | ||
| super(message); | ||
| } | ||
| } |
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
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 |
|---|---|---|
|
|
@@ -817,17 +817,36 @@ class Partition(val topicPartition: TopicPartition, | |
| case None => localReplica.logEndOffset.messageOffset | ||
| } | ||
|
|
||
| if (timestamp == ListOffsetRequest.LATEST_TIMESTAMP) { | ||
| Some(new TimestampAndOffset(RecordBatch.NO_TIMESTAMP, lastFetchableOffset, Optional.of(leaderEpoch))) | ||
| val epochLogString = if(currentLeaderEpoch.isPresent) { | ||
| s"epoch ${currentLeaderEpoch.get}" | ||
| } else { | ||
| def allowed(timestampOffset: TimestampAndOffset): Boolean = | ||
| timestamp == ListOffsetRequest.EARLIEST_TIMESTAMP || timestampOffset.offset < lastFetchableOffset | ||
| "unknown epoch" | ||
| } | ||
|
|
||
| val fetchedOffset = logManager.getLog(topicPartition).flatMap { log => | ||
| log.fetchOffsetByTimestamp(timestamp) | ||
| } | ||
| // Only consider throwing an error if we get a client request (isolationLevel is defined) and the start offset | ||
| // is lagging behind the high watermark | ||
| val maybeOffsetsError: Option[ApiException] = leaderEpochStartOffsetOpt | ||
| .filter(epochLSO => isolationLevel.isDefined && epochLSO > localReplica.highWatermark.messageOffset) | ||
|
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. nit: |
||
| .map(epochLSO => Errors.OFFSET_NOT_AVAILABLE.exception(s"Failed to fetch offsets for " + | ||
| s"partition $topicPartition with leader $epochLogString as this partition's " + | ||
| s"high watermark (${localReplica.highWatermark.messageOffset}) is lagging behind the " + | ||
| s"LSO at the beginning of this epoch ($epochLSO).")) | ||
|
|
||
| def getOffsetByTimestamp: Option[TimestampAndOffset] = { | ||
| logManager.getLog(topicPartition).flatMap(log => log.fetchOffsetByTimestamp(timestamp)) | ||
| } | ||
|
|
||
| fetchedOffset.filter(allowed) | ||
| // If we're in the lagging HW state after a leader election, throw OffsetNotAvailable for "latest" offset | ||
| // or for a timestamp lookup that is beyond the last fetchable offset. | ||
| timestamp match { | ||
| case ListOffsetRequest.LATEST_TIMESTAMP => | ||
| maybeOffsetsError.map(e => throw e) | ||
| .orElse(Some(new TimestampAndOffset(RecordBatch.NO_TIMESTAMP, lastFetchableOffset, Optional.of(leaderEpoch)))) | ||
| case ListOffsetRequest.EARLIEST_TIMESTAMP => | ||
| getOffsetByTimestamp | ||
| case _ => | ||
| getOffsetByTimestamp.filter(timestampAndOffset => timestampAndOffset.offset < lastFetchableOffset) | ||
| .orElse(maybeOffsetsError.map(e => throw e)) | ||
| } | ||
| } | ||
|
|
||
|
|
||
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
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.
Uh oh!
There was an error while loading. Please reload this page.