Better Logging S3 Bulk Delete Failures (#50203) (#50262)

Unfortunately bulk delete exceptions don't show the individual delete
errors when a bulk delete fails when you log them outright so I added this work-around
to get the individual details to get useful logging.
This commit is contained in:
Armin Braun 2019-12-17 09:42:39 +01:00 committed by GitHub
parent c6fdf9ed8a
commit ce294e1564
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 0 deletions

View File

@ -32,6 +32,9 @@ import com.amazonaws.services.s3.model.PartETag;
import com.amazonaws.services.s3.model.PutObjectRequest;
import com.amazonaws.services.s3.model.UploadPartRequest;
import com.amazonaws.services.s3.model.UploadPartResult;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.message.ParameterizedMessage;
import org.apache.lucene.util.SetOnce;
import org.elasticsearch.ExceptionsHelper;
import org.elasticsearch.common.Nullable;
@ -61,6 +64,8 @@ import static org.elasticsearch.repositories.s3.S3Repository.MIN_PART_SIZE_USING
class S3BlobContainer extends AbstractBlobContainer {
private static final Logger logger = LogManager.getLogger(S3BlobContainer.class);
/**
* Maximum number of deletes in a {@link DeleteObjectsRequest}.
* @see <a href="https://docs.aws.amazon.com/AmazonS3/latest/API/multiobjectdeleteapi.html">S3 Documentation</a>.
@ -189,6 +194,10 @@ class S3BlobContainer extends AbstractBlobContainer {
outstanding.removeAll(keysInRequest);
outstanding.addAll(
e.getErrors().stream().map(MultiObjectDeleteException.DeleteError::getKey).collect(Collectors.toSet()));
logger.warn(
() -> new ParameterizedMessage("Failed to delete some blobs {}", e.getErrors()
.stream().map(err -> "[" + err.getKey() + "][" + err.getCode() + "][" + err.getMessage() + "]")
.collect(Collectors.toList())), e);
aex = ExceptionsHelper.useOrSuppress(aex, e);
} catch (AmazonClientException e) {
// The AWS client threw any unexpected exception and did not execute the request at all so we do not