Skip to content

Commit

Permalink
[s3] Remove unnecessary getObjectMetadata() from getS3ObjectAndMetada…
Browse files Browse the repository at this point in the history
…ta() (brianfrankcooper#1060)

* Remove unnecessary getObjectMetadata() from getS3ObjectAndMetadata()

ObjectMetadata is available from S3Object.getObjectMetadata().
We don't need to send a separate GetObjectMetadata Request (an
HTTP HEAD request), in order to get the metadata. This will double
performance for read workloads.

Signed-off-by: Xing Lin <Xing.Lin@netapp.com>

* Remove one unused import to pass style check.

Signed-off-by: Xing Lin <xing.lin@netapp.com>
  • Loading branch information
xinglin authored and busbey committed Dec 2, 2017
1 parent fbd8114 commit 381aaeb
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions s3/src/main/java/com/yahoo/ycsb/db/S3Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
import com.amazonaws.services.s3.model.S3ObjectSummary;
import com.amazonaws.services.s3.model.SSECustomerKey;
import com.amazonaws.services.s3.model.PutObjectRequest;
import com.amazonaws.services.s3.model.GetObjectMetadataRequest;

/**
* S3 Storage client for YCSB framework.
Expand Down Expand Up @@ -350,11 +349,11 @@ protected Status writeToStorage(String bucket, String key,
totalSize = sizeArray*fieldCount;
} else {
try {
Map.Entry<S3Object, ObjectMetadata> objectAndMetadata = getS3ObjectAndMetadata(bucket, key, ssecLocal);
int sizeOfFile = (int)objectAndMetadata.getValue().getContentLength();
S3Object object = getS3ObjectAndMetadata(bucket, key, ssecLocal);
int sizeOfFile = (int)object.getObjectMetadata().getContentLength();
fieldCount = sizeOfFile/sizeArray;
totalSize = sizeOfFile;
objectAndMetadata.getKey().close();
object.close();
} catch (Exception e){
System.err.println("Not possible to get the object :"+key);
e.printStackTrace();
Expand Down Expand Up @@ -425,12 +424,12 @@ protected Status writeToStorage(String bucket, String key,
protected Status readFromStorage(String bucket, String key,
Map<String, ByteIterator> result, SSECustomerKey ssecLocal) {
try {
Map.Entry<S3Object, ObjectMetadata> objectAndMetadata = getS3ObjectAndMetadata(bucket, key, ssecLocal);
InputStream objectData = objectAndMetadata.getKey().getObjectContent(); //consuming the stream
S3Object object = getS3ObjectAndMetadata(bucket, key, ssecLocal);
InputStream objectData = object.getObjectContent(); //consuming the stream
// writing the stream to bytes and to results
result.put(key, new ByteArrayByteIterator(IOUtils.toByteArray(objectData)));
objectData.close();
objectAndMetadata.getKey().close();
object.close();
} catch (Exception e){
System.err.println("Not possible to get the object "+key);
e.printStackTrace();
Expand All @@ -440,23 +439,17 @@ protected Status readFromStorage(String bucket, String key,
return Status.OK;
}

private Map.Entry<S3Object, ObjectMetadata> getS3ObjectAndMetadata(String bucket,
private S3Object getS3ObjectAndMetadata(String bucket,
String key, SSECustomerKey ssecLocal) {
GetObjectRequest getObjectRequest;
GetObjectMetadataRequest getObjectMetadataRequest;
if (ssecLocal != null) {
getObjectRequest = new GetObjectRequest(bucket,
key).withSSECustomerKey(ssecLocal);
getObjectMetadataRequest = new GetObjectMetadataRequest(bucket,
key).withSSECustomerKey(ssecLocal);
} else {
getObjectRequest = new GetObjectRequest(bucket, key);
getObjectMetadataRequest = new GetObjectMetadataRequest(bucket,
key);
}

return new AbstractMap.SimpleEntry<>(s3Client.getObject(getObjectRequest),
s3Client.getObjectMetadata(getObjectMetadataRequest));
return s3Client.getObject(getObjectRequest);
}

/**
Expand Down

0 comments on commit 381aaeb

Please sign in to comment.