roryqi commented on code in PR #13384:
URL: https://github.com/apache/gravitino/pull/13384#discussion_r4534923834


##########
iceberg/iceberg-common/src/main/java/org/apache/gravitino/iceberg/common/ops/IcebergCatalogWrapper.java:
##########
@@ -330,6 +331,23 @@ public LoadTableResponse updateTable(IcebergTableChange 
icebergTableChange) {
     return loadTable(icebergTableChange.getTableIdentifier());
   }
 
+  /**
+   * Builds an {@link IcebergTableChange} and commits it within a single 
proxied call. When this
+   * wrapper is behind the {@link KerberosAwareIcebergCatalogProxy}, the 
entire operation —
+   * including the metadata.json read triggered by {@code loadTable()} inside 
the builder — runs
+   * under the impersonated user's UGI context.
+   *
+   * @param builder a function that uses the underlying catalog to build an 
{@link
+   *     IcebergTableChange}
+   * @return the response after committing the table change
+   */
+  public LoadTableResponse buildAndUpdateTable(Function<Catalog, 
IcebergTableChange> builder) {

Review Comment:
   Added in 4155d48022. The regression test uses a mocked Catalog implementing 
SupportsKerberos behind KerberosAwareIcebergCatalogProxy and verifies that the 
builder, table load, transaction creation, commit, and response reload all run 
inside a single doKerberosOperations callback. Both affected modules passed all 
287 unit tests.



##########
catalogs/catalog-lakehouse-iceberg/src/main/java/org/apache/gravitino/catalog/lakehouse/iceberg/ops/IcebergCatalogWrapperHelper.java:
##########
@@ -232,6 +232,22 @@ private void alterTableColumn(
 
   public IcebergTableChange buildIcebergTableChanges(
       NameIdentifier gravitinoNameIdentifier, TableChange... tableChanges) {
+    return buildIcebergTableChanges(icebergCatalog, gravitinoNameIdentifier, 
tableChanges);

Review Comment:
   Removed the old overload in 4155d48022, together with the catalog field and 
constructor argument on the helper. Production code and table-update tests now 
build changes through buildAndUpdateTable with an explicit catalog.



##########
iceberg/iceberg-common/src/main/java/org/apache/gravitino/iceberg/common/ops/IcebergCatalogWrapper.java:
##########
@@ -330,6 +331,23 @@ public LoadTableResponse updateTable(IcebergTableChange 
icebergTableChange) {
     return loadTable(icebergTableChange.getTableIdentifier());
   }
 
+  /**
+   * Builds an {@link IcebergTableChange} and commits it within a single 
proxied call. When this
+   * wrapper is behind the {@link KerberosAwareIcebergCatalogProxy}, the 
entire operation —
+   * including the metadata.json read triggered by {@code loadTable()} inside 
the builder — runs
+   * under the impersonated user's UGI context.
+   *
+   * @param builder a function that uses the underlying catalog to build an 
{@link
+   *     IcebergTableChange}
+   * @return the response after committing the table change
+   */
+  public LoadTableResponse buildAndUpdateTable(Function<Catalog, 
IcebergTableChange> builder) {
+    IcebergTableChange change = builder.apply(getCatalog());

Review Comment:
   Updated the Javadoc in 4155d48022 to explain that getCatalog() returns the 
same raw catalog instance and does not establish impersonation. It explicitly 
requires the builder to execute inside the wrapper method and warns that moving 
it outside would bypass the Kerberos proxy boundary.



##########
iceberg/iceberg-common/src/main/java/org/apache/gravitino/iceberg/common/ops/IcebergCatalogWrapper.java:
##########
@@ -330,6 +331,23 @@ public LoadTableResponse updateTable(IcebergTableChange 
icebergTableChange) {
     return loadTable(icebergTableChange.getTableIdentifier());
   }
 
+  /**
+   * Builds an {@link IcebergTableChange} and commits it within a single 
proxied call. When this
+   * wrapper is behind the {@link KerberosAwareIcebergCatalogProxy}, the 
entire operation —
+   * including the metadata.json read triggered by {@code loadTable()} inside 
the builder — runs
+   * under the impersonated user's UGI context.
+   *
+   * @param builder a function that uses the underlying catalog to build an 
{@link
+   *     IcebergTableChange}
+   * @return the response after committing the table change
+   */
+  public LoadTableResponse buildAndUpdateTable(Function<Catalog, 
IcebergTableChange> builder) {

Review Comment:
   Added the requested proxy-context regression test in 4155d48022. It checks 
that the builder, load, transaction creation, commit, and response reload 
execute within one doKerberosOperations callback on a mocked SupportsKerberos 
catalog. Both affected modules passed all 287 unit tests.



##########
catalogs/catalog-lakehouse-iceberg/src/main/java/org/apache/gravitino/catalog/lakehouse/iceberg/ops/IcebergCatalogWrapperHelper.java:
##########
@@ -232,6 +232,22 @@ private void alterTableColumn(
 
   public IcebergTableChange buildIcebergTableChanges(

Review Comment:
   Removed this overload and the helper-held catalog in 4155d48022. All callers 
now supply the catalog while building changes inside buildAndUpdateTable.



##########
iceberg/iceberg-common/src/main/java/org/apache/gravitino/iceberg/common/ops/IcebergCatalogWrapper.java:
##########
@@ -330,6 +331,23 @@ public LoadTableResponse updateTable(IcebergTableChange 
icebergTableChange) {
     return loadTable(icebergTableChange.getTableIdentifier());
   }
 
+  /**
+   * Builds an {@link IcebergTableChange} and commits it within a single 
proxied call. When this
+   * wrapper is behind the {@link KerberosAwareIcebergCatalogProxy}, the 
entire operation —
+   * including the metadata.json read triggered by {@code loadTable()} inside 
the builder — runs
+   * under the impersonated user's UGI context.
+   *
+   * @param builder a function that uses the underlying catalog to build an 
{@link
+   *     IcebergTableChange}
+   * @return the response after committing the table change
+   */
+  public LoadTableResponse buildAndUpdateTable(Function<Catalog, 
IcebergTableChange> builder) {
+    IcebergTableChange change = builder.apply(getCatalog());
+    Transaction transaction = change.getTransaction();
+    transaction.commitTransaction();
+    return loadTable(change.getTableIdentifier());

Review Comment:
   This could return stale metadata. Fixed in 4155d48022: buildAndUpdateTable 
now delegates to updateTable(IcebergTableChange), which invalidates the 
metadata cache before committing and reloads the table afterward to refresh the 
response and cache. Added parameterized regression coverage for both 
transaction-update entry points with stale cached metadata.



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