Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating Blob in Azure Blob Storage with the same name simultaneously

Tags:

c#

blob

azure

I have task to load some images into the blob storage simultaneously. Name of blob is defined as md5 of the blob. It can happen that different threads try to load same files from different locations.

Now I need to know how to block other threads from loading same file, if first already trying to upload such blob.

like image 372
Creator Avatar asked Dec 16 '14 12:12

Creator


People also ask

What is difference between block blob Pageend blob and append?

The block blobs allow the users to upload large amount of data. Append blobs are optimized blocks that helps in making the operations efficient. Page blobs are compilation of pages. They allow random read and write operations.

How do I sync blob storage?

You can synchronize local storage with Azure Blob storage by using the AzCopy v10 command-line utility. You can synchronize the contents of a local file system with a blob container. You can also synchronize containers and virtual directories with one another. Synchronization is one way.

How do I transfer data from one blob to another?

Copy containers, directories, and blobs Copy all containers, directories, and blobs to another storage account by using the azcopy copy command. This example encloses path arguments with single quotes (''). Use single quotes in all command shells except for the Windows Command Shell (cmd.exe).


1 Answers

You can do it without leasing it by using optimistic concurrency. Basicly set an access condition that says this blob will be different from all etags of blobs with this name. If there is indeed a blob with some etag the second upload will fail.

var access = AccessCondition.GenerateIfNoneMatchCondition("*");
await blobRef.UploadFromStreamAsync(stream, access, null, null);
like image 94
Esben Skov Pedersen Avatar answered Oct 14 '22 22:10

Esben Skov Pedersen