I am trying to copy a blob from a source location to a destination location under lease. I am using a modified version of AutoRenewLease to be able to do this. Here are the steps in my code
- Create an empty destination blob if blob doesn't exist
- Obtain a regular 30 second lease (which I autorenew) on the blob with leaseId
- Use leaseId to create an AccessCondition object
- Pass the AccessCondition object to StartCopyFromBlobAsync as destAccessCondition
Actual Result: The remote server returned an error: (412) The lease ID matched, but the specified lease must be an infinite-duration lease.
Is there a way to workaround this issue and copy a blob without an infinite lease.
Based on the documentation
here, it is not possible to initiate a copy blob operation where destination blob has finite lease.So if you want to go with lease option, it will have to be an infinite lease on the blob.
Here's one approach I could think of: Because you're already leasing the blob and constantly renewing the lease, my assumption is that you're storing this lease id somewhere (your copy VM could possible crash in those 30 second as well). So what you could do is acquire infinite lease, save the lease id on the blob in some permanent storage.
Then you constantly check the copy status of the destination blob. Once the blob is copied completely, you can simply break the lease on the blob. Now there's a possibility (as you mentioned) that your copy VM could go down. In that case, once the copy VM comes back online you start checking the copy status again. Also the maximum time alloted for copy operation is 2 weeks. If the blob is not copied in 2 weeks, you could simply break the lease on that blob. Please note that you don't need a least id when breaking lease on a blob.