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)
- 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
- Pass the active lease ID as the lease keyword argument when calling upload_blob on the BlobClient.Answer
- CCall release() on a new BlobLeaseClient instance without specifying a lease ID to release the lock held by the crashed worker.
- DConfigure 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
Key Concept
Azure Blob Storage SDK Lease Operations and Concurrency