wombatu-kun commented on code in PR #17150:
URL: https://github.com/apache/iceberg/pull/17150#discussion_r3555946002


##########
core/src/main/java/org/apache/iceberg/avro/AvroIterable.java:
##########
@@ -83,7 +83,16 @@ public CloseableIterator<D> iterator() {
             .setRowPositionSupplier(
                 Suppliers.memoize(() -> 
AvroIO.findStartingRowPos(file::newStream, start)));
       }
-      fileReader = new AvroRangeIterator<>(fileReader, start, end);
+      try {

Review Comment:
   The guard starts one statement too late: `setRowPositionSupplier` on line 82 
can throw before this `try` and leak the same reader. 
`ValueReaders.PositionReader.setRowPositionSupplier` calls `posSupplier.get()` 
eagerly (`core/src/main/java/org/apache/iceberg/avro/ValueReaders.java:1303`), 
so the memoized supplier runs `AvroIO.findStartingRowPos` right there, and that 
throws `InvalidAvroMagicException` 
(`core/src/main/java/org/apache/iceberg/avro/AvroIO.java:163`) or 
`RuntimeIOException` (`AvroIO.java:181`, `AvroIO.java:198`) on the same 
truncated/corrupt file and I/O-error conditions this PR targets.
   
   It is reachable on the same split path: 
`StructReader.setRowPositionSupplier` installs a `PositionReader` whenever 
`_pos` is projected (`ValueReaders.java:1178-1179`), planned readers map `_pos` 
to `ValueReaders.positions()` (`ValueReaders.java:320`), and `DeleteFilter` 
projects `MetadataColumns.ROW_POSITION` whenever position deletes apply 
(`data/src/main/java/org/apache/iceberg/data/DeleteFilter.java:325`).
   
   Move `try {` above the `if (reader instanceof SupportsRowPosition)` on line 
81 so it covers both throw sites. The catch stays correct either way: 
`fileReader` is still the base reader at the first throw site, and after the 
assignment `AvroRangeIterator.close()` delegates to the same reader.



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to