-
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
Changes from 18 commits
c08b21e
4f1722d
2767f70
3e75fdf
eb068a0
3d2f66a
70d43d7
1a0a8c5
b76c543
048b1f7
ae075e7
8f0e8f4
c7336cb
1b42863
ce40782
ea49519
47cf1c7
6a56493
31de57b
ad61063
ca36eba
53dd98b
9e7a667
54d8dd5
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,33 @@ | ||
| /* | ||
| * 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 a recent leader election and high-water mark lag | ||
| */ | ||
| public class OffsetNotAvailableException extends RetriableException { | ||
| private static final long serialVersionUID = 1L; | ||
|
|
||
| public OffsetNotAvailableException(String message) { | ||
| super(message); | ||
| } | ||
|
|
||
| public OffsetNotAvailableException(String message, Throwable cause) { | ||
| super(message, cause); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -817,6 +817,18 @@ class Partition(val topicPartition: TopicPartition, | |
| case None => localReplica.logEndOffset.messageOffset | ||
| } | ||
|
|
||
| // Only actually check the HW if this is a "latest" offset client request | ||
| if (isolationLevel.isDefined && timestamp == ListOffsetRequest.LATEST_TIMESTAMP) { | ||
| // Throw if the HW has not caught up with the start offset from this epoch | ||
| leaderEpochStartOffsetOpt | ||
| .filter(leo => leo > localReplica.highWatermark.messageOffset) | ||
| .map(leo => Errors.OFFSET_NOT_AVAILABLE.exception(s"Failed to fetch offsets for " + | ||
|
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. Could we change this If we are only checking this for the latest case, I guess we could move this into the So we could change the code slightly below. If
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. I think that makes sense, +1
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. Ok, I incorporated this logic into the latest commit. I also reorganized the code to make it easier to understand (hopefully) |
||
| s"partition $topicPartition with leader epoch ${currentLeaderEpoch.get} as this partition's " + | ||
| s"high watermark (${localReplica.highWatermark.messageOffset}) is lagging behind the " + | ||
| s"LEO at the start of this epoch ($leo).")) | ||
| .foreach(apiError => throw apiError) | ||
| } | ||
|
|
||
| if (timestamp == ListOffsetRequest.LATEST_TIMESTAMP) { | ||
| Some(new TimestampAndOffset(RecordBatch.NO_TIMESTAMP, lastFetchableOffset, Optional.of(leaderEpoch))) | ||
| } else { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.