You are developing a backend synchronization service in C# using the Azure.Storage.Blobs SDK (v12). The service needs to update the metadata of a critical blob. However, another worker instance crashed while holding an active lease on the blob, blocking updates. To recover, your service must immediately break the existing lease, secure a new lease to prevent other instances from writing, update the blob's metadata, and clean up. Arrange the steps in the correct order to perform this workflow.
- 1Instantiate a BlobClient using the connection string, container name, and blob name.
- 2Instantiate a BlobLeaseClient by passing the BlobClient to its constructor.
- 3Call BreakAsync on the BlobLeaseClient to immediately terminate the active lease held by the crashed worker.
- 4Call AcquireAsync on the BlobLeaseClient to obtain a new exclusive lease.
- 5Call SetMetadataAsync on the BlobClient with the updated metadata dictionary, passing the new lease ID within a BlobRequestConditions object.
- 6Call ReleaseAsync on the BlobLeaseClient to release the lease.
Answer
First, instantiate a BlobClient, then instantiate a BlobLeaseClient. Next, break the existing lease, acquire a new lease, set the metadata using the new lease ID in the request conditions, and finally release the lease.
The correct sequence starts by obtaining a BlobClient, which is used to construct a BlobLeaseClient. Since the blob is currently locked by a crashed worker's lease, the lease must first be broken using BreakAsync. After the lease is broken, the current process must call AcquireAsync to get a new lease for itself. The metadata is then updated using SetMetadataAsync, passing the new lease ID in the request conditions to authorize the write operation on the locked blob. Finally, ReleaseAsync is called to free the lock.
Step-by-Step Solution
Key Concept
Managing blob leases and performing write operations under an active lease using the Azure.Storage.Blobs SDK.