hello-stephen commented on code in PR #71411:
URL: https://github.com/apache/doris/pull/71411#discussion_r4796708941
##########
fe/fe-core/src/main/java/org/apache/doris/datasource/property/metastore/IcebergRestProperties.java:
##########
@@ -233,12 +238,25 @@ public Catalog initCatalog(String catalogName,
Map<String, String> catalogProps,
protected RESTSessionCatalog buildRestSessionCatalog(String catalogName,
Map<String, String> catalogProps,
Configuration configuration) {
- RESTSessionCatalog sessionCatalog = new RESTSessionCatalog();
+ RESTSessionCatalog sessionCatalog = new RESTSessionCatalog(
+ props ->
HTTPClient.builder(props).uri(props.get(CatalogProperties.URI))
+ .withHeaders(RESTUtil.configHeaders(props)).build(),
+ (context, props) -> buildRestFileIO(props, configuration));
Review Comment:
[P2] Preserve the shared FileIO for REST tables without overrides. Iceberg
reuses the catalog FileIO for empty table config and credentials only when the
builder is absent. This unconditional builder therefore gives each loaded table
generation a separate FileIO even in a catalog using explicit `S3FileIO`. A
multi-table S3 workload now creates separate SDK client pools and, with
`io.manifest.cache-enabled=true`, competes for one of the SDK’s bounded
manifest caches per FileIO. Retain the shared owner for the empty-response case
and keep table-specific owners for table overrides or vended credentials.
[Iceberg table FileIO reuse
condition](https://github.com/apache/iceberg/blob/apache-iceberg-1.11.0/core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java#L1113-L1122),
[Iceberg per-FileIO manifest
cache](https://github.com/apache/iceberg/blob/apache-iceberg-1.11.0/core/src/main/java/org/apache/iceberg/ManifestFiles.java#L55-L76)
##########
fe/fe-iceberg-common/src/main/java/org/apache/iceberg/io/NativeGcsResolvingFileIO.java:
##########
@@ -17,42 +17,217 @@
package org.apache.iceberg.io;
+import org.apache.iceberg.CatalogUtil;
+import org.apache.iceberg.gcp.GCPProperties;
+import org.apache.iceberg.gcp.gcs.PrefixAwareGcsFileIO;
+
+import org.apache.doris.iceberg.GcsOAuthTokenValidator;
+import org.apache.hadoop.conf.Configuration;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
import java.util.Map;
/**
- * A {@link ResolvingFileIO} that preserves the legacy Hadoop GCS path unless
SDK storage options exist.
+ * A {@link ResolvingFileIO} that preserves Hadoop GCS credentials unless SDK
credentials override them.
*
- * <p>Adding iceberg-gcp makes the SDK route these locations to GCSFileIO,
which does not read the
- * {@code fs.s3a.*} HMAC settings Doris supplies. Both FE and the BE metadata
scanner must load this
- * implementation because its class name is carried inside serialized Iceberg
scan tasks. Explicit
- * {@code gcs.*} storage options retain the SDK path, including options
supplied after FE selection.
+ * <p>Doris configures GCS access as Hadoop properties: native credentials
(credential provider type,
+ * service-account impersonation) as {@code fs.gs.*}, and HMAC
interoperability keys or anonymous access as
+ * {@code fs.s3a.*}. Only the Hadoop filesystems read them. Upstream
ResolvingFileIO
+ * routes {@code gs} to {@code GCSFileIO} whenever iceberg-gcp is on the
classpath and falls back to
+ * HadoopFileIO only when that class is missing. Both runtimes bundle
iceberg-gcp for the REST
+ * catalog's {@code GoogleAuthManager} and an explicitly chosen {@code
GCSFileIO}, so this class pins
+ * the default routing instead of relying on that class being absent. SDK
credentials and their storage options retain
+ * the SDK path, including credentials received after FE selection. Other
schemes resolve as upstream.
*
- * <p>The SDK package is required because {@code implFromLocation} is
package-private. It also keeps
- * this class and iceberg-core in the same class loader on both sides of a
metadata scan.
+ * <p>It lives in {@code org.apache.iceberg.io} because {@code
implFromLocation} is package-private; the
+ * override only takes effect when this class and iceberg-core share a class
loader, which holds for the
+ * FE catalog and the BE metadata scanner, both of which bundle iceberg-core
themselves. Its class
+ * name is part of serialized Iceberg scan tasks, so it must stay loadable on
both sides.
*/
public class NativeGcsResolvingFileIO extends ResolvingFileIO {
private static final long serialVersionUID = 1L;
private static final String GCS_FILE_IO_IMPL =
"org.apache.iceberg.gcp.gcs.GCSFileIO";
private static final String HADOOP_FILE_IO_IMPL =
"org.apache.iceberg.hadoop.HadoopFileIO";
- public static boolean hasSdkGcsProperties(Map<String, String> properties) {
- return properties.entrySet().stream()
- .anyMatch(entry -> entry.getKey().startsWith("gcs.") &&
entry.getValue() != null);
- }
+ // Clients are bounded by credential prefixes, not file locations, and are
rebuilt after serialization.
+ private transient Map<String, DelegateFileIO> scopedIos;
+ private volatile Boolean hadoopGcsConfigured;
+ private boolean closed;
@Override
- String implFromLocation(String location) {
+ synchronized String implFromLocation(String location) {
String impl = super.implFromLocation(location);
if (!GCS_FILE_IO_IMPL.equals(impl)) {
return impl;
}
- // REST/table options and matching vended credentials can arrive after
FE chose this resolver.
- // HadoopFileIO ignores SDK encryption and billing options, so those
must keep the native path.
- if (hasSdkGcsProperties(properties()) ||
credentials().stream().anyMatch(credential ->
- location.startsWith(credential.prefix()) &&
hasSdkGcsProperties(credential.config()))) {
+ StorageCredential matching = matchingCredential(location);
+ Map<String, String> scope = matching == null ? Collections.emptyMap()
: matching.config();
+ // Validate the effective scope before choosing an identity: a present
null token is not an absent token.
+ GcsOAuthTokenValidator.validate(properties(), scope);
+ Map<String, String> effective = effectiveProperties(scope);
+ String impersonation =
effective.get("gcs.impersonate.service-account");
+ boolean sdkIdentity = effective.containsKey("gcs.oauth2.token")
+ || Boolean.parseBoolean(effective.get("gcs.no-auth"))
+ || (impersonation != null && !impersonation.isEmpty());
+ if (sdkIdentity) {
return GCS_FILE_IO_IMPL;
}
- return HADOOP_FILE_IO_IMPL;
+ // Project selection is not authentication. SDK-only options must
never silently replace HMAC with ADC.
+ if (properties().containsKey("gs.access_key") ||
hasHadoopGcsConfiguration()) {
+ for (String key : effective.keySet()) {
+ if (key.startsWith("gcs.") && !"gcs.project-id".equals(key)) {
+ throw new IllegalArgumentException("GCS option requires an
explicit SDK storage identity: " + key);
+ }
+ }
+ return HADOOP_FILE_IO_IMPL;
+ }
+ // With no configured Hadoop identity, retain the upstream SDK/ADC
default.
+ return GCS_FILE_IO_IMPL;
+ }
+
+ private boolean hasHadoopGcsConfiguration() {
+ if (hadoopGcsConfigured == null) {
+ boolean configured = false;
+ Configuration conf = getConf();
+ if (conf != null) {
+ for (Map.Entry<String, String> entry : conf) {
+ String key = entry.getKey();
+ // Tuning-only XML properties must not turn the SDK's ADC
default into a Hadoop identity.
+ if ("fs.gs.impl".equals(key) ||
"fs.AbstractFileSystem.gs.impl".equals(key)
Review Comment:
[P2] Preserve Hadoop-only GCS encryption settings. An operator-installed
Hadoop GCS connector can be discovered through Hadoop’s filesystem service
registry without `fs.gs.impl`. With vending disabled and only
`fs.gs.encryption.*` in `core-site.xml`, the base selected HadoopFileIO and
supplied the customer key when reading an encrypted manifest. This narrower
check switches the same catalog to SDK FileIO, which expects
`gcs.decryption-key` and cannot read the object. Keep the Hadoop route when its
configuration supplies required storage options such as CSEK, and add a case
without an explicit filesystem class. [Hadoop filesystem
discovery](https://github.com/apache/hadoop/blob/rel/release-3.4.2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileSystem.java#L3353-L3376),
[GCS connector encryption
options](https://github.com/GoogleCloudDataproc/hadoop-connectors/blob/master/gcs/CONFIGURATION.md#encryption-csek)
##########
fe/fe-core/src/main/java/org/apache/doris/datasource/property/metastore/IcebergRestProperties.java:
##########
@@ -233,12 +238,25 @@ public Catalog initCatalog(String catalogName,
Map<String, String> catalogProps,
protected RESTSessionCatalog buildRestSessionCatalog(String catalogName,
Map<String, String> catalogProps,
Configuration configuration) {
- RESTSessionCatalog sessionCatalog = new RESTSessionCatalog();
+ RESTSessionCatalog sessionCatalog = new RESTSessionCatalog(
+ props ->
HTTPClient.builder(props).uri(props.get(CatalogProperties.URI))
+ .withHeaders(RESTUtil.configHeaders(props)).build(),
+ (context, props) -> buildRestFileIO(props, configuration));
sessionCatalog.setConf(configuration);
sessionCatalog.initialize(catalogName, catalogProps);
return sessionCatalog;
}
+ protected FileIO buildRestFileIO(Map<String, String> effectiveProperties,
Configuration configuration) {
+ String ioImpl =
effectiveProperties.get(CatalogProperties.FILE_IO_IMPL);
+ // The SDK invokes this after merging server defaults, client
properties, overrides and table config.
+ // Keep explicit implementations and the merged map intact so a later
table choice retains precedence.
+ if (ioImpl == null || ResolvingFileIO.class.getName().equals(ioImpl)) {
+ ioImpl = NativeGcsResolvingFileIO.class.getName();
+ }
+ return CatalogUtil.loadFileIO(ioImpl, effectiveProperties,
configuration);
Review Comment:
[P2] Install vended credentials before initializing explicit FileIOs. The
REST callback calls the three-argument `CatalogUtil.loadFileIO`, which
initializes the implementation with an empty credential list. Iceberg supplies
the table credentials only after the callback returns. The base passed them
before `initialize`, as documented by `CatalogUtil`. An explicit `io-impl` that
requires or captures credentials during initialization can now fail a table
load or initialize its client with the default identity. Preserve the SDK
initialization order for explicit implementations and cover a FileIO that
checks its credentials in `initialize`. [Iceberg REST FileIO
construction](https://github.com/apache/iceberg/blob/apache-iceberg-1.11.0/core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java#L1087-L1111),
[CatalogUtil initialization
contract](https://github.com/apache/iceberg/blob/apache-iceberg-1.11.0/core/src/main/java/org/apache/iceberg/CatalogUtil.java#L346-L396)
##########
fe/fe-iceberg-common/src/main/java/org/apache/iceberg/io/NativeGcsResolvingFileIO.java:
##########
@@ -17,42 +17,217 @@
package org.apache.iceberg.io;
+import org.apache.iceberg.CatalogUtil;
+import org.apache.iceberg.gcp.GCPProperties;
+import org.apache.iceberg.gcp.gcs.PrefixAwareGcsFileIO;
+
+import org.apache.doris.iceberg.GcsOAuthTokenValidator;
+import org.apache.hadoop.conf.Configuration;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
import java.util.Map;
/**
- * A {@link ResolvingFileIO} that preserves the legacy Hadoop GCS path unless
SDK storage options exist.
+ * A {@link ResolvingFileIO} that preserves Hadoop GCS credentials unless SDK
credentials override them.
*
- * <p>Adding iceberg-gcp makes the SDK route these locations to GCSFileIO,
which does not read the
- * {@code fs.s3a.*} HMAC settings Doris supplies. Both FE and the BE metadata
scanner must load this
- * implementation because its class name is carried inside serialized Iceberg
scan tasks. Explicit
- * {@code gcs.*} storage options retain the SDK path, including options
supplied after FE selection.
+ * <p>Doris configures GCS access as Hadoop properties: native credentials
(credential provider type,
+ * service-account impersonation) as {@code fs.gs.*}, and HMAC
interoperability keys or anonymous access as
+ * {@code fs.s3a.*}. Only the Hadoop filesystems read them. Upstream
ResolvingFileIO
+ * routes {@code gs} to {@code GCSFileIO} whenever iceberg-gcp is on the
classpath and falls back to
+ * HadoopFileIO only when that class is missing. Both runtimes bundle
iceberg-gcp for the REST
+ * catalog's {@code GoogleAuthManager} and an explicitly chosen {@code
GCSFileIO}, so this class pins
+ * the default routing instead of relying on that class being absent. SDK
credentials and their storage options retain
+ * the SDK path, including credentials received after FE selection. Other
schemes resolve as upstream.
*
- * <p>The SDK package is required because {@code implFromLocation} is
package-private. It also keeps
- * this class and iceberg-core in the same class loader on both sides of a
metadata scan.
+ * <p>It lives in {@code org.apache.iceberg.io} because {@code
implFromLocation} is package-private; the
+ * override only takes effect when this class and iceberg-core share a class
loader, which holds for the
+ * FE catalog and the BE metadata scanner, both of which bundle iceberg-core
themselves. Its class
+ * name is part of serialized Iceberg scan tasks, so it must stay loadable on
both sides.
*/
public class NativeGcsResolvingFileIO extends ResolvingFileIO {
private static final long serialVersionUID = 1L;
private static final String GCS_FILE_IO_IMPL =
"org.apache.iceberg.gcp.gcs.GCSFileIO";
private static final String HADOOP_FILE_IO_IMPL =
"org.apache.iceberg.hadoop.HadoopFileIO";
- public static boolean hasSdkGcsProperties(Map<String, String> properties) {
- return properties.entrySet().stream()
- .anyMatch(entry -> entry.getKey().startsWith("gcs.") &&
entry.getValue() != null);
- }
+ // Clients are bounded by credential prefixes, not file locations, and are
rebuilt after serialization.
+ private transient Map<String, DelegateFileIO> scopedIos;
+ private volatile Boolean hadoopGcsConfigured;
+ private boolean closed;
@Override
- String implFromLocation(String location) {
+ synchronized String implFromLocation(String location) {
String impl = super.implFromLocation(location);
if (!GCS_FILE_IO_IMPL.equals(impl)) {
return impl;
}
- // REST/table options and matching vended credentials can arrive after
FE chose this resolver.
- // HadoopFileIO ignores SDK encryption and billing options, so those
must keep the native path.
- if (hasSdkGcsProperties(properties()) ||
credentials().stream().anyMatch(credential ->
- location.startsWith(credential.prefix()) &&
hasSdkGcsProperties(credential.config()))) {
+ StorageCredential matching = matchingCredential(location);
+ Map<String, String> scope = matching == null ? Collections.emptyMap()
: matching.config();
+ // Validate the effective scope before choosing an identity: a present
null token is not an absent token.
+ GcsOAuthTokenValidator.validate(properties(), scope);
+ Map<String, String> effective = effectiveProperties(scope);
+ String impersonation =
effective.get("gcs.impersonate.service-account");
+ boolean sdkIdentity = effective.containsKey("gcs.oauth2.token")
+ || Boolean.parseBoolean(effective.get("gcs.no-auth"))
+ || (impersonation != null && !impersonation.isEmpty());
+ if (sdkIdentity) {
return GCS_FILE_IO_IMPL;
}
- return HADOOP_FILE_IO_IMPL;
+ // Project selection is not authentication. SDK-only options must
never silently replace HMAC with ADC.
+ if (properties().containsKey("gs.access_key") ||
hasHadoopGcsConfiguration()) {
+ for (String key : effective.keySet()) {
+ if (key.startsWith("gcs.") && !"gcs.project-id".equals(key)) {
Review Comment:
[P2] Keep HMAC reads working when a different scope needs OAuth refresh. A
REST table can return a table-level `gcs.oauth2.refresh-credentials-endpoint`
and vend an OAuth token only for its private manifest prefix. A read outside
that prefix has no effective SDK token and should use the configured HMAC
identity. This loop throws on the inherited refresh setting before opening the
HMAC object. Apply refresh settings only when the selected path uses an OAuth
token, and exercise both routes in the same test. [Iceberg attaches refresh to
OAuth
credentials](https://github.com/apache/iceberg/blob/apache-iceberg-1.11.0/gcp/src/main/java/org/apache/iceberg/gcp/GCPAuthUtils.java#L29-L54)
--
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]