Search code examples
azureazure-storageazure-blob-storage

CloudBlob.CopyState is null after direct account-to-account copy completes


Edit: Extended code sample to show how the destinationBlob is loaded.

We're making use of direct account to account copying to transfer a set of blobs. Because properties are overwritten when the process starts we monitor the destination blobs on an interval then set properties when the copy is complete. For the most part this process works fine.

However, for just a couple of these blobs, there is no copy state on the destination blob (CloudBlob.CopyState is null). These blobs do not exist before hand, they're created as a result of calling CloudBlob.StartCopyAsync().

Here is some simplified code to outline how it works.

// Start copy operation
var operationId = await destinationBlob.StartCopyAsync(new Uri(sourceBlobUrlWithSas));

...

// In a separate process, check the status after a delay, then repeat on an interval
var destinationBlob = await _destinationContainer.GetBlobReferenceFromServerAsync(blobName);

if (destinationBlob.CopyState.Status == CopyStatus.Success) // <-- CopyState is null
{
    // Set properties
}

Microsoft docs indicate CopyState will be null when there is no copy state, but don't outline when that is. From my own experimentation, the destination blob seems to be created immediately, and the copy state seems remain on the blob for some time after an copy operation completes. When the issue occurs it's only a few minutes between starting the copy and checking the CopyState.

What could be the issue? Are there alternate methods of setting properties on the destination blob?


Solution

  • This issue ended up being due to a logic error whereby blobs would be 'touched' resulting in the copy state being removed. The documentation around the lifecycle of copy state data could certainly be better, though hopefully this insight helps others who encounter a similar issue.