rishabhdaim commented on code in PR #2558:
URL: https://github.com/apache/jackrabbit-oak/pull/2558#discussion_r2416470164
##########
oak-blob-cloud/src/main/java/org/apache/jackrabbit/oak/blob/cloud/s3/S3Backend.java:
##########
@@ -316,57 +306,72 @@ void setBinaryTransferAccelerationEnabled(boolean
enabled) {
* method uses parallel concurrent connections to upload.
*/
@Override
- public void write(DataIdentifier identifier, File file)
- throws DataStoreException {
+ public void write(DataIdentifier identifier, File file) throws
DataStoreException {
String key = getKeyName(identifier);
- ObjectMetadata objectMetaData = null;
long start = System.currentTimeMillis();
ClassLoader contextClassLoader =
Thread.currentThread().getContextClassLoader();
try {
- Thread.currentThread().setContextClassLoader(
- getClass().getClassLoader());
+
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
// check if the same record already exists
+ HeadObjectResponse headMeta = null;
try {
- objectMetaData =
s3service.getObjectMetadata(s3ReqDecorator.decorate(new
GetObjectMetadataRequest(bucket, key)));
- } catch (AmazonServiceException ase) {
- if (!(ase.getStatusCode() == 404 || ase.getStatusCode() ==
403)) {
- throw ase;
+ headMeta = s3Client.headObject(s3ReqDecorator.decorate(
+ HeadObjectRequest.builder()
+ .bucket(bucket)
+ .key(key)
+ .build()));
+ } catch (S3Exception se) {
+ if (!(se instanceof NoSuchKeyException || se.statusCode() ==
404 || se.statusCode() == 403)) {
+ throw se;
}
}
- if (objectMetaData != null) {
- long l = objectMetaData.getContentLength();
+ if (headMeta != null) {
+ long l = headMeta.contentLength();
if (l != file.length()) {
- throw new DataStoreException("Collision: " + key
- + " new length: " + file.length() + " old length: " +
l);
+ throw new DataStoreException("Collision: " + key + " new
length: " + file.length() + " old length: " + l);
}
- LOG.debug("[{}]'s exists, lastmodified = [{}]", key,
- objectMetaData.getLastModified().getTime());
- CopyObjectRequest copReq = new CopyObjectRequest(bucket, key,
- bucket, key);
- LOG.warn("Object MetaData before copy: {}",
objectMetaData.getRawMetadata());
+ LOG.debug("[{}]'s exists, lastmodified = [{}]", key,
headMeta.lastModified().toEpochMilli());
+ CopyObjectRequest copyReq =
+ CopyObjectRequest.builder()
+ .sourceBucket(bucket)
+ .sourceKey(key)
+ .destinationBucket(bucket)
+ .destinationKey(key)
+ .metadataDirective(MetadataDirective.REPLACE)
+ .build();
+ LOG.warn("Object MetaData before copy: {}",
headMeta.metadata());
if (Objects.equals(RemoteStorageMode.S3,
properties.get(S3Constants.MODE))) {
Review Comment:
No, this is required to update metadata and reset creation time. Without
this, the ITs started failing.
Also, COPY is the default behaviour.
--
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]