Question

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

An Azure integration workflow must modify the metadata of a blob while preventing write conflicts. Using the .NET SDK (`Azure.Storage.Blobs`), write operations to the blob must be temporarily locked.

Order the steps required to programmatically lock the blob, apply the metadata changes, and release the lock.

  1. 1Call the `GetBlobLeaseClient` extension method on a `BlobClient` instance to generate a helper client for lease operations.
  2. 2Invoke `AcquireAsync` on the lease client to obtain a write lock and generate the corresponding lease ID.
  3. 3Invoke `SetMetadataAsync` on the `BlobClient` while passing the lease ID inside a `BlobRequestConditions` object.
  4. 4Invoke `ReleaseAsync` on the lease client to terminate the write lock and allow other clients to modify the blob.

Answer

The correct sequence begins by instantiating a lease client using GetBlobLeaseClient, followed by acquiring the lease using AcquireAsync. Next, SetMetadataAsync is invoked on the BlobClient with the acquired lease ID supplied within BlobRequestConditions, and finally, the lease is freed by calling ReleaseAsync on the lease client.
To modify a blob safely under a concurrency lock, a client must first obtain a BlobLeaseClient to coordinate lease actions. Second, the lease must be explicitly acquired to retrieve the lease ID. Third, the metadata update is committed using the lease ID inside BlobRequestConditions. Finally, the lease must be released to clean up the lock and make the blob available to other clients.

Step-by-Step Solution

1
Instantiate the lease client.
A BlobLeaseClient object bound to the target BlobClient is created.
The Azure SDK structures lease operations under a specialized lease client rather than the main blob client.
2
Acquire the lease.
The blob is locked for write operations, and a unique lease ID is returned.
Acquiring the lease establishes the lock and generates the identifier required for subsequent modifications.
3
Apply the metadata with the lease ID.
The metadata is successfully updated on the blob.
Passing the lease ID in BlobRequestConditions ensures the write operation is permitted on the leased blob.
4
Release the lease.
The lease lock is removed, returning the blob to an unlocked state.
Releasing the lease promptly allows other processes to interact with the blob without waiting for the lease duration to expire.

Key Concept

Acquiring, using, and releasing a lease during blob metadata modifications to prevent concurrency issues using the Azure Storage SDK.
Rate this question