szehon-ho commented on code in PR #16960:
URL: https://github.com/apache/iceberg/pull/16960#discussion_r3649138913


##########
core/src/main/java/org/apache/iceberg/RewriteTablePathUtil.java:
##########
@@ -780,24 +781,22 @@ private static long rewriteDVFile(
       String sourcePrefix,
       String targetPrefix)
       throws IOException {
-    List<Blob> rewrittenBlobs = Lists.newArrayList();
-    try (PuffinReader reader = 
Puffin.read(io.newInputFile(deleteFile.location())).build()) {
-      // Read all blobs and rewrite them with updated referenced data file 
paths
-      for (Pair<org.apache.iceberg.puffin.BlobMetadata, ByteBuffer> blobPair :
+    try (PuffinReader reader = 
Puffin.read(io.newInputFile(deleteFile.location())).build();
+        PuffinWriter writer =
+            
Puffin.write(outputFile).createdBy(IcebergBuild.fullVersion()).build()) {

Review Comment:
   Opening the writer alongside the reader changes what happens on the failure 
path.
   
   `PuffinWriter`'s constructor calls `outputFile.create()`, so the output file 
now exists before a single source byte is read — `reader.fileMetadata()` just 
below is the first read, and it can throw on a corrupt footer or a transient IO 
error. Since `PuffinWriter.close()` calls `finish()` when the writer hasn't 
finished, try-with-resources then writes a footer on that path, leaving a 
well-formed Puffin file that holds a subset of the DVs (possibly zero) and is 
indistinguishable from a correct rewrite.
   
   That also affects retries. Puffin has no overwrite option — `PuffinWriter` 
always uses `create()`, and both `HadoopOutputFile.create()` and 
`S3OutputFile.create()` throw `AlreadyExistsException`. 
`RewriteTablePathSparkAction` derives the staging path deterministically from 
the source location via `RewriteTablePathUtil.stagingPath`, so a retried Spark 
task re-enters this method, finds the leftover file, and fails permanently. 
Before this change the writer was only constructed after the read completed, so 
a read failure left nothing behind and the retry succeeded.
   
   `rewriteDataManifest` above co-locates a reader and writer in the same way, 
but its appenders are built with `.overwrite()`, so it isn't exposed to this.



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