1

Azure blob API sometimes looks like it's been designed by aliens. Like designed for some very exotic use cases when most simple ones require jumping through the hoops. Here is one such.

I have two worker roles. One is creating blobs, another one is processing them (and moving to "completed" folder when processing is done). The blob size can be moderately big, like 100 MB. Obviously, I don't want second role to start reading the blob before the blob has all the data. Okay, one can expect the help from the Lease API: acquire the lease, copy the blob, release the lease. Then, reader will also try to acquire the lease before processing and therefore will have to wait. But no, lease can't be acquired on a blob that does not exist yet. Also, I couldn't find any method that creates a blob with the lease "on" as an atomic operation.

Please let me know if you know the trick to make it work. Sincerely Yours.

4

1 回答 1

1

显然,我不希望第二个角色在 blob 拥有所有数据之前开始读取 blob。

假设您正在创建一个BlockBlob, 直到 blob 被提交(或者换句话说,所有数据都写入 blob)出于所有意图和目的,blob 将不存在并且不会出现在 blob 列表结果中(除非您列出 blob 时特别要求未提交的 blob)。所以我认为你不必在那里做任何特别的事情。

好的,可以期待 Lease API 的帮助:获取租约、复制 blob、释放租约。然后,读者也会在处理之前尝试获取租约,因此必须等待。

有一个替代解决方案。你能做的就是利用Azure Queues. 当 blob 创建者工作角色完成上传 blob 时,它只是在队列中写入一条消息,该消息将由处理 blob 的工作角色轮询。假设有许多处理器工作者角色的实例,那么每个实例都可以GET从这个队列中获取消息,其工作方式类似于blob lease(消息仅对一个实例可用),然后开始处理 blob。

于 2015-01-23T04:11:11.167 回答