CalvinKirs commented on code in PR #64695: URL: https://github.com/apache/doris/pull/64695#discussion_r3586485941
########## fe/fe-filesystem/fe-filesystem-oss-hdfs/src/main/java/org/apache/doris/filesystem/hdfs/properties/OssHdfsProperties.java: ########## @@ -0,0 +1,175 @@ +// 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. + +package org.apache.doris.filesystem.hdfs.properties; + +import org.apache.doris.foundation.property.ConnectorProperty; + +import com.google.common.collect.ImmutableSet; +import org.apache.commons.lang3.StringUtils; + +import java.util.Map; +import java.util.Optional; +import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * Aliyun OSS-HDFS (JindoFS) storage properties for fe-filesystem. + * + * <p>OSS-HDFS is an HDFS-compatible service over OSS, addressed with {@code oss://} URIs and + * served by the JindoFS Hadoop FileSystem ({@code com.aliyun.jindodata.oss.JindoOssFileSystem}). + * It therefore sits on the shared {@link HdfsCompatibleProperties} base alongside plain + * {@link HdfsProperties} and produces a backend config map for {@code DFSFileSystem}; the only + * delta is the Jindo {@code fs.oss.*} wiring plus oss-dls endpoint/region handling.</p> + * + * <p>Self-contained port of the kernel {@code OSSHdfsProperties}, with zero fe-core / fe-common + * dependency. The Jindo impl class names are kept as string constants (loaded reflectively by the + * backend), so no compile dependency on the Jindo SDK is introduced.</p> + * + * <p>The normalized {@code fs.oss.*} backend keys are accepted as aliases so the binder is a + * fixpoint for converter-produced maps: fe-core's StoragePropertiesConverter hands the plugin + * {@code getBackendConfigProperties()} output (plus the {@code _STORAGE_TYPE_} marker), not the + * raw user keys, and rebinding that map must yield the same configuration.</p> + */ +public class OssHdfsProperties extends HdfsCompatibleProperties { + + private static final String JINDO_OSS_FILE_SYSTEM_IMPL = + "com.aliyun.jindodata.oss.JindoOssFileSystem"; + private static final String JINDO_OSS_ABSTRACT_FILE_SYSTEM_IMPL = + "com.aliyun.jindodata.oss.JindoOSS"; + + private static final String OSS_HDFS_PREFIX_KEY = "oss.hdfs."; + private static final String OSS_HDFS_ENDPOINT_SUFFIX = ".oss-dls.aliyuncs.com"; + + private static final Set<String> OSS_ENDPOINT_KEY_NAME = ImmutableSet.of("oss.hdfs.endpoint", + "oss.endpoint", "dlf.endpoint", "dlf.catalog.endpoint"); + + private static final Set<Pattern> ENDPOINT_PATTERN = ImmutableSet.of( + Pattern.compile("(?:https?://)?([a-z]{2}-[a-z0-9-]+)\\.oss-dls\\.aliyuncs\\.com"), + Pattern.compile("^(?:https?://)?dlf(?:-vpc)?\\.([a-z0-9-]+)\\.aliyuncs\\.com(?:/.*)?$")); + + private static final Set<String> SUPPORT_SCHEMA = ImmutableSet.of("oss", "hdfs"); + + @ConnectorProperty(names = {"oss.hdfs.endpoint", "oss.endpoint", "dlf.endpoint", "dlf.catalog.endpoint", + "fs.oss.endpoint"}, + description = "The endpoint of OSS.") + private String endpoint = ""; + + @ConnectorProperty(names = {"oss.hdfs.access_key", "oss.access_key", "dlf.access_key", "dlf.catalog.accessKeyId", + "fs.oss.accessKeyId"}, + sensitive = true, + description = "The access key of OSS.") + private String accessKey = ""; + + @ConnectorProperty(names = {"oss.hdfs.secret_key", "oss.secret_key", "dlf.secret_key", "dlf.catalog.secret_key", + "fs.oss.accessKeySecret"}, + sensitive = true, + description = "The secret key of OSS.") + private String secretKey = ""; + + @ConnectorProperty(names = {"oss.hdfs.region", "oss.region", "dlf.region", "fs.oss.region"}, + required = false, + description = "The region of OSS.") + private String region = ""; + + @ConnectorProperty(names = {"oss.hdfs.fs.defaultFS"}, required = false, description = "") + private String fsDefaultFS = ""; + + @ConnectorProperty(names = {"oss.hdfs.hadoop.config.resources"}, + required = false, + description = "The xml files of Hadoop configuration.") + private String hadoopConfigResources = ""; + + @ConnectorProperty(names = {"oss.hdfs.security_token", "oss.security_token", "fs.oss.securityToken"}, + required = false, + sensitive = true, + description = "The security token of OSS.") + private String securityToken = ""; + + public OssHdfsProperties(Map<String, String> origProps) { + super(origProps); + } + + /** + * Cheap, deterministic detection of an OSS-HDFS configuration: an explicit {@code oss.hdfs.} + * enable flag, or any endpoint key pointing at an {@code *.oss-dls.aliyuncs.com} host. + */ + public static boolean guessIsMe(Map<String, String> props) { + boolean enable = props.entrySet().stream() + .anyMatch(e -> e.getKey().equalsIgnoreCase(OSS_HDFS_PREFIX_KEY) + && Boolean.parseBoolean(e.getValue())); + if (enable) { + return true; + } + return OSS_ENDPOINT_KEY_NAME.stream() + .map(props::get) + .anyMatch(ep -> StringUtils.isNotBlank(ep) && ep.endsWith(OSS_HDFS_ENDPOINT_SUFFIX)); + } + + static Optional<String> extractRegion(String endpoint) { + for (Pattern pattern : ENDPOINT_PATTERN) { + Matcher matcher = pattern.matcher(endpoint.toLowerCase()); + if (matcher.matches()) { + return Optional.ofNullable(matcher.group(1)); + } + } + return Optional.empty(); + } + + private void convertDlfToOssEndpointIfNeeded() { + if (this.endpoint.contains("dlf")) { + this.endpoint = this.region + ".oss-dls.aliyuncs.com"; + } + } + + @Override + protected void doInitNormalizeAndCheckProps() { + // Derive region from the endpoint when not explicitly set, e.g. + // "cn-shanghai.oss-dls.aliyuncs.com" -> "cn-shanghai". + if (StringUtils.isBlank(this.region)) { + Optional<String> regionOptional = extractRegion(endpoint); + if (!regionOptional.isPresent()) { + throw new IllegalArgumentException("The region extracted from the endpoint is empty. " + + "Please check the endpoint format: " + endpoint + " or set oss.hdfs.region"); + } + this.region = regionOptional.get(); + } + convertDlfToOssEndpointIfNeeded(); + if (StringUtils.isBlank(fsDefaultFS)) { + this.fsDefaultFS = HdfsPropertiesUtils.extractDefaultFsFromUri(origProps, SUPPORT_SCHEMA); + } + initConfigurationParams(); + } + + private void initConfigurationParams() { + Map<String, String> config = loadConfigFromFile(hadoopConfigResources); + config.put("fs.oss.endpoint", endpoint); Review Comment: Fixed in 77e63c7880d. `initConfigurationParams()` now passes `hadoop.`/`dfs.`/`fs.` prefixed entries from the input map through (after the XML load, before the derived keys, so the fixed credential/endpoint/impl keys still win), and `fs.defaultFS` is accepted as a binder alias like the HDFS/JFS plugins. That restores master's behavior, where the whole converted map went into `DFSFileSystem`'s configuration verbatim. Extended the round-trip test with XML-style Jindo tuning keys, `fs.defaultFS`, and the system-injected markers (which must not leak through). One clarification: the "existing backend entries such as XML-loaded fs.oss.* keys" part is right, but raw catalog `fs.oss.*` extras were never part of the kernel's backend map either — kernel `initConfigurationParams` only emits XML-sourced entries plus the fixed keys — so the parity gap was exactly the XML-loaded entries and `fs.defaultFS`, both covered now. -- 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]
