Skip to content

Commit 1205394

Browse files
Updates to .NET lease articles
1 parent 3d0577e commit 1205394

File tree

5 files changed

+162
-50
lines changed

5 files changed

+162
-50
lines changed

articles/storage/blobs/storage-blob-container-lease-python.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ ms.custom: devx-track-python, devguide-python
1616

1717
# Create and manage container leases with Python
1818

19-
This article shows how to create and manage container leases using the [Azure Storage client library for Python](/python/api/overview/azure/storage).
19+
This article shows how to create and manage container leases using the [Azure Storage client library for Python](/python/api/overview/azure/storage). You can use the Python client library to acquire, renew, release and break container leases.
2020

2121
A lease establishes and manages a lock on a container for delete operations. The lock duration can be 15 to 60 seconds, or can be infinite. A lease on a container provides exclusive delete access to the container. A container lease only controls the ability to delete the container using the [Delete Container](/rest/api/storageservices/delete-container) REST API operation. To delete a container with an active lease, a client must include the active lease ID with the delete request. All other container operations will succeed on a leased container without the lease ID. If you've enabled [container soft delete](soft-delete-container-overview.md), you can restore deleted containers.
2222

articles/storage/blobs/storage-blob-container-lease.md

Lines changed: 30 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,80 @@
11
---
2-
title: Create and manage blob or container leases with .NET
2+
title: Create and manage container leases with .NET
33
titleSuffix: Azure Storage
4-
description: Learn how to manage a lock on a blob or container in your Azure Storage account using the .NET client library.
4+
description: Learn how to manage a lock on a container in your Azure Storage account using the .NET client library.
55
services: storage
66
author: pauljewellmsft
77
ms.author: pauljewell
88

99
ms.service: storage
1010
ms.topic: how-to
11-
ms.date: 03/28/2022
11+
ms.date: 04/10/2023
1212
ms.subservice: blobs
1313
ms.devlang: csharp
1414
ms.custom: devx-track-csharp, devguide-csharp
1515
---
1616

17-
# Create and manage blob or container leases with .NET
17+
# Create and manage container leases with .NET
1818

19-
A lease establishes and manages a lock on a container or the blobs in a container. You can use the .NET client library to acquire, renew, release and break leases. To learn more about leasing blobs or containers, see [Lease Container](/rest/api/storageservices/lease-container) or [Lease Blobs](/rest/api/storageservices/lease-blob).
19+
This article shows how to create and manage container leases using the [Azure Storage client library for .NET](/dotnet/api/overview/azure/storage). You can use the .NET client library to acquire, renew, release, and break container leases.
20+
21+
## About container leases
22+
23+
[!INCLUDE [storage-dev-guide-about-container-lease](../../../includes/storage-dev-guides/storage-dev-guide-about-container-lease.md)]
24+
25+
To learn more about container leases using the client library, see [Create and manage blob leases with .NET](storage-blob-lease.md).
2026

2127
## Acquire a lease
2228

23-
When you acquire a lease, you'll obtain a lease ID that your code can use to operate on the blob or container. To acquire a lease, create an instance of the [BlobLeaseClient](/dotnet/api/azure.storage.blobs.specialized.blobleaseclient) class, and then use either of these methods:
29+
When you acquire a container lease, you obtain a lease ID that your code can use to operate on the container. If the container already has an active lease, you can only request a new lease by using the active lease ID. However, you can specify a new lease duration. To acquire a lease, create an instance of the [BlobLeaseClient](/dotnet/api/azure.storage.blobs.specialized.blobleaseclient) class, and then use one of the following methods:
2430

2531
- [Acquire](/dotnet/api/azure.storage.blobs.specialized.blobleaseclient.acquire)
2632
- [AcquireAsync](/dotnet/api/azure.storage.blobs.specialized.blobleaseclient.acquireasync)
2733

28-
The following example acquires a 30 second lease for a container.
29-
30-
```csharp
31-
public static async Task AcquireLease(BlobContainerClient containerClient)
32-
{
33-
BlobLeaseClient blobLeaseClient = containerClient.GetBlobLeaseClient();
34+
The following example acquires a 30-second lease for a container:
3435

35-
TimeSpan ts = new TimeSpan(0, 0, 0, 30);
36-
Response<BlobLease> blobLeaseResponse = await blobLeaseClient.AcquireAsync(ts);
37-
38-
Console.WriteLine("Blob Lease Id:" + blobLeaseResponse.Value.LeaseId);
39-
Console.WriteLine("Remaining Lease Time: " + blobLeaseResponse.Value.LeaseTime);
40-
}
41-
```
36+
:::code language="csharp" source="~/azure-storage-snippets/blobs/howto/dotnet/BlobDevGuideBlobs/LeaseContainer.cs" id="Snippet_AcquireContainerLease":::
4237

