liaoxin01 commented on code in PR #38962:
URL: https://github.com/apache/doris/pull/38962#discussion_r1709315533


##########
fe/fe-core/src/main/java/org/apache/doris/cloud/storage/CosRemote.java:
##########
@@ -94,6 +111,67 @@ public Triple<String, String, String> getStsToken() throws 
DdlException {
         }
     }
 
+    @Override
+    public ListObjectsResult listObjects(String continuationToken) throws 
DdlException {
+        return listObjectsInner(normalizePrefix(), continuationToken);
+    }
+
+    @Override
+    public ListObjectsResult listObjects(String subPrefix, String 
continuationToken) throws DdlException {
+        return listObjectsInner(normalizePrefix(subPrefix), continuationToken);
+    }
+
+    @Override
+    public ListObjectsResult headObject(String subKey) throws DdlException {
+        initClient();
+        try {
+            String key = normalizePrefix(subKey);
+            ObjectMetadata metadata = 
cosClient.getObjectMetadata(obj.getBucket(), key);
+            ObjectFile objectFile = new ObjectFile(key, getRelativePath(key), 
formatEtag(metadata.getETag()),
+                    metadata.getContentLength());
+            return new ListObjectsResult(Lists.newArrayList(objectFile), 
false, null);
+        } catch (CosServiceException e) {
+            if (e.getStatusCode() == 404) {
+                LOG.warn("NoSuchKey when head object for COS, subKey={}", 
subKey);
+                return new ListObjectsResult(Lists.newArrayList(), false, 
null);
+            }
+            LOG.warn("Failed to head object for COS, subKey={}", subKey, e);
+            throw new DdlException(
+                    "Failed to head object for COS, subKey=" + subKey + ", 
Error code=" + e.getErrorCode()
+                            + ", Error message=" + e.getCause().getMessage());
+        } catch (CosClientException e) {
+            LOG.warn("Failed to head object for COS, subKey={}", subKey, e);
+            throw new DdlException(
+                    "Failed to head object for COS, subKey=" + subKey + ", 
Error code=" + e.getErrorCode()
+                            + ", Error message=" + e.getCause().getMessage());
+        }
+    }
+
+    private ListObjectsResult listObjectsInner(String prefix, String 
continuationToken) throws DdlException {
+        initClient();
+        try {
+            ListObjectsRequest listObjectsRequest = new ListObjectsRequest();
+            listObjectsRequest.setBucketName(obj.getBucket());
+            listObjectsRequest.setPrefix(prefix);
+            listObjectsRequest.setMaxKeys(1000);
+            if (!StringUtils.isEmpty(continuationToken)) {
+                listObjectsRequest.setMarker(continuationToken);
+            }
+            ObjectListing objectListing = 
cosClient.listObjects(listObjectsRequest);
+            List<COSObjectSummary> cosObjectSummaries = 
objectListing.getObjectSummaries();
+            List<ObjectFile> objectFiles = new ArrayList<>();
+            for (COSObjectSummary s : cosObjectSummaries) {
+                objectFiles.add(
+                        new ObjectFile(s.getKey(), 
getRelativePath(s.getKey()), formatEtag(s.getETag()), s.getSize()));
+            }
+            return new ListObjectsResult(objectFiles, 
objectListing.isTruncated(), objectListing.getMarker());
+        } catch (CosClientException e) {
+            LOG.warn("Failed to list objects for OSS", e);

Review Comment:
   ```suggestion
               LOG.warn("Failed to list objects for COS", e);
   ```



-- 
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]

Reply via email to