Skip to content
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

Put (uploadBlob) in AzureCloudDestination should autocreate container if not exists #1277

Merged
merged 1 commit into from
Oct 10, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ private boolean uploadIfNotExists(BlobId blobId, long inputLength, CloudBlobMeta
azureMetrics.blobUploadRequestCount.inc();
Timer.Context storageTimer = azureMetrics.blobUploadTime.time();
try {
CloudBlockBlob azureBlob = getAzureBlobReference(blobId);
CloudBlockBlob azureBlob = getAzureBlobReference(blobId, true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better to add piece of comment for this method when container doesn't exist.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are comments in lines 526 and 529, when we actually create the container. Let me know if you think we need more logging.

cloudBlobMetadata.setCloudBlobName(getAzureBlobName(blobId));
azureBlob.setMetadata(getMetadataMap(cloudBlobMetadata));
azureBlob.upload(blobInputStream, inputLength, condition, options, blobOpContext);
Expand All @@ -260,7 +260,7 @@ public void downloadBlob(BlobId blobId, OutputStream outputStream) throws CloudS
azureMetrics.blobDownloadRequestCount.inc();
Timer.Context storageTimer = azureMetrics.blobDownloadTime.time();
try {
CloudBlockBlob azureBlob = getAzureBlobReference(blobId);
CloudBlockBlob azureBlob = getAzureBlobReference(blobId, false);
azureBlob.download(outputStream);
azureMetrics.blobDownloadSuccessCount.inc();
} catch (URISyntaxException | StorageException e) {
Expand Down Expand Up @@ -393,7 +393,7 @@ private boolean updateBlobMetadata(BlobId blobId, String fieldName, Object value
// 2) the blob storage entry metadata (to enable rebuilding the database)

try {
CloudBlockBlob azureBlob = getAzureBlobReference(blobId);
CloudBlockBlob azureBlob = getAzureBlobReference(blobId, false);

if (!azureBlob.exists(null, null, blobOpContext)) {
logger.debug("Blob {} not found in Azure container {}.", blobId, getContainer(blobId, false).getName());
Expand Down Expand Up @@ -488,7 +488,7 @@ public int purgeBlobs(List<CloudBlobMetadata> blobMetadataList) throws CloudStor
@Override
public boolean doesBlobExist(BlobId blobId) throws CloudStorageException {
try {
CloudBlockBlob azureBlob = getAzureBlobReference(blobId);
CloudBlockBlob azureBlob = getAzureBlobReference(blobId, false);
return azureBlob.exists(null, null, blobOpContext);
} catch (URISyntaxException | StorageException e) {
throw new CloudStorageException("Could not check existence of blob: " + blobId, e);
Expand Down Expand Up @@ -568,12 +568,14 @@ public boolean retrieveTokens(String partitionPath, String tokenFileName, Output
/**
* Get the azure blob reference for blobid.
* @param blobId id of the blob for which {@code CloudBlockBlob} reference is asked for.
* @param autoCreateContainer flag indicating whether to create the container if it does not exist.
* @return {@code CloudBlockBlob} reference.
* @throws StorageException if storage service error occured.
* @throws URISyntaxException if resource name or uri is invalid.
*/
private CloudBlockBlob getAzureBlobReference(BlobId blobId) throws StorageException, URISyntaxException {
CloudBlobContainer azureContainer = getContainer(blobId, false);
private CloudBlockBlob getAzureBlobReference(BlobId blobId, boolean autoCreateContainer)
throws StorageException, URISyntaxException {
CloudBlobContainer azureContainer = getContainer(blobId, autoCreateContainer);
String azureBlobName = getAzureBlobName(blobId);
return azureContainer.getBlockBlobReference(azureBlobName);
}
Expand Down