hello-stephen commented on code in PR #71396:
URL: https://github.com/apache/doris/pull/71396#discussion_r4790117872


##########
fe/fe-core/src/main/java/org/apache/doris/datasource/iceberg/IcebergTransaction.java:
##########
@@ -744,20 +761,33 @@ public void commit() throws UserException {
      */
     @VisibleForTesting
     org.apache.iceberg.Transaction newWriteTransaction() {
-        if (!writeSchemaContext.isPresent()) {
-            return table.newTransaction();
+        return newWriteTransaction(table);
+    }
+
+    private org.apache.iceberg.Transaction newWriteTransaction(Table 
writeTable) {
+        if (!(writeTable instanceof HasTableOperations)) {
+            Preconditions.checkState(!writeSchemaContext.isPresent(),
+                    "Iceberg write table %s does not expose table operations", 
writeTable.name());
+            return writeTable.newTransaction();
+        }
+        TableOperations operations = ((HasTableOperations) 
writeTable).operations();
+        FileIO fileIO = operations.io();
+        if (fileIO instanceof HadoopFileIO) {

Review Comment:
   [P2] Preserve configured Hadoop FileIO overrides
   
   A catalog can set `io-impl` to a `HadoopFileIO` subclass. This check wraps 
that instance, so Iceberg’s typed `newInputFile(ManifestFile)` call now falls 
through to the default path-based implementation and `BaseTransaction` cleanup 
uses the stock `deleteFiles` implementation. A subclass that opens manifests 
through its typed hook can fail an overwrite, and one that relies on bulk 
deletion can leave uncommitted files behind. Limit this adapter to stock 
`HadoopFileIO` or preserve those custom overrides. [Manifest 
input](https://github.com/apache/iceberg/blob/apache-iceberg-1.11.0/core/src/main/java/org/apache/iceberg/ManifestFiles.java#L533-L538)
 · [Transaction 
cleanup](https://github.com/apache/iceberg/blob/apache-iceberg-1.11.0/core/src/main/java/org/apache/iceberg/BaseTransaction.java#L409-L411)



##########
regression-test/suites/external_table_p0/kerberos/test_iceberg_hadoop_catalog_kerberos.groovy:
##########
@@ -20,6 +20,7 @@ suite("test_iceberg_hadoop_catalog_kerberos", 
"p0,external,kerberos,external_doc
     if (enabled == null || !enabled.equalsIgnoreCase("true")) {
         return
     }
+    // Exercise SDK HadoopFileIO so asynchronous manifest writes must carry 
catalog authentication.

Review Comment:
   [P2] Keep snapshot expiration authenticated in the Hadoop Kerberos suite
   
   This switch to raw `HadoopFileIO` also changes the existing 
`expire_snapshots` step. Rolling back and appending again puts the second 
snapshot outside main’s ancestry. Iceberg commits the expiration, then opens 
that snapshot’s manifest list on its shared planner using the action’s raw 
FileIO. A reused worker without this catalog’s credentials can make the 
statement fail after the expiration has committed. Keep `DelegateFileIO` in the 
action fixture and exercise stock FileIO in a separate write case, or 
authenticate the expiration planner. [Expiration commit and 
cleanup](https://github.com/apache/iceberg/blob/apache-iceberg-1.11.0/core/src/main/java/org/apache/iceberg/RemoveSnapshots.java#L324-L372)
 · [Worker manifest 
reads](https://github.com/apache/iceberg/blob/apache-iceberg-1.11.0/core/src/main/java/org/apache/iceberg/ReachableFileCleanup.java#L131-L153)



##########
regression-test/suites/external_table_p0/kerberos/test_iceberg_hms_manifest_kerberos.groovy:
##########
@@ -0,0 +1,127 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+suite("test_iceberg_hms_manifest_kerberos", 
"p0,external,kerberos,external_docker,external_docker_kerberos") {
+    if 
(!"true".equalsIgnoreCase(context.config.otherConfigs.get("enableKerberosTest")))
 {
+        return
+    }
+    String externalEnvIp = context.config.otherConfigs.get("externalEnvIp")
+    String suffix = UUID.randomUUID().toString().replace("-", "").substring(0, 
12)
+    String database = "manifest_auth_${suffix}"
+    def fixtures = [
+        [catalog: "iceberg_manifest_a_${suffix}", realm: "LABS.TERADATA.COM", 
host: "hadoop-master",
+         hmsPort: 9583, hdfsPort: 8520, keytab: "hive-presto-master.keytab"],
+        [catalog: "iceberg_manifest_b_${suffix}", realm: "OTHERREALM.COM", 
host: "hadoop-master-2",
+         hmsPort: 9683, hdfsPort: 8620, keytab: 
"other-hive-presto-master.keytab"]
+    ]
+    String rules = 'RULE:[2:$1@$0](.*@LABS.TERADATA.COM)s/@.*//\n' +
+            'RULE:[2:$1@$0](.*@OTHERREALM.COM)s/@.*//\nDEFAULT'
+    def overwriteModeRows = sql "SHOW VARIABLES LIKE 
'iceberg_partition_overwrite_mode'"
+    String previousOverwriteMode = overwriteModeRows.isEmpty() ? null : 
overwriteModeRows[0][1].toString()
+    Throwable failure = null
+    try {
+        if (previousOverwriteMode != null) {
+            sql "SET iceberg_partition_overwrite_mode = 'dynamic'"
+        }
+        fixtures.each { fixture ->
+            // Keep the SDK HadoopFileIO: DelegateFileIO would mask a 
manifest-worker authentication regression.
+            sql """
+                CREATE CATALOG `${fixture.catalog}` PROPERTIES (
+                    "type" = "iceberg",
+                    "iceberg.catalog.type" = "hms",
+                    "warehouse" = 
"hdfs://${externalEnvIp}:${fixture.hdfsPort}/tmp/iceberg/${database}",
+                    "hive.metastore.uris" = 
"thrift://${externalEnvIp}:${fixture.hmsPort}",
+                    "hive.metastore.sasl.enabled" = "true",
+                    "hive.metastore.kerberos.principal" = 
"hive/${fixture.host}@${fixture.realm}",
+                    "fs.defaultFS" = 
"hdfs://${externalEnvIp}:${fixture.hdfsPort}",
+                    "hadoop.security.authentication" = "kerberos",
+                    "hadoop.kerberos.principal" = 
"hive/presto-master.docker.cluster@${fixture.realm}",
+                    "hadoop.kerberos.keytab" = "/keytabs/${fixture.keytab}",
+                    "hadoop.security.auth_to_local" = "${rules}",
+                    "dfs.namenode.kerberos.principal" = 
"hdfs/${fixture.host}@${fixture.realm}",
+                    "dfs.client.use.datanode.hostname" = "true",
+                    "hadoop.security.token.service.use_ip" = "false",
+                    "dfs.data.transfer.protection" = "authentication",
+                    "meta.cache.iceberg.manifest.enable" = "true"
+                )
+            """
+            sql "CREATE DATABASE `${fixture.catalog}`.`${database}`"
+            sql """
+                CREATE TABLE `${fixture.catalog}`.`${database}`.events (id 
INT, payload STRING)
+                ENGINE = iceberg PROPERTIES ("write-format" = "parquet")
+            """
+        }
+        def tableName = { fixture -> 
"`${fixture.catalog}`.`${database}`.events" }
+        def checkRows = { fixture, expected ->
+            sql "REFRESH TABLE ${tableName(fixture)}"
+            def rows = sql "SELECT id, payload FROM ${tableName(fixture)} 
ORDER BY id"
+            assertEquals(expected, rows.collect { row -> row.collect { value 
-> value.toString() } })
+        }
+        // Alternate realms on the same FE so a shared SDK worker must not 
retain the previous catalog's identity.
+        fixtures.each { fixture -> sql "INSERT INTO ${tableName(fixture)} 
VALUES (1, 'first')" }
+        fixtures.reverseEach { fixture -> sql "INSERT INTO 
${tableName(fixture)} VALUES (2, 'second')" }
+        fixtures.each { fixture -> checkRows(fixture, [["1", "first"], ["2", 
"second"]]) }
+        fixtures.each { fixture ->
+            sql "INSERT OVERWRITE TABLE ${tableName(fixture)} SELECT 3, 
'replacement'"
+            checkRows(fixture, [["3", "replacement"]])
+            def snapshots = sql "SELECT count(*) FROM 
`${fixture.catalog}`.`${database}`.`events\$snapshots`"
+            assertEquals(3L, snapshots[0][0] as long)
+            assertFalse((sql "SELECT * FROM 
`${fixture.catalog}`.`${database}`.`events\$history`").isEmpty())
+            assertFalse((sql "SELECT * FROM 
`${fixture.catalog}`.`${database}`.`events\$manifests`").isEmpty())
+            sql "INSERT OVERWRITE TABLE ${tableName(fixture)} SELECT 4, 
'empty' WHERE 1 = 0"
+            checkRows(fixture, [])
+            // Two new appends and REFRESH expose parallel reads during an 
empty dynamic overwrite.
+            sql "INSERT INTO ${tableName(fixture)} VALUES (5, 
'first-manifest')"
+            sql "INSERT INTO ${tableName(fixture)} VALUES (6, 
'second-manifest')"
+            checkRows(fixture, [["5", "first-manifest"], ["6", 
"second-manifest"]])
+            sql "REFRESH TABLE ${tableName(fixture)}"
+            sql "INSERT OVERWRITE TABLE ${tableName(fixture)} SELECT 7, 
'empty' WHERE 1 = 0"
+            checkRows(fixture, [])
+        }
+    } catch (Throwable error) {
+        failure = error
+        throw error
+    } finally {
+        List<Throwable> cleanupErrors = []
+        fixtures.reverseEach { fixture ->
+            ["DROP TABLE IF EXISTS `${fixture.catalog}`.`${database}`.events",

Review Comment:
   [P3] Clean up the HMS fixture paths under the catalog identity
   
   The HMS `DROP TABLE` purges through the raw `HadoopFileIO`. Iceberg logs and 
suppresses failures from manifest-read and bulk-delete workers, so the cleanup 
SQL can succeed while files remain if a worker lacks that realm’s credentials. 
`DROP DATABASE` keeps the HDFS data. Add authenticated cleanup for each run’s 
unique fixture paths so repeat runs against the same HDFS do not accumulate 
orphan files. [Purge 
behavior](https://github.com/apache/iceberg/blob/apache-iceberg-1.11.0/core/src/main/java/org/apache/iceberg/CatalogUtil.java#L150-L212)
 · [Namespace 
drop](https://github.com/apache/iceberg/blob/apache-iceberg-1.11.0/hive-metastore/src/main/java/org/apache/iceberg/hive/HiveCatalog.java#L507-L520)



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