chia7712 commented on code in PR #24239:
URL: https://github.com/apache/kafka/pull/24239#discussion_r4653623580
##########
clients/src/main/java/org/apache/kafka/common/record/internal/AbstractRecords.java:
##########
@@ -77,15 +79,25 @@ private Iterator<Record> recordsIterator() {
@Override
protected Record makeNext() {
- if (records != null && records.hasNext())
- return records.next();
-
- if (batches.hasNext()) {
- records = batches.next().iterator();
- return makeNext();
+ while (records == null || !records.hasNext()) {
+ if (!batches.hasNext()) {
+ return allDone();
+ }
+
+ RecordBatch batch = batches.next();
+ // The Iterable API has no close method. Compressed
batches must release the
+ // decompression stream before handing records to a caller
that may stop early.
+ if (batch.magic() >= RecordBatch.MAGIC_VALUE_V2 &&
batch.isCompressed()) {
Review Comment:
Records#records has only one usage in production code
(`convertAndAssignOffsetsNonCompressed`), so we could redefine the interface to
return a `CloseableIterator`, allowing us to remove the list allocation here.
--
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]