deardeng commented on code in PR #14405:
URL: https://github.com/apache/doris/pull/14405#discussion_r1040367420


##########
fe/fe-core/src/main/java/org/apache/doris/catalog/S3Resource.java:
##########
@@ -121,12 +126,51 @@ protected void setProperties(Map<String, String> 
properties) throws DdlException
         checkRequiredProperty(S3_ACCESS_KEY);
         checkRequiredProperty(S3_SECRET_KEY);
         checkRequiredProperty(S3_BUCKET);
+
+        // default need check resource conf valid, so need fix ut and 
regression case
+        boolean needCheck = !properties.containsKey(S3_VALIDITY_CHECK)
+                || Boolean.parseBoolean(properties.get(S3_VALIDITY_CHECK));
+        LOG.debug("s3 info need check validity : {}", needCheck);
+        if (needCheck) {
+            boolean available = pingS3();
+            if (!available) {
+                throw new DdlException("S3 can't use, please check your 
properties");
+            }
+        }
+
         // optional
         checkOptionalProperty(S3_MAX_CONNECTIONS, DEFAULT_S3_MAX_CONNECTIONS);
         checkOptionalProperty(S3_REQUEST_TIMEOUT_MS, 
DEFAULT_S3_REQUEST_TIMEOUT_MS);
         checkOptionalProperty(S3_CONNECTION_TIMEOUT_MS, 
DEFAULT_S3_CONNECTION_TIMEOUT_MS);
     }
 
+    private boolean pingS3() {
+        String bucket = "s3://" + properties.getOrDefault(S3_BUCKET, "") + "/";
+        Map<String, String> propertiesPing = new HashMap<>();
+        propertiesPing.put("AWS_ACCESS_KEY", 
properties.getOrDefault(S3_ACCESS_KEY, ""));
+        propertiesPing.put("AWS_SECRET_KEY", 
properties.getOrDefault(S3_SECRET_KEY, ""));
+        propertiesPing.put("AWS_ENDPOINT", "http://"; + 
properties.getOrDefault(S3_ENDPOINT, ""));
+        propertiesPing.put("AWS_REGION", properties.getOrDefault(S3_REGION, 
""));
+        propertiesPing.put(S3Storage.USE_PATH_STYLE, "false");
+        S3Storage storage = new S3Storage(propertiesPing);
+
+        String testFile = bucket + properties.getOrDefault(S3_ROOT_PATH, "") + 
"/test-object-valid.txt";
+        String content = "doris will be better";
+        Status status = storage.directUpload(content, testFile);
+        if (status != Status.OK) {
+            LOG.warn("ping update file status: {}, properties: {}", status, 
propertiesPing);
+            return false;
+        }
+
+        Status delete = storage.delete(testFile);

Review Comment:
   fixed



-- 
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: commits-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to