4338
## Renew a lease
4439

45-
If your lease expires, you can renew it. To renew a lease, use either of the following methods of the [BlobLeaseClient](/dotnet/api/azure.storage.blobs.specialized.blobleaseclient) class:
40+
You can renew a container lease if the lease ID specified on the request matches the lease ID associated with the container. The lease can be renewed even if it has expired, as long as the container hasn't been leased again since the expiration of that lease. When you renew a lease, the duration of the lease resets.
41+
42+
To renew a lease, use one of the following methods on a [BlobLeaseClient](/dotnet/api/azure.storage.blobs.specialized.blobleaseclient) instance:
4643

4744
- [Renew](/dotnet/api/azure.storage.blobs.specialized.blobleaseclient.renew)
4845
- [RenewAsync](/dotnet/api/azure.storage.blobs.specialized.blobleaseclient.renewasync)
4946

50-
Specify the lease ID by setting the [IfMatch](/dotnet/api/azure.matchconditions.ifmatch) property of a [RequestConditions](/dotnet/api/azure.requestconditions) instance.
47+
You can specify the lease ID by setting the [IfMatch](/dotnet/api/azure.matchconditions.ifmatch) property of a [RequestConditions](/dotnet/api/azure.requestconditions) instance.
5148

52-
The following example renews a lease for a blob.
49+
The following example renews a container lease:
5350

54-
```csharp
55-
public static async Task RenewLease(BlobClient blobClient, string leaseID)
56-
{
57-
BlobLeaseClient blobLeaseClient = blobClient.GetBlobLeaseClient();
58-
RequestConditions requestConditions = new RequestConditions();
59-
requestConditions.IfMatch = new ETag(leaseID);
60-
await blobLeaseClient.RenewAsync();
61-
}
62-
```
51+
:::code language="csharp" source="~/azure-storage-snippets/blobs/howto/dotnet/BlobDevGuideBlobs/LeaseContainer.cs" id="Snippet_RenewContainerLease":::
6352

6453
## Release a lease
6554

66-
You can either wait for a lease to expire or explicitly release it. When you release a lease, other clients can obtain a lease. You can release a lease by using either of these methods of the [BlobLeaseClient](/dotnet/api/azure.storage.blobs.specialized.blobleaseclient) class.
55+
You can release a container lease if the lease ID specified on the request matches the lease ID associated with the container. Releasing a lease allows another client to acquire a lease for the container immediately after the release is complete.
56+
57+
You can release a lease using one of the following methods on a [BlobLeaseClient](/dotnet/api/azure.storage.blobs.specialized.blobleaseclient) instance:
6758

6859
- [Release](/dotnet/api/azure.storage.blobs.specialized.blobleaseclient.release)
6960
- [ReleaseAsync](/dotnet/api/azure.storage.blobs.specialized.blobleaseclient.releaseasync)
7061

71-
The following example releases the lease on a container.
62+
The following example releases a lease on a container:
7263

73-
```csharp
74-
public static async Task ReleaseLease(BlobContainerClient containerClient)
75-
{
76-
BlobLeaseClient blobLeaseClient = containerClient.GetBlobLeaseClient();
77-
await blobLeaseClient.ReleaseAsync();
78-
}
79-
```
64+
:::code language="csharp" source="~/azure-storage-snippets/blobs/howto/dotnet/BlobDevGuideBlobs/LeaseContainer.cs" id="Snippet_ReleaseContainerLease":::
8065

8166
## Break a lease
8267

83-
When you break a lease, the lease ends, but other clients can't acquire a lease until the lease period expires. You can break a lease by using either of these methods:
68+
You can break a container lease if the container has an active lease. Any authorized request can break the lease; the request isn't required to specify a matching lease ID. A lease can't be renewed after it's broken, and breaking a lease prevents a new lease from being acquired for a period of time until the original lease expires or is released.
69+
70+
You can break a lease using one of the following methods on a [BlobLeaseClient](/dotnet/api/azure.storage.blobs.specialized.blobleaseclient) instance:
8471

8572
- [Break](/dotnet/api/azure.storage.blobs.specialized.blobleaseclient.break)
8673
- [BreakAsync](/dotnet/api/azure.storage.blobs.specialized.blobleaseclient.breakasync);
8774

