Skip to content

Commit 98b0267

Browse files
joachimdraegerAli Beyad
authored and
Ali Beyad
committed
Remove redundant and broken MD5 checksum from repository-s3 (#25270)
Remove redundant and not resettable (fails on retries) check-summing. Checksums are calculated and compared by the S3 client already. Closes #25269
1 parent cc67d02 commit 98b0267

File tree

2 files changed

+5
-31
lines changed

2 files changed

+5
-31
lines changed

plugins/repository-s3/src/main/java/org/elasticsearch/repositories/s3/DefaultS3OutputStream.java

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -122,30 +122,11 @@ protected void doUpload(S3BlobStore blobStore, String bucketName, String blobNam
122122
}
123123
md.setContentLength(length);
124124

125-
// We try to compute a MD5 while reading it
126-
MessageDigest messageDigest;
127-
InputStream inputStream;
128-
try {
129-
messageDigest = MessageDigest.getInstance("MD5");
130-
inputStream = new DigestInputStream(is, messageDigest);
131-
} catch (NoSuchAlgorithmException impossible) {
132-
// Every implementation of the Java platform is required to support MD5 (see MessageDigest)
133-
throw new RuntimeException(impossible);
134-
}
135-
136-
PutObjectRequest putRequest = new PutObjectRequest(bucketName, blobName, inputStream, md)
125+
PutObjectRequest putRequest = new PutObjectRequest(bucketName, blobName, is, md)
137126
.withStorageClass(blobStore.getStorageClass())
138127
.withCannedAcl(blobStore.getCannedACL());
139-
PutObjectResult putObjectResult = blobStore.client().putObject(putRequest);
140-
141-
String localMd5 = Base64.encodeAsString(messageDigest.digest());
142-
String remoteMd5 = putObjectResult.getContentMd5();
143-
if (!localMd5.equals(remoteMd5)) {
144-
logger.debug("MD5 local [{}], remote [{}] are not equal...", localMd5, remoteMd5);
145-
throw new AmazonS3Exception("MD5 local [" + localMd5 +
146-
"], remote [" + remoteMd5 +
147-
"] are not equal...");
148-
}
128+
blobStore.client().putObject(putRequest);
129+
149130
}
150131

151132
private void initializeMultipart() {

plugins/repository-s3/src/test/java/org/elasticsearch/repositories/s3/MockAmazonS3.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,20 +76,13 @@ public ObjectMetadata getObjectMetadata(
7676
public PutObjectResult putObject(PutObjectRequest putObjectRequest)
7777
throws AmazonClientException, AmazonServiceException {
7878
String blobName = putObjectRequest.getKey();
79-
DigestInputStream stream = (DigestInputStream) putObjectRequest.getInputStream();
8079

8180
if (blobs.containsKey(blobName)) {
8281
throw new AmazonS3Exception("[" + blobName + "] already exists.");
8382
}
8483

85-
blobs.put(blobName, stream);
86-
87-
// input and output md5 hashes need to match to avoid an exception
88-
String md5 = Base64.encodeAsString(stream.getMessageDigest().digest());
89-
PutObjectResult result = new PutObjectResult();
90-
result.setContentMd5(md5);
91-
92-
return result;
84+
blobs.put(blobName, putObjectRequest.getInputStream());
85+
return new PutObjectResult();
9386
}
9487

9588
@Override

0 commit comments

Comments
 (0)