Skip to content

KAFKA-17108: Add EarliestPendingUpload offset spec in ListOffsets API#16584

Merged
kamalcph merged 4 commits into
apache:trunkfrom
abhijeetk88:KAFKA-17108
Aug 27, 2025
Merged

KAFKA-17108: Add EarliestPendingUpload offset spec in ListOffsets API#16584
kamalcph merged 4 commits into
apache:trunkfrom
abhijeetk88:KAFKA-17108

Conversation

@abhijeetk88

@abhijeetk88 abhijeetk88 commented Jul 12, 2024

Copy link
Copy Markdown
Contributor

This is the first part of the implementation of
KIP-1023

The purpose of this pull request is for the broker to start returning
the correct offset when it receives a -6 as a timestamp in a ListOffsets
API request.

Added unit tests for the new timestamp.

Reviewers: Kamal Chandraprakash kamal.chandraprakash@gmail.com

@abhijeetk88
abhijeetk88 marked this pull request as draft July 12, 2024 17:18
@abhijeetk88
abhijeetk88 force-pushed the KAFKA-17108 branch 6 times, most recently from b4f63a6 to d89d53b Compare August 5, 2024 06:26
@abhijeetk88
abhijeetk88 marked this pull request as ready for review August 5, 2024 06:30
@kamalcph kamalcph added the tiered-storage Related to the Tiered Storage feature label Aug 5, 2024
@kamalcph
kamalcph self-requested a review August 5, 2024 07:55

@kamalcph kamalcph left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the patch! Left minor comments to address.

Should we need to add an OffsetSpec on the client side to make the earliest_pending_upload_offset queryable from command line tools similar to 6e32448?

Comment on lines +1352 to +1353
val epochResult: Optional[Integer] =
if (leaderEpochCache.isDefined) {
val epochOpt = leaderEpochCache.get.epochForOffset(earliestPendingUploadOffset)
if (epochOpt.isPresent) {
Optional.of(epochOpt.getAsInt)
} else {
Optional.empty()
}
} else {
Optional.empty()
}
Some(new TimestampAndOffset(RecordBatch.NO_TIMESTAMP, earliestPendingUploadOffset, epochResult))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
val epochResult: Optional[Integer] =
if (leaderEpochCache.isDefined) {
val epochOpt = leaderEpochCache.get.epochForOffset(earliestPendingUploadOffset)
if (epochOpt.isPresent) {
Optional.of(epochOpt.getAsInt)
} else {
Optional.empty()
}
} else {
Optional.empty()
}
Some(new TimestampAndOffset(RecordBatch.NO_TIMESTAMP, earliestPendingUploadOffset, epochResult))
val epochResult = leaderEpochCache.flatMap(_.epochForOffset(earliestPendingUploadOffset).asScala)
.asJava.asInstanceOf[Optional[Integer]]
Some(new TimestampAndOffset(RecordBatch.NO_TIMESTAMP, earliestPendingUploadOffset, epochResult))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Thanks for the suggestion.

@OmniaGM OmniaGM Aug 13, 2024

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are other places in the same method can benefit from this refactor as well like line 1319 and 1298

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made the requested changes. Also changed for LATEST_TIMESTAMP

Comment thread core/src/test/scala/unit/kafka/log/UnifiedLogTest.scala Outdated
@abhijeetk88
abhijeetk88 force-pushed the KAFKA-17108 branch 3 times, most recently from e40dd55 to 5684997 Compare August 8, 2024 15:17
@abhijeetk88

Copy link
Copy Markdown
Contributor Author

Should we need to add an OffsetSpec on the client side to make the earliest_pending_upload_offset queryable from command line tools similar to 6e32448?

@kamalcph I can make it as part of a separate change. Will that be ok?

} else {
Some(new TimestampAndOffset(RecordBatch.NO_TIMESTAMP, -1L, Optional.of(-1)))
}
} else if (targetTimestamp == ListOffsetsRequest.EARLIEST_PENDING_UPLOAD_OFFSET_TIMESTAMP) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we extract this into different method and call it from here especially that the logic here has too many if stataments ? I know the rest of fetchOffsetByTimestamp has been done in-place but the method has grown and it hard to follow.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@kamalcph kamalcph left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM. Left one minor comment to address. Thanks for covering the patch with detailed unit tests!

Comment thread clients/src/main/java/org/apache/kafka/common/requests/ListOffsetsRequest.java Outdated
@abhijeetk88
abhijeetk88 force-pushed the KAFKA-17108 branch 2 times, most recently from bff7bf8 to 5e548a3 Compare August 16, 2024 15:11
@abhijeetk88

Copy link
Copy Markdown
Contributor Author

