morningman commented on code in PR #57004:
URL: https://github.com/apache/doris/pull/57004#discussion_r2432904300
##########
fe/fe-core/src/main/java/org/apache/doris/datasource/ExternalCatalog.java:
##########
@@ -132,6 +135,9 @@ public abstract class ExternalCatalog
protected static final int ICEBERG_CATALOG_EXECUTOR_THREAD_NUM =
Runtime.getRuntime().availableProcessors();
+ public static final String TEST_CONNECTIVITY = "test_connectivity";
Review Comment:
Better same as JDBC catalog: `test_connection`
##########
fe/fe-core/src/main/java/org/apache/doris/datasource/property/metastore/MetastoreProperties.java:
##########
@@ -122,4 +123,14 @@ protected MetastoreProperties(Type type, Map<String,
String> props) {
protected MetastoreProperties(Map<String, String> props) {
super(props);
}
+
+ /**
+ * Create connectivity tester for this metadata service.
+ * Subclass can override to provide specific tester.
+ *
+ * @return null if testing not supported
+ */
+ public MetaConnectivityTester createConnectivityTester() {
+ return null; // Default: not supported
Review Comment:
I suggest to create a MetaConnectivityTester instead of nullptr
##########
fe/fe-core/src/main/java/org/apache/doris/datasource/property/storage/StorageProperties.java:
##########
@@ -233,4 +234,14 @@ protected static boolean checkIdentifierKey(Map<String,
String> origProps, List<
public abstract String getStorageName();
public abstract void initializeHadoopStorageConfig();
+
+ /**
+ * Create connectivity tester for this storage.
+ * Subclass can override to provide specific tester.
+ *
+ * @return null if testing not supported
+ */
+ public StorageConnectivityTester createConnectivityTester(String
testLocation) {
+ return null; // Default: not supported
Review Comment:
dito
##########
fe/fe-core/src/main/java/org/apache/doris/datasource/connectivity/HiveMetaStoreConnectivityTester.java:
##########
@@ -0,0 +1,88 @@
+// 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.datasource.connectivity;
+
+import org.apache.doris.datasource.property.metastore.AbstractHMSProperties;
+
+import org.apache.hadoop.hive.conf.HiveConf;
+import org.apache.hadoop.hive.metastore.HiveMetaHookLoader;
+import org.apache.hadoop.hive.metastore.IMetaStoreClient;
+import org.apache.hadoop.hive.metastore.RetryingMetaStoreClient;
+import org.apache.hadoop.hive.metastore.api.Database;
+import org.apache.hadoop.hive.metastore.api.NoSuchObjectException;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+
+/**
+ * Connectivity tester for Hive MetaStore.
+ * Tests connectivity by calling getDatabase("default").
+ */
+public class HiveMetaStoreConnectivityTester implements MetaConnectivityTester
{
+ private static final Logger LOG =
LogManager.getLogger(HiveMetaStoreConnectivityTester.class);
+ private static final HiveMetaHookLoader DUMMY_HOOK_LOADER = t -> null;
+ private final AbstractHMSProperties properties;
+ private String warehouseLocation;
+
+ public HiveMetaStoreConnectivityTester(AbstractHMSProperties properties) {
+ this.properties = properties;
+ }
+
+ @Override
+ public void testConnection() throws Exception {
+ HiveConf hiveConf = properties.getHiveConf();
+
+ // Create a temporary HMS client
+ IMetaStoreClient client = null;
+ try {
+ // Use authentication if configured
+ client = properties.getExecutionAuthenticator()
+ .execute(() -> RetryingMetaStoreClient.getProxy(hiveConf,
DUMMY_HOOK_LOADER,
+
org.apache.hadoop.hive.metastore.HiveMetaStoreClient.class.getName()));
+
+ // Test connectivity by getting the "default" database
+ // Almost all HMS installations have this database
+ // And even if an exception is thrown that does not exist, it can
prove that the connection is successful
+ final IMetaStoreClient finalClient = client;
+ try {
+ Database db =
properties.getExecutionAuthenticator().execute(() ->
finalClient.getDatabase("default"));
Review Comment:
How about using 'listDatabases'?
##########
be/src/io/fs/s3_connectivity_checker.cpp:
##########
@@ -0,0 +1,139 @@
+// 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.
+
+#include "io/fs/s3_connectivity_checker.h"
+
+#include <aws/core/auth/AWSCredentials.h>
+#include <aws/s3/S3Client.h>
+#include <aws/s3/model/HeadBucketRequest.h>
+
+#include "common/logging.h"
+#include "util/s3_uri.h"
+#include "util/s3_util.h"
+
+namespace doris::io {
+
+S3ConnectivityChecker::S3ConnectivityChecker(const std::map<std::string,
std::string>& properties) {
+ auto status = _parse_properties(properties);
+ if (!status.ok()) {
+ LOG(WARNING) << "Failed to parse S3 properties: " <<
status.to_string();
+ }
+}
+
+Status S3ConnectivityChecker::check() {
+ // Validate test_location
+ if (_test_location.empty()) {
+ return Status::InvalidArgument("Missing 'test_location' property");
+ }
+
+ // Extract bucket from test_location
+ std::string bucket;
+ RETURN_IF_ERROR(_extract_bucket_from_location(_test_location, &bucket));
+
+ // Validate required properties for creating S3 client
+ if (_endpoint.empty()) {
+ return Status::InvalidArgument("Missing 'AWS_ENDPOINT' property");
+ }
+ if (_region.empty()) {
+ return Status::InvalidArgument("Missing 'AWS_REGION' property");
+ }
+ if (_access_key.empty()) {
+ return Status::InvalidArgument("Missing 'AWS_ACCESS_KEY' property");
+ }
+ if (_secret_key.empty()) {
+ return Status::InvalidArgument("Missing 'AWS_SECRET_KEY' property");
+ }
+
+ // Configure AWS client
+ Aws::Client::ClientConfiguration config =
S3ClientFactory::getClientConfiguration();
+ config.endpointOverride = _endpoint;
+ config.region = _region;
+
+ // Create credentials
+ Aws::Auth::AWSCredentials credentials(_access_key, _secret_key);
Review Comment:
I think the builder of `Aws::S3::S3Client` should be wrapped in
`be/src/util/s3_util.cpp`, so that all callers share the same code
##########
fe/fe-core/src/main/java/org/apache/doris/datasource/ExternalCatalog.java:
##########
@@ -258,6 +264,42 @@ public boolean ifNotSetFallbackToSimpleAuth() {
// Will be called when creating catalog(not replaying).
// Subclass can override this method to do some check when creating
catalog.
public void checkWhenCreating() throws DdlException {
+ boolean testConnection = Boolean.parseBoolean(
+ catalogProperty.getOrDefault(TEST_CONNECTIVITY,
String.valueOf(DEFAULT_TEST_CONNECTIVITY)));
+
+ if (!testConnection) {
+ return;
+ }
+
+ String testLocation = null;
+
+ // 1. Test Meta connectivity
+ MetaConnectivityTester metaTester =
catalogProperty.getMetastoreProperties().createConnectivityTester();
+ if (metaTester != null) {
+ try {
+ metaTester.testConnection();
+ } catch (Exception e) {
+ throw new DdlException("Meta connectivity test failed: " +
e.getMessage());
Review Comment:
better print the type of metastore
##########
fe/fe-core/src/main/java/org/apache/doris/datasource/ExternalCatalog.java:
##########
@@ -258,6 +264,42 @@ public boolean ifNotSetFallbackToSimpleAuth() {
// Will be called when creating catalog(not replaying).
// Subclass can override this method to do some check when creating
catalog.
public void checkWhenCreating() throws DdlException {
+ boolean testConnection = Boolean.parseBoolean(
+ catalogProperty.getOrDefault(TEST_CONNECTIVITY,
String.valueOf(DEFAULT_TEST_CONNECTIVITY)));
+
+ if (!testConnection) {
+ return;
+ }
+
+ String testLocation = null;
+
+ // 1. Test Meta connectivity
+ MetaConnectivityTester metaTester =
catalogProperty.getMetastoreProperties().createConnectivityTester();
+ if (metaTester != null) {
+ try {
+ metaTester.testConnection();
+ } catch (Exception e) {
+ throw new DdlException("Meta connectivity test failed: " +
e.getMessage());
+ }
+ testLocation = metaTester.getTestLocation();
+ }
+ // 2. Test Storage connectivity
+ Map<StorageProperties.Type, StorageProperties> storagePropertiesMap =
catalogProperty.getStoragePropertiesMap();
+ for (StorageProperties storageProperties :
storagePropertiesMap.values()) {
+ StorageConnectivityTester storageTester =
storageProperties.createConnectivityTester(testLocation);
+ if (storageTester != null) {
+ try {
+ storageTester.testFeConnection();
+ } catch (Exception e) {
+ throw new DdlException("Storage connectivity test failed:
" + e.getMessage());
Review Comment:
better print the type of storage
##########
gensrc/thrift/BackendService.thrift:
##########
@@ -369,6 +369,16 @@ struct TDictionaryStatusList {
1: optional list<TDictionaryStatus> dictionary_status_list
}
+// Storage connectivity test request
+struct TTestStorageConnectivityRequest {
+ 1: required map<string, string> properties;
+}
+
+// Storage connectivity test result
+struct TTestStorageConnectivityResult {
+ 1: required Status.TStatus status;
Review Comment:
```suggestion
1: optional Status.TStatus status;
```
##########
gensrc/thrift/BackendService.thrift:
##########
@@ -369,6 +369,16 @@ struct TDictionaryStatusList {
1: optional list<TDictionaryStatus> dictionary_status_list
}
+// Storage connectivity test request
+struct TTestStorageConnectivityRequest {
+ 1: required map<string, string> properties;
Review Comment:
```suggestion
1: optional map<string, string> properties;
```
--
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]