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-14151: validate offsets of input records before writing them file #12516

Draft
wants to merge 1 commit into
base: trunk
Choose a base branch
from

Conversation

vincent81jiang
Copy link
Contributor

@vincent81jiang vincent81jiang commented Aug 15, 2022

Validate offsets of records before writing to log segment file.

Committer Checklist (excluded from commit message)

  • Verify design and implementation
  • Verify test coverage and CI build status
  • Verify documentation (including upgrade notes)

@vincent81jiang vincent81jiang changed the title Validate offsets of input records before writing them file KAFKA-14151: validate offsets of input records before writing them file Aug 15, 2022
@vincent81jiang vincent81jiang marked this pull request as draft August 18, 2022 17:42
Copy link
Contributor

@junrao junrao left a comment

Choose a reason for hiding this comment

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

@vincent81jiang : Thanks for the PR. Left a couple of comments.

@@ -176,10 +179,28 @@ class LogSegment private[log] (val log: FileRecords,
throw new LogSegmentOffsetOverflowException(this, offset)
}

/**
* Validate that offsets of records are monotonically increasing and are in [offsetLowerBound, offsetUpperBound] range.
Copy link
Contributor

Choose a reason for hiding this comment

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

We are just verifying the offsets of record batches, not individual records.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right. Will fix the comment.

private def ensureOffsetsInRangeForRecords(records: Records, offsetLowerBound: Long, offsetUpperBound: Long): Unit = {
var offsetLowerBoundForBatch = offsetLowerBound
records.batches.forEach { batch =>
if (batch.baseOffset < offsetLowerBoundForBatch || batch.lastOffset > offsetUpperBound || batch.baseOffset > batch.lastOffset) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Was the issue reported issue in the jira on the leader or the follower? If it's on the leader, currently, each leader append only has one batch. I am wondering if the validation should be done inside LogValidator.validateMessagesAndAssignOffsets.

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