@kamalcph @OmniaGM addressed your comments. PTAL again.

@kamalcph kamalcph left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for addressing the review comments!

Should we have to bump the ListOffsetRequest version for this change? PTAL.

cc @showuon @satishd

@showuon showuon self-assigned this Sep 6, 2024
@kamalcph

kamalcph commented Oct 7, 2024

Copy link
Copy Markdown
Contributor

@abhijeetk88

Please rebase this PR with trunk.

@github-actions

github-actions Bot commented Jan 6, 2025

Copy link
Copy Markdown

This PR is being marked as stale since it has not had any activity in 90 days. If you
would like to keep this PR alive, please leave a comment asking for a review. If the PR has
merge conflicts, update it with the latest from the base branch.

If you are having difficulty finding a reviewer, please reach out on the [mailing list](https://kafka.apache.org/contact).

If this PR is no longer valid or desired, please feel free to close it. If no activity occurs in the next 30 days, it will be automatically closed.

@github-actions github-actions Bot added the stale Stale PRs label Jan 6, 2025
@abhijeetk88

Copy link
Copy Markdown
Contributor Author

I would like to revive this PR. @kamalcph @showuon will you be able to help with reviews. I can rebase the PR with trunk.

@github-actions github-actions Bot removed the stale Stale PRs label Jan 13, 2025
@github-actions

Copy link
Copy Markdown

This PR is being marked as stale since it has not had any activity in 90 days. If you
would like to keep this PR alive, please leave a comment asking for a review. If the PR has
merge conflicts, update it with the latest from the base branch.

If you are having difficulty finding a reviewer, please reach out on the [mailing list](https://kafka.apache.org/contact).

If this PR is no longer valid or desired, please feel free to close it. If no activity occurs in the next 30 days, it will be automatically closed.

@github-actions github-actions Bot added the stale Stale PRs label Apr 13, 2025
@github-actions

Copy link
Copy Markdown

This PR has been closed since it has not had any activity in 120 days. If you feel like this
was a mistake, or you would like to continue working on it, please feel free to re-open the
PR and ask for a review.

@github-actions github-actions Bot added the closed-stale PRs that were closed due to inactivity label May 14, 2025
@github-actions github-actions Bot closed this May 14, 2025
@satishd satishd reopened this Aug 18, 2025
@github-actions github-actions Bot added triage PRs from the community core Kafka Broker clients and removed triage PRs from the community closed-stale PRs that were closed due to inactivity stale Stale PRs labels Aug 18, 2025
@github-actions github-actions Bot added the storage Pull requests that target the storage module label Aug 21, 2025
@abhijeetk88
abhijeetk88 requested a review from kamalcph August 21, 2025 09:05

@kamalcph kamalcph left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the patch! Please address the below comments:

  1. ListOffsetsRequest version needs a bump as a new targetTimestamp value is added . Previous comment and
  2. Also, could you add the EarliestPendingUploadSpec in OffsetSpec and cover with integration tests?

Comment thread core/src/test/scala/unit/kafka/log/UnifiedLogTest.scala
@github-actions github-actions Bot added the tools label Aug 25, 2025
@kamalcph

Copy link
Copy Markdown
Contributor

@abhijeetk88

Could you follow this #16781 PR and handle similarly for EarliestPendingUploadSpec? Thanks!

@kamalcph kamalcph left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for the patch!

@kamalcph kamalcph changed the title KAFKA-17108: Earliest pending upload offset KAFKA-17108: Add EarliestPendingUpload offset spec in ListOffsets API Aug 26, 2025
@kamalcph
kamalcph merged commit 8d93d10 into apache:trunk Aug 27, 2025
34 of 36 checks passed
@chia7712

Copy link
Copy Markdown
Member

@abhijeetk88 Do you mind documenting these new APIs in upgrade.html?

* <br/>
* Note: When tiered storage is not enabled, we will return unknown offset.
*/
public static OffsetSpec earliestPendingUpload() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean this new public API

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, will add.

eduwercamacaro pushed a commit to littlehorse-enterprises/kafka that referenced this pull request Nov 12, 2025
…apache#16584)

This is the first part of the implementation of

[KIP-1023](https://cwiki.apache.org/confluence/display/KAFKA/KIP-1023%3A+Follower+fetch+from+tiered+offset)

The purpose of this pull request is for the broker to start returning
the correct offset when it receives a -6 as a timestamp in a ListOffsets
API request.

Added unit tests for the new timestamp.

Reviewers: Kamal Chandraprakash <kamal.chandraprakash@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clients core Kafka Broker storage Pull requests that target the storage module tiered-storage Related to the Tiered Storage feature tools

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants