TSFenwick commented on code in PR #14131:
URL: https://github.com/apache/druid/pull/14131#discussion_r1172741352


##########
extensions-core/s3-extensions/src/main/java/org/apache/druid/storage/s3/S3DataSegmentKiller.java:
##########
@@ -64,6 +69,52 @@ public S3DataSegmentKiller(
     this.inputDataConfig = inputDataConfig;
   }
 
+  @Override
+  public void killBatched(List<DataSegment> segments) throws 
SegmentLoadingException
+  {
+    int size = segments.size();
+    if (size == 0) {
+      return;
+    }
+    if (segments.size() == 1) {
+      kill(segments.get(0));
+      return;
+    }
+    try {
+      // we can assume that all segments are in the same bucket.
+      String s3Bucket = MapUtils.getString(segments.get(0).getLoadSpec(), 
"bucket");
+      final ServerSideEncryptingAmazonS3 s3Client = 
this.s3ClientSupplier.get();
+
+      // 1000 objects is the max amount of objects that can be deleted in s3 
at a time.
+      List<List<DataSegment>> segmentsChunks = Lists.partition(segments, 1000);
+      for (List<DataSegment> segmentsChunk : segmentsChunks) {
+        DeleteObjectsRequest deleteObjectsRequest = new 
DeleteObjectsRequest(s3Bucket);
+        deleteObjectsRequest = deleteObjectsRequest.withKeys(
+            segmentsChunk.stream()
+                         .map(segment -> 
MapUtils.getString(segment.getLoadSpec(), "key"))
+                         .toArray(String[]::new));
+        DeleteObjectsResult deleteResult = 
s3Client.deleteObjects(deleteObjectsRequest);
+        log.info("deleted objects %s", deleteResult);
+
+        // delete descriptors which are a files to store segment metadata in 
deep storage.
+        // This file is deprecated and not stored anymore, but we still delete 
them if they exist.
+        deleteObjectsRequest = new DeleteObjectsRequest(s3Bucket);
+        deleteObjectsRequest = deleteObjectsRequest.withKeys(
+            segmentsChunk.stream()
+                         .map(segment -> 
DataSegmentKiller.descriptorPath(MapUtils.getString(
+                             segment.getLoadSpec(),
+                             "key"
+                         )))
+                         .toArray(String[]::new));
+        deleteResult = s3Client.deleteObjects(deleteObjectsRequest);
+        log.info("deleted objects %s", deleteResult);
+      }
+    }
+    catch (MultiObjectDeleteException e) {

Review Comment:
   what other exceptions can happen here? Is this the best message in the 
exception?
   
   
https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/s3/AmazonS3.html#deleteObjects-com.amazonaws.services.s3.model.DeleteObjectsRequest-
   https://docs.aws.amazon.com/AmazonS3/latest/API/API_DeleteObjects.html



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