Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is Azure Lease Blob?

Tags:

What is Azure Lease Blob? Is it just a mechanism which provides an exclusive lock to the blob storage? What is special about it? Where can I use it? I tried to read Azure documents, but it's not clear to me yet.

like image 669
user43286 Avatar asked Jun 09 '17 21:06

user43286


People also ask

What is a lease in Azure?

A lease establishes and manages a lock on a container or the blobs in a container. You can use the . NET client library to acquire, renew, release and break leases.

How do I get my lease ID from Azure blob?

Unfortunately you can't get the lease id after the fact. The lease id is not stored anywhere in the system. It is the responsibility of the lease acquirer to store the lease id. Considering you don't have the lease id, thus you won't be able to release the lease.

Why is it called Azure blob?

Azure Blob storage is a feature of Microsoft Azure. It allows users to store large amounts of unstructured data on Microsoft's data storage platform. In this case, Blob stands for Binary Large Object, which includes objects such as images and multimedia files.


1 Answers

What is Azure Lease Blob? Is it just a mechanism which provides an exclusive lock to the blob storage?

Your understanding is correct. When you lease a blob, you acquire an exclusive lock on that blob. As long as the blob is leased, no one other than lease holder can modify or delete the blob. You can either acquire a temporary lease, duration of which could be anywhere between 15 to 60 seconds or an infinite lease.

Where can I use it?

Most commonly this functionality is used by Azure Virtual Machines. As you know Azure VMs are backed by Azure Page Blobs. So when a VM is created, an infinite lease is acquired on the blob holding the VHD for that Azure VM so that no other process can modify or delete that blob.

Yet another place where you would want to use lease blob functionality is when you want to implement Leader Election pattern.

For example, consider a scenario where you would want to process a file stored in blob storage through a background Worker Role. Further assume that there are multiple instances of that Worker Role running where each instance wakes up after 30 seconds and checks for blobs in a container and if any blob is found that instance processes it.

Since Azure Worker Roles are stateless in nature, without locking that blob each instance will process that blob (not something you would want). To avoid this situation what you could do is have each instance try to acquire a lease on that blob. Only one instance will succeed (and hence elected as leader). Other instances will fail to acquire the lock on that blob. The leader instance will process the blob.

Another example would be where you want to distribute work in Competing Consumers where you would want to distribute work among them. In one of our products, we are using this pattern with Leader Election pattern. Through blob lease functionality, we find a leader (consumer which was able to acquire blob lease) and then this leader distributes work amongst other consumers.

like image 144
Gaurav Mantri Avatar answered Nov 08 '22 15:11

Gaurav Mantri