Question

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

You are developing a C# console application that updates the metadata of a block blob in Azure Blob Storage. The application uses the Azure.Storage.Blobs SDK (version 12). To prevent other processes from modifying the blob during the update, you must acquire a write lease on the blob, perform the metadata update, and then release the lease.

Which five actions should you perform in sequence? To answer, arrange the actions in the correct order.

  1. 1Instantiate a BlobClient for the target Azure Blob Storage block blob.
  2. 2Create a BlobLeaseClient using the BlobClient instance.
  3. 3Call AcquireAsync on the BlobLeaseClient to obtain a write lease on the blob.
  4. 4Call SetMetadataAsync on the BlobClient with a BlobRequestConditions object containing the acquired lease ID.
  5. 5Call ReleaseAsync on the BlobLeaseClient to unlock the blob.

Answer

To perform a leased metadata update, you first instantiate a BlobClient, then create a BlobLeaseClient from it, acquire the lease, call SetMetadataAsync using a BlobRequestConditions containing the lease ID, and finally call ReleaseAsync to release the lease.
The correct sequence starts with instantiating a BlobClient to reference the blob. Next, a BlobLeaseClient is created from the BlobClient. The lease is then acquired using AcquireAsync. Once the lease is active, SetMetadataAsync is called with BlobRequestConditions containing the lease ID. Finally, the lease is released using ReleaseAsync.

Step-by-Step Solution

1
Create a BlobClient instance.
Establishes a programmatic reference to the target blob.
Required to create the BlobLeaseClient and perform operations.
2
Instantiate a BlobLeaseClient using the BlobClient.
Creates a client capable of managing leases on the target blob.
Leases cannot be managed directly through the standard BlobClient.
3
Invoke AcquireAsync on the BlobLeaseClient.
Secures an exclusive write lock (lease) on the blob and returns a lease ID.
Prevents concurrent write operations from other clients.
4
Call SetMetadataAsync on the BlobClient, passing the metadata dictionary and a BlobRequestConditions object containing the lease ID.
Applies the metadata updates to the blob.
Because the blob is leased, any write operation must supply the active lease ID to succeed.
5
Invoke ReleaseAsync on the BlobLeaseClient.
Unlocks the blob, allowing subsequent access by other processes.
Ensures the resource is not locked indefinitely.

Key Concept

Acquiring a write lease, updating blob metadata with request conditions, and releasing the lease using the Azure SDK for .NET.
Rate this question