-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ability to Delete task logs and segments from S3 #9459
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
914510f
Ability to Delete task logs and segments from S3
zachjsh 5d505a1
* update licenses for updated AWS SDK version
zachjsh 2af8070
* fix bug in iterating through results from S3
zachjsh 345c22e
* Address review comments
zachjsh 1c54e4c
* Fix failing dependency check
zachjsh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
core/src/main/java/org/apache/druid/common/utils/CurrentTimeMillisSupplier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* 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.druid.common.utils; | ||
|
||
import java.util.function.LongSupplier; | ||
|
||
public class CurrentTimeMillisSupplier implements LongSupplier | ||
{ | ||
@Override | ||
public long getAsLong() | ||
{ | ||
return System.currentTimeMillis(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ | |
import com.amazonaws.services.s3.model.AccessControlList; | ||
import com.amazonaws.services.s3.model.AmazonS3Exception; | ||
import com.amazonaws.services.s3.model.CanonicalGrantee; | ||
import com.amazonaws.services.s3.model.DeleteObjectsRequest; | ||
import com.amazonaws.services.s3.model.Grant; | ||
import com.amazonaws.services.s3.model.ListObjectsV2Request; | ||
import com.amazonaws.services.s3.model.ListObjectsV2Result; | ||
|
@@ -31,6 +32,7 @@ | |
import com.amazonaws.services.s3.model.S3ObjectSummary; | ||
import com.google.common.base.Joiner; | ||
import com.google.common.base.Predicate; | ||
import com.google.common.collect.ImmutableList; | ||
import org.apache.druid.data.input.impl.CloudObjectLocation; | ||
import org.apache.druid.java.util.common.ISE; | ||
import org.apache.druid.java.util.common.RetryUtils; | ||
|
@@ -41,7 +43,9 @@ | |
import java.io.File; | ||
import java.io.IOException; | ||
import java.net.URI; | ||
import java.util.ArrayList; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
|
||
/** | ||
* | ||
|
@@ -200,6 +204,54 @@ public static S3ObjectSummary getSingleObjectSummary(ServerSideEncryptingAmazonS | |
return objectSummary; | ||
} | ||
|
||
public static void deleteObjectsInPath( | ||
ServerSideEncryptingAmazonS3 s3Client, | ||
S3InputDataConfig config, | ||
String bucket, | ||
String prefix, | ||
Predicate<S3ObjectSummary> filter | ||
) | ||
throws Exception | ||
{ | ||
final List<DeleteObjectsRequest.KeyVersion> keysToDelete = new ArrayList<>(config.getMaxListingLength()); | ||
final ObjectSummaryIterator iterator = new ObjectSummaryIterator( | ||
s3Client, | ||
ImmutableList.of(new CloudObjectLocation(bucket, prefix).toUri("s3")), | ||
config.getMaxListingLength() | ||
); | ||
|
||
while (iterator.hasNext()) { | ||
final S3ObjectSummary nextObject = iterator.next(); | ||
if (filter.apply(nextObject)) { | ||
keysToDelete.add(new DeleteObjectsRequest.KeyVersion(nextObject.getKey())); | ||
if (keysToDelete.size() == config.getMaxListingLength()) { | ||
deleteBucketKeys(s3Client, bucket, keysToDelete); | ||
log.info("Deleted %d files", keysToDelete.size()); | ||
keysToDelete.clear(); | ||
} | ||
} | ||
} | ||
|
||
if (keysToDelete.size() > 0) { | ||
deleteBucketKeys(s3Client, bucket, keysToDelete); | ||
log.info("Deleted %d files", keysToDelete.size()); | ||
} | ||
} | ||
|
||
public static void deleteBucketKeys( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: this can be private actually (my bad) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll get this in the next change which should be coming shortly. |
||
ServerSideEncryptingAmazonS3 s3Client, | ||
String bucket, | ||
List<DeleteObjectsRequest.KeyVersion> keysToDelete | ||
) | ||
throws Exception | ||
{ | ||
DeleteObjectsRequest deleteRequest = new DeleteObjectsRequest(bucket).withKeys(keysToDelete); | ||
S3Utils.retryS3Operation(() -> { | ||
s3Client.deleteObjects(deleteRequest); | ||
return null; | ||
}); | ||
} | ||
|
||
/** | ||
* Uploads a file to S3 if possible. First trying to set ACL to give the bucket owner full control of the file before uploading. | ||
* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: javadocs describing this method would be nice
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll get this in the next change which should be coming shortly.