什么是Azure租赁Blob? [英] What is Azure Lease Blob?

查看:52
本文介绍了什么是Azure租赁Blob?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是Azure租赁Blob?仅仅是一种提供对Blob存储的排他锁的机制吗?有什么特别之处?在哪里可以使用?我试图阅读Azure文档,但是我还不清楚.

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.

推荐答案

什么是Azure租赁Blob?仅仅是一种机制可以提供独家锁定Blob存储空间?

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

您的理解是正确的.当您租借Blob时,您将获得对该Blob的排他锁.只要Blob被租用,除租约持有人外,其他任何人都无法修改或删除Blob.您可以获取临时租约,其持续时间可以在15到60秒之间,也可以是无限租约.

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?

大多数情况下,Azure虚拟机使用此功能.如您所知,Azure VM由Azure Page Blob支持.因此,在创建VM时,将在持有该Azure VM的VHD的Blob上获取无限租约,以便其他任何进程都无法修改或删除该Blob.

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.

另一个要使用租用Blob功能的地方是要实现 领导选举 模式.

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

例如,考虑一种情况,您希望通过后台工作人员角色"处理存储在Blob存储中的文件.进一步假设存在该角色运行的多个实例,其中每个实例在30秒后唤醒,并检查容器中的blob,以及是否发现该实例对其进行处理的blob.

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.

由于Azure Worker角色本质上是无状态的,因此在不锁定该Blob的情况下,每个实例将处理该Blob(不是您想要的).为了避免这种情况,您可以做的是让每个实例尝试在该Blob上获取租约.只有一个实例将成功(并因此被选为领导者).其他实例将无法获取该Blob上的锁定.Leader实例将处理Blob.

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.

另一个示例是您要在 竞争消费者 ,您希望在其中分配工作.在我们的一种产品中,我们将此模式与 Leader Election 模式一起使用.通过Blob租赁功能,我们找到了一个领导者(能够获得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.

这篇关于什么是Azure租赁Blob?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