collado-mike commented on code in PR #1378:
URL: https://github.com/apache/polaris/pull/1378#discussion_r2053108958


##########
service/common/src/main/java/org/apache/polaris/service/catalog/iceberg/IcebergCatalog.java:
##########
@@ -1328,6 +1346,41 @@ 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

Review Comment:
   Ugh. I see the problem - it is here: 
https://github.com/apache/iceberg/blob/main/core/src/main/java/org/apache/iceberg/TableMetadata.java#L985
 . The `TableMetadata` builder copies the `changes` field from the original, so 
when we set the `metadataLocation`, it looks like we're trying to set it on an 
object that has changes already 🙄
   
   We _can_ do this without reflection if we roundtrip to JSON. Something like 
this diff does work. It does require a roundtrip through Jackson, so there's a 
performance cost 😢. Worth considering whether we'd rather pay the perf cost or 
deal with reflection in the code. The perf cost would scale with the size of 
the `TableMetadata`, though for larger metadata files, we're probably not 
loading the `TableMetadata` in memory at all. 
   
   ```diff
   diff --git 
a/service/common/src/main/java/org/apache/polaris/service/catalog/iceberg/IcebergCatalog.java
 
b/service/common/src/main/java/org/apache/polaris/service/catalog/iceberg/IcebergCatalog.java
   index 2e8fadab..8d77fa84 100644
   --- 
a/service/common/src/main/java/org/apache/polaris/service/catalog/iceberg/IcebergCatalog.java
   +++ 
b/service/common/src/main/java/org/apache/polaris/service/catalog/iceberg/IcebergCatalog.java
   @@ -1242,6 +1242,9 @@ public class IcebergCatalog extends 
BaseMetastoreViewCatalog
                SHOULD_RETRY_REFRESH_PREDICATE,
                getMaxMetadataRefreshRetries(),
                metadataLocation -> {
   +              if (tblMetadata.containsKey(metadataLocation)) {
   +                return tblMetadata.get(metadataLocation);
   +              }
                  String latestLocationDir =
                      latestLocation.substring(0, 
latestLocation.lastIndexOf('/'));
                  // TODO: Once we have the "current" table properties pulled 
into the resolvedEntity
   @@ -1259,6 +1262,8 @@ public class IcebergCatalog extends 
BaseMetastoreViewCatalog
          }
        }
   
   +    Map<String, TableMetadata> tblMetadata = new HashMap<>();
   +
        @Override
        public void doCommit(TableMetadata base, TableMetadata metadata) {
          LOGGER.debug(
   @@ -1400,9 +1405,9 @@ public class IcebergCatalog extends 
BaseMetastoreViewCatalog
          // TODO: we should not need to do this hack, but there's no other way 
to modify
          // currentMetadata / currentMetadataLocation
          if (updateMetadataOnCommit) {
   -        TableOperationsReflectionUtil reflectionUtil = 
TableOperationsReflectionUtil.getInstance();
   -        reflectionUtil.setMetadataFileLocation(metadata, newLocation);
   -        reflectionUtil.setCurrentMetadata(this, metadata, newLocation);
   +        TableMetadata updated =
   +            TableMetadataParser.fromJson(newLocation, 
TableMetadataParser.toJson(metadata));
   +        tblMetadata.put(newLocation, updated);
          }
          if (null == existingLocation) {
            createTableLike(tableIdentifier, entity);
   ```



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

Reply via email to