hello-stephen commented on code in PR #71396:
URL: https://github.com/apache/doris/pull/71396#discussion_r4794823327
##########
fe/fe-core/src/main/java/org/apache/doris/datasource/iceberg/IcebergExternalMetaCache.java:
##########
@@ -1391,14 +1396,25 @@ private ManifestCacheValue loadDeleteFiles(
return builder.build();
}
+ private void trackManifestFileIo(NameMapping nameMapping,
IcebergMetadataOps ops, Table table) {
+ try {
+ fileIoTracker.track(nameMapping.getCtlId(), ops, table.io());
+ } catch (Exception e) {
+ // Cache bookkeeping must not reject a custom metadata-only table
whose IO is unavailable.
+ LOG.warn("Failed to track iceberg FileIO for manifest cache
cleanup", e);
+ }
+ }
+
/**
- * Collect every FileIO a catalog's cached values still retain. A snapshot
value can outlive
+ * Collect tracked catalog IO as well as IO still retained by cached
values. A snapshot value can outlive
* its weighted/expired/collected table entry while retaining the same
frozen table graph, so
* both entries are enumerated; identity de-duplication keeps the later
drop pass bounded.
*/
private List<FileIO> collectManifestFileIos(long catalogId) {
IdentityHashMap<FileIO, Boolean> seen = new IdentityHashMap<>();
- List<FileIO> fileIos = new ArrayList<>();
+ // Writes can outlive every read-cache entry while the captured
catalog generation still owns IO.
+ List<FileIO> fileIos = fileIoTracker.snapshot(catalogId);
Review Comment:
[P2] Clear SDK manifest caches after the Doris group is detached
With SDK manifest caching enabled, start an unpartitioned dynamic empty
overwrite and refresh the catalog after the writer acquires its lease. The
refresh removes the Doris cache group. The retained writer can then refill the
authenticated SDK cache without recreating that group. A second `REFRESH
CATALOG` skips Iceberg in `ExternalMetaCacheMgr.safeInvalidate` because the
group is absent and Iceberg inherits
`supportsInvalidationWithoutCatalogEntries() == false`. Opt Iceberg into
invalidation without an entry group and drive the repeated refresh through the
manager. The new test currently calls the engine directly and bypasses this
guard.
##########
regression-test/suites/external_table_p0/kerberos/test_iceberg_hms_manifest_kerberos.groovy:
##########
@@ -0,0 +1,257 @@
+// 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'
+ // The regression runner also needs the fixture credentials to verify HDFS
cleanup after SDK purge errors.
+ String clientConfig =
context.config.otherConfigs.get("kerberosClientConfig") ?:
+ System.getProperty("java.security.krb5.conf") ?:
System.getenv("KRB5_CONFIG") ?: "/etc/krb5.conf"
+ File configFile = new File(clientConfig).absoluteFile
+ assert configFile.isFile() && configFile.canRead():
+ "Configure kerberosClientConfig with a readable fixture krb5.conf"
+ String clientKeytabDir =
context.config.otherConfigs.get("kerberosClientKeytabDir")
+ if (!clientKeytabDir) {
+ // Rootless hosts keep generated credentials together; older fixtures
still provision /keytabs.
+ File configDirectory = configFile.parentFile
+ boolean adjacentKeytabs = fixtures.every { fixture ->
+ File keytab = new File(configDirectory, fixture.keytab)
+ keytab.isFile() && keytab.canRead()
+ }
+ clientKeytabDir = adjacentKeytabs ? configDirectory.path : "/keytabs"
+ }
+ fixtures.each { fixture ->
+ fixture.warehouse =
"hdfs://${externalEnvIp}:${fixture.hdfsPort}/tmp/iceberg/${database}"
+ assert new File(clientKeytabDir, fixture.keytab).canRead():
+ "Configure kerberosClientKeytabDir with both fixture keytabs"
+ }
+ // Hadoop 2.x uses global UGI state for SASL; isolate each realm from the
parallel regression JVM.
+ String fileSystemScript = '''
+ import org.apache.hadoop.conf.Configuration
+ import org.apache.hadoop.fs.FileSystem
+ import org.apache.hadoop.fs.Path
+ import org.apache.hadoop.security.SecurityUtil
+ import org.apache.hadoop.security.UserGroupInformation
+ import java.security.PrivilegedExceptionAction
+
+ def (principal, keytab, warehouse, namenode, rules, phase, database) =
args
+ URI root = new URI(warehouse)
+ assert database ==~ /manifest_auth_[0-9a-f]{12}/
+ assert root.scheme == "hdfs" && root.authority && root.query == null
&& root.fragment == null
+ assert root.path == "/tmp/iceberg/${database}"
+ Configuration conf = new Configuration(false)
+ conf.set("hadoop.security.authentication", "kerberos")
+ conf.set("hadoop.security.auth_to_local", rules)
+ conf.set("dfs.namenode.kerberos.principal", namenode)
+ conf.set("fs.hdfs.impl",
"org.apache.hadoop.hdfs.DistributedFileSystem")
+ conf.setBoolean("dfs.client.use.datanode.hostname", true)
+ conf.set("dfs.data.transfer.protection", "authentication")
+ SecurityUtil.setTokenServiceUseIp(false)
+ UserGroupInformation.setConfiguration(conf)
+ def identity =
UserGroupInformation.loginUserFromKeytabAndReturnUGI(principal, keytab)
+ identity.doAs({
+ FileSystem fs = FileSystem.newInstance(root, conf)
+ try {
+ Path path = new Path(root)
+ if (phase == "cleanup" && fs.exists(path)) {
+ assert fs.delete(path, true)
+ }
+ assert !fs.exists(path)
+ } finally {
+ fs.close()
+ }
+ return null
+ } as PrivilegedExceptionAction)
+ '''
+ def checkFileSystem = { fixture, phase ->
+ List<String> command = [new File(System.getProperty("java.home"),
"bin/java").path,
+ "-Xmx256m", "-Djava.security.krb5.conf=${clientConfig}", "-cp",
+ System.getProperty("java.class.path"), "groovy.ui.GroovyMain",
"-e", fileSystemScript, "--",
+ "hive/presto-master.docker.cluster@${fixture.realm}",
+ new File(clientKeytabDir, fixture.keytab).path,
fixture.warehouse,
+ "hdfs/${fixture.host}@${fixture.realm}", rules.replace('\\n',
'\n'), phase, database]
+ .collect { it.toString() }
+ String javaVersion = System.getProperty("java.specification.version")
+ int javaMajor = (javaVersion.startsWith("1.") ?
javaVersion.substring(2) : javaVersion).tokenize(".")[0] as int
+ if (javaMajor >= 9) {
+ // Hadoop 2.x uses JDK-internal DNS and Kerberos helpers during
authenticated IPC setup.
+ command.add(1, "--add-exports=java.base/sun.net.dns=ALL-UNNAMED")
+ command.add(1, "--add-exports=java.base/sun.net.util=ALL-UNNAMED")
+ command.add(1,
"--add-exports=java.security.jgss/sun.security.krb5=ALL-UNNAMED")
+ command.add(1,
"--add-exports=java.security.jgss/sun.security.jgss=ALL-UNNAMED")
+ }
+ File output = File.createTempFile("iceberg-manifest-filesystem-",
".log")
+ Process process = null
+ Throwable processFailure = null
+ try {
+ process = new
ProcessBuilder(command).redirectErrorStream(true).redirectOutput(output).start()
+ assert process.waitFor(60, java.util.concurrent.TimeUnit.SECONDS):
+ "Timed out verifying the fixture HDFS directory"
+ assert process.exitValue() == 0: "Fixture HDFS verification
failed: ${output.text}"
+ } catch (Throwable error) {
+ processFailure = error
+ throw error
+ } finally {
+ List<Throwable> errors = []
+ try {
+ if (process != null && process.isAlive()) {
+ process.destroyForcibly()
+ assert process.waitFor(10,
java.util.concurrent.TimeUnit.SECONDS):
+ "The fixture filesystem process did not terminate"
+ }
+ } catch (Throwable error) {
+ errors.add(error)
+ }
+ try {
+ java.nio.file.Files.deleteIfExists(output.toPath())
+ } catch (Throwable error) {
+ errors.add(error)
+ }
+ if (!errors.isEmpty()) {
+ if (processFailure != null) {
+ errors.each { processFailure.addSuppressed(it) }
+ } else {
+ errors.tail().each { errors[0].addSuppressed(it) }
+ throw errors[0]
+ }
+ }
+ }
+ }
+ // Check both identities before creating SQL resources; a missing runner
keytab must fail without leaking data.
+ fixtures.each { checkFileSystem(it, "prepare") }
+ 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" = "${fixture.warehouse}",
+ "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}`
+ PROPERTIES ("location" = "${fixture.warehouse}/database")"""
+ sql """
+ CREATE TABLE `${fixture.catalog}`.`${database}`.events (id
INT, payload STRING)
+ ENGINE = iceberg PROPERTIES ("write-format" = "parquet")
+ """
+ sql """
+ CREATE TABLE `${fixture.catalog}`.`${database}`.empty_source
(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())
+ // An external scan returns zero rows at runtime, so the planner
cannot bypass the overwrite transaction.
+ sql """INSERT OVERWRITE TABLE ${tableName(fixture)}
+ SELECT id, payload FROM
`${fixture.catalog}`.`${database}`.empty_source"""
+ 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)}"
Review Comment:
[P3] Clear the manifest byte cache before the empty overwrite
With the suite’s manifest cache enabled under the default budget
configuration, the preceding `checkRows` can cache both manifests under the
catalog’s raw FileIO. `REFRESH TABLE` keeps those bytes. If `newWriteScan`
falls back to the raw scan, shared workers can then read cached bytes without
opening the secured HDFS manifests, so this check can pass despite the
authentication regression. Use `REFRESH CATALOG` here to clear the raw and
authenticated SDK caches before the overwrite. [Iceberg manifest byte-cache
lookup](https://github.com/apache/iceberg/blob/apache-iceberg-1.11.0/core/src/main/java/org/apache/iceberg/io/ContentCache.java#L204-L229)
--
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]