88-
The following example breaks the lease on a blob.
75+
The following example breaks a lease on a container:
8976

90-
```csharp
91-
public static async Task BreakLease(BlobClient blobClient)
92-
{
93-
BlobLeaseClient blobLeaseClient = blobClient.GetBlobLeaseClient();
94-
await blobLeaseClient.BreakAsync();
95-
}
96-
```
77+
:::code language="csharp" source="~/azure-storage-snippets/blobs/howto/dotnet/BlobDevGuideBlobs/LeaseContainer.cs" id="Snippet_BreakContainerLease":::
9778

9879
## See also
9980

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
---
2+
title: Create and manage blob leases with .NET
3+
titleSuffix: Azure Storage
4+
description: Learn how to manage a lock on a blob in your Azure Storage account using the .NET client library.
5+
services: storage
6+
author: pauljewellmsft
7+
ms.author: pauljewell
8+
9+
ms.service: storage
10+
ms.topic: how-to
11+
ms.date: 04/10/2023
12+
ms.subservice: blobs
13+
ms.devlang: csharp
14+
ms.custom: devx-track-csharp, devguide-csharp
15+
---
16+
17+
# Create and manage blob leases with .NET
18+
19+
This article shows how to create and manage blob leases using the [Azure Storage client library for .NET](/dotnet/api/overview/azure/storage). You can use the .NET client library to acquire, renew, release, and break blob leases.
20+
21+
## About blob leases
22+
23+
[!INCLUDE [storage-dev-guide-about-blob-lease](../../../includes/storage-dev-guides/storage-dev-guide-about-blob-lease.md)]
24+
25+
To learn more about container leases using the client library, see [Create and manage container leases with .NET](storage-blob-container-lease.md).
26+
27+
## Acquire a lease
28+
29+
When you acquire a blob lease, you obtain a lease ID that your code can use to operate on the blob. If the blob already has an active lease, you can only request a new lease by using the active lease ID. However, you can specify a new lease duration. To acquire a lease, create an instance of the [BlobLeaseClient](/dotnet/api/azure.storage.blobs.specialized.blobleaseclient) class, and then use one of the following methods:
30+
31+
- [Acquire](/dotnet/api/azure.storage.blobs.specialized.blobleaseclient.acquire)
32+
- [AcquireAsync](/dotnet/api/azure.storage.blobs.specialized.blobleaseclient.acquireasync)
33+
34+
The following example acquires a 30-second lease for a blob:
35+
36+
:::code language="csharp" source="~/azure-storage-snippets/blobs/howto/dotnet/BlobDevGuideBlobs/LeaseBlob.cs" id="Snippet_AcquireBlobLease":::
37+
38+
## Renew a lease
39+
40+
You can renew a blob lease if the lease ID specified on the request matches the lease ID associated with the blob. The lease can be renewed even if it has expired, as long as the blob hasn't been modified or leased again since the expiration of that lease. When you renew a lease, the duration of the lease resets.
41+
42+
To renew a lease, use one of the following methods on a [BlobLeaseClient](/dotnet/api/azure.storage.blobs.specialized.blobleaseclient) instance:
43+
44+
- [Renew](/dotnet/api/azure.storage.blobs.specialized.blobleaseclient.renew)
45+
- [RenewAsync](/dotnet/api/azure.storage.blobs.specialized.blobleaseclient.renewasync)
46+
47+
You can specify the lease ID by setting the [IfMatch](/dotnet/api/azure.matchconditions.ifmatch) property of a [RequestConditions](/dotnet/api/azure.requestconditions) instance.
48+
49+
The following example renews a lease for a blob:
50+
51+
:::code language="csharp" source="~/azure-storage-snippets/blobs/howto/dotnet/BlobDevGuideBlobs/LeaseBlob.cs" id="Snippet_RenewBlobLease":::
52+
53+
## Release a lease
54+
55+
You can release a blob lease if the lease ID specified on the request matches the lease ID associated with the blob. Releasing a lease allows another client to acquire a lease for the blob immediately after the release is complete.
56+
57+
You can release a lease using one of the following methods on a [BlobLeaseClient](/dotnet/api/azure.storage.blobs.specialized.blobleaseclient) instance:
58+
59+
- [Release](/dotnet/api/azure.storage.blobs.specialized.blobleaseclient.release)
60+
- [ReleaseAsync](/dotnet/api/azure.storage.blobs.specialized.blobleaseclient.releaseasync)
61+
62+
The following example releases a lease on a blob:
63+
64+
:::code language="csharp" source="~/azure-storage-snippets/blobs/howto/dotnet/BlobDevGuideBlobs/LeaseBlob.cs" id="Snippet_ReleaseBlobLease":::
65+
66+
## Break a lease
67+
68+
You can break a blob lease if the blob has an active lease. Any authorized request can break the lease; the request isn't required to specify a matching lease ID. A lease can't be renewed after it's broken, and breaking a lease prevents a new lease from being acquired for a period of time until the original lease expires or is released.
69+
70+
You can break a lease using one of the following methods on a [BlobLeaseClient](/dotnet/api/azure.storage.blobs.specialized.blobleaseclient) instance:
71+
72+
- [Break](/dotnet/api/azure.storage.blobs.specialized.blobleaseclient.break)
73+
- [BreakAsync](/dotnet/api/azure.storage.blobs.specialized.blobleaseclient.breakasync);
74+
75+
The following example breaks a lease on a blob:
76+
77+
:::code language="csharp" source="~/azure-storage-snippets/blobs/howto/dotnet/BlobDevGuideBlobs/LeaseBlob.cs" id="Snippet_BreakBlobLease":::
78+
79+
[!INCLUDE [storage-dev-guide-blob-lease](../../../includes/storage-dev-guides/storage-dev-guide-blob-lease.md)]
80+
81+
## Resources
82+
83+
To learn more about managing blob leases using the Azure Blob Storage client library for .NET, see the following resources.
84+
85+
### REST API operations
86+
87+
The Azure SDK for .NET contains libraries that build on top of the Azure REST API, allowing you to interact with REST API operations through familiar .NET paradigms. The client library methods for managing blob leases use the following REST API operation:
88+
89+
- [Lease Blob](/rest/api/storageservices/lease-blob)
90+
91+
### Code samples
92+
93+
- [View code samples from this article (GitHub)](https://github.com/Azure-Samples/AzureStorageSnippets/blob/master/blobs/howto/dotnet/BlobDevGuideBlobs/LeaseBlob.cs)
94+
95+
[!INCLUDE [storage-dev-guide-resources-dotnet](../../../includes/storage-dev-guides/storage-dev-guide-resources-dotnet.md)]
96+
97+
### See also
98+
99+
- [Managing Concurrency in Blob storage](concurrency-manage.md)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
title: "include file"
3+
description: "include file"
4+
services: storage
5+
author: pauljewellmsft
6+
ms.service: storage
7+
ms.topic: include
8+
ms.date: 04/10/2023
9+
ms.author: pauljewell
10+
ms.custom: include file
11+
---
12+
13+
A lease creates and manages a lock on a blob for write and delete operations. The lock duration can be 15 to 60 seconds, or can be infinite. A lease on a blob provides exclusive write and delete access to the blob. To write to a blob with an active lease, a client must include the active lease ID with the write request.
14+
15+
Lease operations are handled by the [BlobLeaseClient](/dotnet/api/azure.storage.blobs.specialized.blobleaseclient) class, which provides a client containing all lease operations for blobs and blob containers. To learn more about lease states and when you might perform an action on a lease, see [Lease states and actions](#lease-states-and-actions).
16+
17+
All container operations are permitted on a container that includes blobs with an active lease, including [Delete Container](/rest/api/storageservices/delete-container). Therefore, a container may be deleted even if blobs within it have active leases. Use the [Lease Container](/rest/api/storageservices/lease-container) operation to control rights to delete a container.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
title: "include file"
3+
description: "include file"
4+
services: storage
5+
author: pauljewellmsft
6+
ms.service: storage
7+
ms.topic: include
8+
ms.date: 04/10/2023
9+
ms.author: pauljewell
10+
ms.custom: include file
11+
---
12+
13+
A lease establishes and manages a lock on a container for delete operations. The lock duration can be 15 to 60 seconds, or can be infinite. A lease on a container provides exclusive delete access to the container. A container lease only controls the ability to delete the container using the [Delete Container](/rest/api/storageservices/delete-container) REST API operation. To delete a container with an active lease, a client must include the active lease ID with the delete request. All other container operations will succeed on a leased container without the lease ID. If you've enabled [container soft delete](soft-delete-container-overview.md), you can restore deleted containers.
14+
15+
Lease operations are handled by the [BlobLeaseClient](/dotnet/api/azure.storage.blobs.specialized.blobleaseclient) class, which provides a client containing all lease operations for blobs and blob containers. To learn more about lease states and when you might perform an action on a lease, see [Lease states and actions](#lease-states-and-actions).

0 commit comments

Comments
 (0)