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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With