Skip to content
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

kafka: return lowest offset if requested epoch is lower than local log #9264

Merged
merged 1 commit into from
Mar 7, 2023

Conversation

andrwng
Copy link
Contributor

@andrwng andrwng commented Mar 3, 2023

If reading from tiered storage is disabled, we would previously return an offset -1 if the epoch queried fell below the start of our local log.

This doesn't match what happens in Kafka, which returns the next available offset in a higher epoch. This behavior is matched by our lookup when reading from cloud storage.

This patch updates the Kafka handler to return the start offset of our local log if the requested term falls below the local log's beginning.

Backports Required

  • none - not a bug fix
  • none - this is a backport
  • none - issue does not exist in previous branches
  • none - papercut/not impactful enough to backport
  • v23.1.x
  • v22.3.x
  • v22.2.x

Release Notes

Bug Fixes

  • Fixed a bug that would cause Redpanda to return an invalid offset when consuming from a term that falls below the beginning of the local log when reading from tiered storage is disabled.

bharathv
bharathv previously approved these changes Mar 3, 2023
Copy link
Contributor

@bharathv bharathv left a comment

Choose a reason for hiding this comment

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

needs backports?

const auto first_local_term = _partition->get_term(
_partition->start_offset());
// found in local state
const auto first_local_offset = _partition->start_offset();
Copy link
Contributor

Choose a reason for hiding this comment

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

we should post the link to the code of the java upstream here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

// Return the offset of the next-highest term, i.e. the start of the local
// log. This mirrors behavior in Kafka, see
// https://github.com/apache/kafka/pull/5678 for more details.
return _translator->from_log_offset(first_local_offset);
Copy link
Contributor

Choose a reason for hiding this comment

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

this is great. how do we write a test that exercises this path.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I updated one of the tests added when implementing KIP-320. Will look into testing more organically

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Opted to add a unit test, per @graphcareful's suggestion

@piyushredpanda
Copy link
Contributor

Let's get this going, backport and shoot for a minor next week.

@piyushredpanda piyushredpanda added this to the v23.1.x-next milestone Mar 4, 2023
@mattschumpert
Copy link

This seems like the correct new behavior, but also a significant change from what existing apps had been depending on, so definitely needs release notes or changes to any doc page mentioning how this works. @micheleRP. I'm glad it happens to be coming near the first 23.1 release

@piyushredpanda should we also mention this in older version docs in our Kafka compat page (basically it's an incompatibility we're correcting in 23.1)

@andrwng andrwng force-pushed the get-leader-epoch-last-offset branch from d08a5a8 to d6f3889 Compare March 6, 2023 17:27
@andrwng andrwng marked this pull request as ready for review March 6, 2023 17:33
@piyushredpanda
Copy link
Contributor

This seems like the correct new behavior, but also a significant change from what existing apps had been depending on, so definitely needs release notes or changes to any doc page mentioning how this works. @micheleRP. I'm glad it happens to be coming near the first 23.1 release

@piyushredpanda should we also mention this in older version docs in our Kafka compat page (basically it's an incompatibility we're correcting in 23.1)

Lean towards no. I don't know if many users and applications have noticed this; this behavior incompat has certainly been around years and has only just bubbled up. (Sidenote, we will be backporting fix to older branches, not just in v23.1.x)

@andrwng andrwng force-pushed the get-leader-epoch-last-offset branch from d6f3889 to 53830d8 Compare March 7, 2023 01:57
@andrwng andrwng requested a review from bharathv March 7, 2023 01:59
kafka: return lowest offset if requested epoch is lower than local log

If reading from tiered storage is disabled, we would previously return
an offset -1 if the epoch queried fell below the start of our local log.

This doesn't match what happens in Kafka, which returns the next
available offset in a higher epoch. This behavior is matched by our
lookup when reading from cloud storage.

This patch updates the Kafka handler to return the start offset of our
local log if the requested term falls below the local log's beginning.
@andrwng andrwng force-pushed the get-leader-epoch-last-offset branch from 53830d8 to 350c8ec Compare March 7, 2023 02:01
@andrwng andrwng merged commit ff1245c into redpanda-data:dev Mar 7, 2023
@andrwng
Copy link
Contributor Author

andrwng commented Mar 7, 2023

/backport v23.1.x

@andrwng
Copy link
Contributor Author

andrwng commented Mar 7, 2023

/backport v22.3.x

@andrwng
Copy link
Contributor Author

andrwng commented Mar 7, 2023

/backport v22.2.x

@vbotbuildovich
Copy link
Collaborator

Failed to run cherry-pick command. I executed the below command:

git cherry-pick -x 350c8ec6fe846f2417acd1e375d19f9e84139865

Workflow run logs.

@vbotbuildovich
Copy link
Collaborator

Failed to run cherry-pick command. I executed the below command:

git cherry-pick -x 350c8ec6fe846f2417acd1e375d19f9e84139865

Workflow run logs.

@raja
Copy link

raja commented Mar 7, 2023

Thank you 🙏🏾 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants