Question

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

A C# financial auditing application needs to update the custom metadata on an existing block blob containing a transaction ledger. To prevent concurrent write operations from other clients, the application must implement lease-controlled metadata updates using the Azure SDK for .NET. Which of the following sequences represents the correct order of steps the application must execute to perform this update securely?

  1. 1Instantiate a `BlobClient` object pointing to the target ledger block blob.
  2. 2Instantiate a `BlobLeaseClient` associated with the `BlobClient` and call `AcquireAsync` to secure a lease.
  3. 3Call `GetPropertiesAsync` on the `BlobClient`, providing a `BlobRequestConditions` object populated with the lease ID.
  4. 4Call `SetMetadataAsync` on the `BlobClient` with the new metadata dictionary and the `BlobRequestConditions` containing the active lease ID.
  5. 5Call `ReleaseAsync` on the `BlobLeaseClient` to free the lock on the blob.

Answer

The correct order of operations begins with instantiating a `BlobClient` to reference the target blob. Next, a `BlobLeaseClient` is created and `AcquireAsync` is invoked to secure a lease. Once the lease is acquired, `GetPropertiesAsync` is called with the lease ID in the request conditions to read the current state. Afterward, `SetMetadataAsync` is executed with the updated metadata and the lease ID in the request conditions. Finally, the lease is released using `ReleaseAsync` on the lease client.
The correct order requires establishing the client connection first, obtaining a write lock (lease) to ensure concurrency control, fetching the current properties under that lease, applying the metadata change using the lease ID, and finally releasing the lease so others can access the blob.

Step-by-Step Solution

1
Instantiate a `BlobClient` object.
Establishes a connection to the target blob resource in Azure Storage.
All subsequent operations, including lease acquisition and metadata updates, require a reference to the target blob.
2
Create a `BlobLeaseClient` and call `AcquireAsync`.
Obtains a unique lease ID and places a write lock on the blob.
The lease must be acquired before reading the current state or applying updates to prevent race conditions.
3
Call `GetPropertiesAsync` passing the lease ID.
Retrieves the current metadata and properties of the leased blob.
Accessing the blob's properties requires passing the lease ID in `BlobRequestConditions` since the blob is now locked.
4
Call `SetMetadataAsync` passing the updated metadata and the lease ID.
Updates the custom metadata on the block blob.
Writing metadata to a leased blob requires the active lease ID in the `BlobRequestConditions` to authorize the modification.
5
Call `ReleaseAsync` on the lease client.
Releases the write lock on the blob.
Releasing the lease allows other instances of the application or other clients to obtain a lease and make modifications.

Key Concept

Lease-controlled blob operations in Azure Blob Storage using the .NET SDK.
Estimated Time:2m 0s
Rate this question