Skip to content

Conversation

@chirag-wadhwa5
Copy link
Collaborator

@chirag-wadhwa5 chirag-wadhwa5 commented Aug 21, 2025

As per the current implementation in archiveRecords, when LSO is
updated, if we have multiple record batches before the new LSO, then
only the first one gets archived. This is because of the following lines
of code ->

isAnyOffsetArchived = isAnyOffsetArchived || archivePerOffsetBatchRecords(inFlightBatch, startOffset, endOffset - 1, initialState);

isAnyBatchArchived = isAnyBatchArchived || archiveCompleteBatch(inFlightBatch, initialState);

The first record / batch will make isAnyOffsetArchived /
isAnyBatchArchived true, after which this line of code will
short-circuit and the methods archivePerOffsetBatchRecords /
archiveCompleteBatch will not be called again. This PR changes the
order of the expressions so that the short-circuit does not prevent from
archiving all the required batches.

Reviewers: Apoorv Mittal apoorvmittal10@gmail.com

… method so that short-circuit does not prevent archiving necessary records / batches
@github-actions github-actions bot added triage PRs from the community core Kafka Broker KIP-932 Queues for Kafka small Small PRs labels Aug 21, 2025
@chirag-wadhwa5 chirag-wadhwa5 changed the title KAFKA-19630: Changed the order of expressions of || in archiveRecords method so that short-circuit does not prevent archiving necessary records / batches KAFKA-19630: Changed the order of expressions of || in archiveRecords method Aug 21, 2025
@chirag-wadhwa5 chirag-wadhwa5 changed the title KAFKA-19630: Changed the order of expressions of || in archiveRecords method KAFKA-19630: Changed the order of expressions in || in archiveRecords method Aug 21, 2025
@chirag-wadhwa5 chirag-wadhwa5 changed the title KAFKA-19630: Changed the order of expressions in || in archiveRecords method KAFKA-19630: Changed the order of expressions for || in archiveRecords method Aug 21, 2025
@chirag-wadhwa5 chirag-wadhwa5 changed the title KAFKA-19630: Changed the order of expressions for || in archiveRecords method KAFKA-19630: Changed the order of expressions for OR (||) in archiveRecords method Aug 21, 2025
@chirag-wadhwa5 chirag-wadhwa5 changed the title KAFKA-19630: Changed the order of expressions for OR (||) in archiveRecords method KAFKA-19630: Changed the order of operands in Java logical OR (||) within archiveRecords method Aug 21, 2025
@chirag-wadhwa5 chirag-wadhwa5 changed the title KAFKA-19630: Changed the order of operands in Java logical OR (||) within archiveRecords method KAFKA-19630: Reordered operands in Java OR (||) in archiveRecords method Aug 21, 2025
@apoorvmittal10 apoorvmittal10 changed the title KAFKA-19630: Reordered operands in Java OR (||) in archiveRecords method KAFKA-19630: Reordered OR operands in archiveRecords method for SharePartiton Aug 21, 2025
Copy link
Contributor

@apoorvmittal10 apoorvmittal10 left a comment

Choose a reason for hiding this comment

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

LGTM! I have suggested to add 1 more validation in the test.

Comment on lines +4523 to +4524
// Note, the records that are in ACQUIRED state will remain in ACQUIRED state and will be transitioned to a Terminal
// state when the corresponding acquisition lock timer task expires.
Copy link
Contributor

Choose a reason for hiding this comment

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

In the end of this current method:
Can you call sharePartition.acknowledge(MEMBER_ID, List.of(new ShareAcknowledgementBatch(21L, 30L, List.of((byte) 2)))). Validate the response and cached state. This will make sure that acknowledge did nothing and also didn't fail. However, I ll discuss this behaviour in a separate PR, when I ll update the method docs.

Then call sharePartition.cachedState().get(21L).batchAcquisitionLockTimeoutTask().run(); and validate the respective records are directly archived.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for the review. I have made the required changes in the latest commit.

@apoorvmittal10 apoorvmittal10 added ci-approved and removed triage PRs from the community labels Aug 21, 2025
@github-actions github-actions bot removed the small Small PRs label Aug 21, 2025
Copy link
Contributor

@apoorvmittal10 apoorvmittal10 left a comment

Choose a reason for hiding this comment

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

LGTM! Build is failing though.

@apoorvmittal10 apoorvmittal10 merged commit def5f16 into apache:trunk Aug 22, 2025
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-approved core Kafka Broker KIP-932 Queues for Kafka

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants