You are developing a C# application using the Azure.Storage.Blobs SDK (v12). The application needs to perform a concurrency-safe metadata update on an existing blob named config.json. You must acquire a lease, apply the metadata dictionary, and release the lease.
Which sequence of code actions should you perform to complete this operation? Arrange the actions in the correct order.
- 1BlobClient blobClient = containerClient.GetBlobClient("config.json");
- 2BlobLeaseClient leaseClient = blobClient.GetBlobLeaseClient();
- 3BlobLease lease = await leaseClient.AcquireAsync(TimeSpan.FromSeconds(30));
- 4await blobClient.SetMetadataAsync(metadata, new BlobRequestConditions { LeaseId = lease.LeaseId });
- 5await leaseClient.ReleaseAsync();
Answer
To perform a concurrency-safe metadata update using the Azure.Storage.Blobs SDK, you must first get the BlobClient instance, initialize the BlobLeaseClient, acquire the lease to obtain a LeaseId, set the metadata while passing the LeaseId in the BlobRequestConditions, and finally release the lease.
The correct sequence begins by locating the target blob, initializing the lease manager, locking the blob to secure a lease ID, applying the metadata change with the required request conditions, and finally freeing the resource for other tasks.
Step-by-Step Solution
Key Concept
Concurrency management and metadata updates using BlobLeaseClient in Azure Storage SDK (v12).