From 79363b8bf5828fea8348aa8c5950d8d8e2470668 Mon Sep 17 00:00:00 2001 From: Weibing Zhan Date: Fri, 28 Jul 2023 15:00:15 -0700 Subject: [PATCH] Delete the lease-detection blob after the migration for the asset is done --- azure/AzureStorageUploader.cs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/azure/AzureStorageUploader.cs b/azure/AzureStorageUploader.cs index fbd36a8..908bf27 100644 --- a/azure/AzureStorageUploader.cs +++ b/azure/AzureStorageUploader.cs @@ -257,11 +257,17 @@ public async Task UploadCleanupAsync( CancellationToken cancellationToken) { var lockBlob = await GetLockBlobAsync(containerName, outputPath, cancellationToken); - var leaseClient = lockBlob.GetBlobLeaseClient(_leaseId); - await leaseClient.ReleaseAsync(cancellationToken: cancellationToken); + // The lease is guaranteed to hold by this tool, the migration work for the asset + // has done, no matter succeed or failed, + // + // It is safe to delete the lease-detection blob now. - _logger.LogTrace("The lease for output path {path} under {container} is released.", + await lockBlob.DeleteAsync(DeleteSnapshotsOption.IncludeSnapshots, + new BlobRequestConditions() { LeaseId = _leaseId }, + cancellationToken); + + _logger.LogTrace("The lease-detect blob for output path {path} under {container} is deleted.", outputPath, containerName); }