junrao commented on code in PR #21379:
URL: https://github.com/apache/kafka/pull/21379#discussion_r3761497110
##########
storage/src/main/java/org/apache/kafka/storage/internals/log/Cleaner.java:
##########
@@ -401,6 +460,19 @@ public boolean shouldRetainRecord(RecordBatch batch,
Record record) {
if (outputBuffer.position() > 0) {
outputBuffer.flip();
MemoryRecords retained =
MemoryRecords.readableRecords(outputBuffer);
+
+ // While groupSegmentsBySize() ensures source segments don't
exceed Integer.MAX_VALUE,
Review Comment:
Claude found a bug in this PR. The problem is that `checkBatchRetention()`
modifies `transactionMetadata`, which stores the ongoing txn state and is
reused during cleaning. When we detect an overflow, we rewind the cleaning
position to Optional.of(position - result.bytesRead()), but the corresponding
`transactionMetadata` is not rewound. When the cleaning resumes, since
`transactionMetadata` is not accurate, we can have all sorts of bad outcomes.
For example, an aborted record could now appear as a committed record after
cleaning.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]