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?
- 1Instantiate a BlobClient representing the target log blob.
- 2Initialize a BlobLeaseClient using the BlobClient and call AcquireAsync to obtain a lease ID.
- 3Call SetMetadataAsync on the BlobClient, passing a BlobRequestConditions object initialized with the lease ID.
- 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
Key Concept
Acquiring, using, and releasing exclusive-write leases during metadata updates using the Azure Storage SDK for .NET.