eric-maynard commented on code in PR #1378:
URL: https://github.com/apache/polaris/pull/1378#discussion_r2051415810


##########
service/common/src/main/java/org/apache/polaris/service/catalog/iceberg/IcebergCatalog.java:
##########
@@ -1328,6 +1347,38 @@ public void doCommit(TableMetadata base, TableMetadata 
metadata) {
       String newLocation = writeNewMetadataIfRequired(base == null, metadata);
       String oldLocation = base == null ? null : base.metadataFileLocation();
 
+      // TODO: we should not need to do this hack, but there's no other way to 
modify
+      // currentMetadata / currentMetadataLocation
+      if (updateMetadataOnCommit) {
+        try {
+          Field tableMetadataField = 
TableMetadata.class.getDeclaredField("metadataFileLocation");
+          tableMetadataField.setAccessible(true);
+          tableMetadataField.set(metadata, newLocation);
+
+          Field unsafeField = Unsafe.class.getDeclaredField("theUnsafe");
+          unsafeField.setAccessible(true);
+          Unsafe unsafe = (Unsafe) unsafeField.get(null);
+          Field changesField = TableMetadata.class.getDeclaredField("changes");
+          changesField.setAccessible(true);
+          long offset = unsafe.objectFieldOffset(changesField);
+          unsafe.putObject(metadata, offset, new ArrayList<MetadataUpdate>());
+
+          Field currentMetadataLocationField =
+              
BaseMetastoreTableOperations.class.getDeclaredField("currentMetadataLocation");
+          currentMetadataLocationField.setAccessible(true);
+          currentMetadataLocationField.set(this, newLocation);

Review Comment:
   Well maybe not worry but at least it's good we are being cautious. The bug 
and the fix here are both subtle.
   
   What I mean is, once the metadata is actually written to the metadata 
location, it should be correct to attach the location to it. If the commit ends 
up failing, it seems like we (in the tests, at least) don't make any 
assumptions that the metadata is still useful after the failed commit. So the 
location of this in the method should not matter. If anything, I would think 
that the TableOperations pointing at a "failed" commit could be troublesome, 
but previously it was just pointing at null.



-- 
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: issues-unsubscr...@polaris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to