Question

Difficulty: Very hardPerform Blob and Container Operations using Azure Storage SDKs

You are developing a Python microservice that updates a shared configuration file named `process_state.json` in Azure Blob Storage. The microservice uses the `azure-storage-blob` library (v12). To prevent multiple workers from modifying the file simultaneously, you must implement a lease-based locking mechanism. Additionally, the service must be able to recover and force-release the lock if a worker crashes while holding the lease. Which two of the following actions must you implement to perform these operations using the SDK? (Select TWO)

  1. Initialize a BlobLeaseClient for the target blob and call break_lease(lease_break_period=0) to immediately terminate any active lease held by a failed worker.Answer
  2. Pass the active lease ID as the lease keyword argument when calling upload_blob on the BlobClient.Answer
  3. C
    Call release() on a new BlobLeaseClient instance without specifying a lease ID to release the lock held by the crashed worker.
  4. D
    Configure the lease duration to -1 during acquisition to ensure it automatically expires after 60 seconds if the worker crashes.

Answer

Initialize a BlobLeaseClient for the target blob and call break_lease(lease_break_period=0) to immediately terminate any active lease held by a failed worker, and pass the active lease ID as the lease keyword argument when calling upload_blob on the BlobClient.
To modify a leased blob, you must authorize the request by passing the active lease ID as the lease parameter during write operations such as upload_blob. If a worker holding a lease crashes and the lease ID is lost, the lease can be broken administratively by initializing a BlobLeaseClient and calling break_lease(lease_break_period=0), which ignores the lease ID and immediately frees the resource.

Step-by-Step Solution

1
Manage Write Access to Leased Blobs
Upload succeeds without Precondition Failed errors
When a blob has an active lease, write operations like upload_blob require the active lease ID to be passed as a keyword argument (lease=lease_id) to verify ownership of the lock.
2
Handle Crashed Leases
Active lease is terminated immediately
If a worker crashes and the lease ID is lost, you cannot call release() because it requires the exact lease ID. Calling break_lease(lease_break_period=0) on the BlobLeaseClient breaks the lease administrative-wise without needing the lease ID.

Key Concept

Azure Blob Storage SDK Lease Operations and Concurrency
Rate this question