The error you’re encountering is on the Sink side when trying to perform an operation on Azure Data Lake Storage Gen2 (ADLS Gen2), with a specific message stating that the lease is not present. This is accompanied by the PreconditionFailed status code, which generally means that the system expected certain conditions (like an active lease) but did not find them.
Potential Causes:
- Lease Requirement Not Met: The operation expected an active lease on the file or directory, but no lease exists at the time of the operation.
- Concurrent Access: Another process could have released the lease prematurely, or the lease may have expired.
- Invalid Preconditions: The operation expected specific conditions (like a lease or metadata) to be present, which were not.
Solution Steps:
1. Acquire a Lease (if Required):
If the Sink operation requires a lease, you must acquire one on the file or directory before writing. Use the Azure CLI or SDK to acquire a lease.
Azure CLI Command to Acquire a Lease:
az storage blob lease acquire \
--container-name <container-name> \
--blob-name <blob-name> \
--account-name <storage-account>
Replace <container-name>
, <blob-name>
, and <storage-account>
with your actual values.
This will acquire a lease and allow the operation to proceed.
2. Ensure Lease Is Not Expired:
If your operation takes a long time to complete, the lease may expire before the operation finishes. You can either:
- Renew the lease periodically to extend it.
- Set a longer lease duration (default lease time is 60 seconds).
Use the following command to renew the lease:
az storage blob lease renew \
--container-name <container-name> \
--blob-name <blob-name> \
--account-name <storage-account> \
--lease-id <lease-id>
This command renews an existing lease, ensuring it stays valid during your operation.
3. Check for Lease Conflicts:
If multiple processes are interacting with the same file or directory, ensure that only one process is acquiring and managing the lease at any given time. Lease conflicts can occur if multiple processes try to acquire or break the lease on the same resource.
4. Manually Break the Lease (if stuck):
If another process has a stale or orphaned lease on the resource, you can manually break the lease before proceeding.
Breaking a Lease:
az storage blob lease break \
--container-name <container-name> \
--blob-name <blob-name> \
--account-name <storage-account>
This will forcefully break the lease, allowing the Sink operation to proceed.
5. Check Permissions:
Ensure that the Azure Data Factory or service accessing the ADLS Gen2 resource has sufficient permissions. It should have read/write access to the container and files. You can configure permissions using Azure RBAC (Role-Based Access Control) in the Azure Portal.
6. Implement Retry Logic:
The error may also be transient, caused by network latency or temporary unavailability. Implementing retry logic can help automatically handle such transient issues.
In Azure Data Factory, you can configure retry policy in the Copy Activity:
- Open your pipeline and go to the Copy Activity.
- Under General settings, configure the Retry option (e.g., 3 retries with 30 seconds delay).
7. Check File System or File Path Issues:
Ensure that the path (Enterprise Data Store/Secured/interimdata/InboundFiles/DeltaLoad/CDP/Customer_Profile_Aggregates/...
) exists and the file system is accessible. Also, confirm that the file is not being locked by another operation.
Summary:
- Check and acquire a lease if required, or renew it periodically to prevent expiration during the operation.
- Manually break the lease if another process is holding a stale lease.
- Ensure permissions are set correctly for accessing the ADLS resource.
- Add retry logic to handle transient issues and network problems.