Question

Difficulty: EasyManage Properties, Metadata, and Access Tiers for Azure Blob Storage

A backend service is being updated to coordinate access to a shared log file stored in Azure Blob Storage. To ensure thread safety when modifying metadata, the service must obtain a write lease, perform the metadata update, and clean up the lease. What is the correct sequence of operations to complete this task using the Azure.Storage.Blobs namespace?

  1. 1Instantiate a BlobClient representing the target log blob.
  2. 2Initialize a BlobLeaseClient using the BlobClient and call AcquireAsync to obtain a lease ID.
  3. 3Call SetMetadataAsync on the BlobClient, passing a BlobRequestConditions object initialized with the lease ID.
  4. 4Invoke ReleaseAsync on the BlobLeaseClient to unlock the blob.

Answer

The correct sequence is: Instantiate a BlobClient representing the target log blob, initialize a BlobLeaseClient using the BlobClient and call AcquireAsync to obtain a lease ID, call SetMetadataAsync on the BlobClient passing a BlobRequestConditions object initialized with the lease ID, and then invoke ReleaseAsync on the BlobLeaseClient to unlock the blob.
To update a leased blob, a client must first establish a BlobClient, use it to initialize a BlobLeaseClient, acquire the lease, apply the metadata update by passing the lease ID in the request conditions, and finally release the lease to unlock the resource.

Step-by-Step Solution

1
Obtain a BlobClient reference.
An active client reference to the target blob is established.
Both the lease client initialization and the metadata update require the underlying BlobClient.
2
Create a BlobLeaseClient and call AcquireAsync.
A lease lock is successfully acquired on the blob, generating a lease ID.
The blob must be locked prior to any modification to prevent concurrent writes from other instances.
3
Invoke SetMetadataAsync with BlobRequestConditions containing the lease ID.
The metadata on the leased blob is updated.
Since the blob has an active lease, all write operations must explicitly include the lease ID to prove ownership of the lock.
4
Call ReleaseAsync on the BlobLeaseClient.
The lease is released, clearing the write lock.
Releasing the lease unlocks the blob, enabling other operations and clients to modify it.

Key Concept

Acquiring, using, and releasing exclusive-write leases during metadata updates using the Azure Storage SDK for .NET.
Rate this question