Question

Difficulty: MediumPerform Blob and Container Operations using Azure Storage SDKs

You are developing a C# application using the Azure.Storage.Blobs SDK (v12). The application must perform a concurrency-safe update to an existing blob named `configuration.json` by acquiring a 30-second exclusive-write lease, uploading the new content, and then immediately releasing the lease.

How should you order the developer's actions to achieve this workflow?

  1. 1Initialize a `BlobClient` pointing to the `configuration.json` blob in the target container.
  2. 2Instantiate a `BlobLeaseClient` using the initialized `BlobClient` instance.
  3. 3Call `AcquireAsync` on the `BlobLeaseClient` specifying a lease duration of 30 seconds.
  4. 4Call `UploadAsync` on the `BlobClient` passing `BlobUploadOptions` containing `BlobRequestConditions` populated with the acquired lease ID.
  5. 5Call `ReleaseAsync` on the `BlobLeaseClient` to free the lease for other processes.

Answer

The correct order of operations is to first initialize the BlobClient, instantiate the BlobLeaseClient, acquire the lease, upload the content using the lease ID, and finally release the lease.
To perform a leased upload operation, you must first create a `BlobClient` to target the blob. Next, you construct a `BlobLeaseClient` using the `BlobClient`. You then acquire the lease to obtain a lease ID. With this lease ID, you can perform the upload by specifying it in the `BlobUploadOptions`. Finally, you release the lease to free the resource.

Step-by-Step Solution

1
Initialize a `BlobClient`.
An active reference to the `configuration.json` blob is established.
A client reference is required to interact with the blob and to initialize the lease client.
2
Instantiate a `BlobLeaseClient` using the `BlobClient`.
A lease client is created.
In modern SDK v12, lease operations are handled via the specialized `BlobLeaseClient`.
3
Call `AcquireAsync` on the lease client.
An exclusive-write lease is acquired on the blob, returning a unique lease ID.
The lease ID is necessary to perform write operations on the leased blob.
4
Call `UploadAsync` on the `BlobClient` with `BlobUploadOptions` containing the lease ID.
The blob content is safely updated.
The lease ID must be passed to satisfy the concurrency constraint of the active lease.
5
Call `ReleaseAsync` on the lease client.
The lease is released.
Releasing the lease allows other clients to perform modifications without waiting for the lease duration to expire.

Key Concept

Blob Lease Management Workflow using Azure Storage SDK
Rate this question