Skip to content

Commit 510bd15

Browse files
authored
Merge pull request #181 from EmmaZhu/putblobfromurl
Add support for service side sync copy
2 parents d8f127b + e3352db commit 510bd15

File tree

59 files changed

+2517
-206
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+2517
-206
lines changed

BreakingChanges.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
Tracking Breaking Changes since 0.12.0
2+
- Changed parameter isServiceCopy of bool value to copyMethod which is an enumeration value in interfaces of CopyAsync and CopyDirectoryAsync.
3+
14
Tracking Breaking Changes since 0.10.1
25
- Changed base namespace from Microsoft.WindowsAzure.Storage.DataMovement to Microsoft.Azure.Storage.DataMovement,
36
to keep align with azure storage client libraries' namespace change from Microsoft.WindowsAzure.Storage to Microsoft.Azure.Storage, assembly name is changed accordingly.

README.md

Lines changed: 112 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Microsoft Azure Storage Data Movement Library (0.12.0)
1+
# Microsoft Azure Storage Data Movement Library (1.0.0)
22

33
The Microsoft Azure Storage Data Movement Library designed for high-performance uploading, downloading and copying Azure Storage Blob and File. This library is based on the core data movement framework that powers [AzCopy](https://azure.microsoft.com/documentation/articles/storage-use-azcopy/).
44

@@ -11,13 +11,13 @@ For more information about the Azure Storage, please visit [Microsoft Azure Stor
1111

1212
- Blobs
1313
- Download/Upload/Copy Blobs.
14-
- Synchronous and asynchronous copy Blobs
14+
- Copy Blobs with synchronous copying, service side asynchronous copying and service side synchronous copying.
1515
- Concurrently transfer Blobs and Blob chunks, define number of concurrent operations
1616
- Download Specific Blob Snapshot
1717

1818
- Files
1919
- Download/Upload/Copy Files.
20-
- Synchronous and asynchronous copy Files
20+
- Copy File with synchronous copying and service side asynchronous copying.
2121
- Concurrently transfer Files and File ranges, define number of concurrent operations
2222

2323
- General
@@ -120,6 +120,55 @@ var task = TransferManager.UploadAsync(
120120
sourcePath, destBlob, null, context, CancellationToken.None);
121121
task.Wait();
122122
```
123+
124+
### Copy a blob
125+
126+
First, include the classes you need, which is the same as the sample to Upload a blob.
127+
128+
```csharp
129+
using System;
130+
using System.Threading;
131+
using Microsoft.Azure.Storage;
132+
using Microsoft.Azure.Storage.Blob;
133+
using Microsoft.Azure.Storage.DataMovement;
134+
```
135+
136+
Now use the interfaces provided by Storage client lib to setup the storage contexts (find more details at [how to use Blob Storage from .NET](https://azure.microsoft.com/documentation/articles/storage-dotnet-how-to-use-blobs/)):
137+
138+
```csharp
139+
string sourceStorageConnectionString = "sourceStorageConnectionString";
140+
CloudStorageAccount sourceAccount = CloudStorageAccount.Parse(sourceStorageConnectionString);
141+
CloudBlobClient sourceBlobClient = sourceAccount.CreateCloudBlobClient();
142+
CloudBlobContainer sourceBlobContainer = sourceBlobClient.GetContainerReference("sourcecontainer");
143+
CloudBlockBlob sourceBlob = sourceBlobContainer.GetBlockBlobReference("sourceBlobName");
144+
145+
string destStorageConnectionString = "destinationStorageConnectionString";
146+
CloudStorageAccount destAccount = CloudStorageAccount.Parse(destStorageConnectionString);
147+
CloudBlobClient destBlobClient = sourceAccount.CreateCloudBlobClient();
148+
CloudBlobContainer destBlobContainer = sourceBlobClient.GetContainerReference("destinationcontainer");
149+
CloudBlockBlob destBlob = sourceBlobContainer.GetBlockBlobReference("destBlobName");
150+
```
151+
152+
Once you setup the storage blob contexts, you can start to use `WindowsAzure.Storage.DataMovement.TransferManager` to copy the blob and track the copy progress:
153+
154+
```csharp
155+
// Setup the number of the concurrent operations
156+
TransferManager.Configurations.ParallelOperations = 64;
157+
// Setup the transfer context and track the copy progress
158+
SingleTransferContext context = new SingleTransferContext();
159+
context.ProgressHandler = new Progress<TransferStatus>((progress) =>
160+
{
161+
Console.WriteLine("Bytes Copied: {0}", progress.BytesTransferred);
162+
});
163+
164+
// Copy a blob
165+
var task = TransferManager.CopyAsync(
166+
sourceBlob, destBlob, CopyMethod.ServiceSideSyncCopy, null, context, CancellationToken.None);
167+
task.Wait();
168+
```
169+
170+
DMLib supports three different copying methods: Synchronous Copy, Service Side Asynchronous Copy and Service Side Synchronous Copy. The above sample uses Service Side Synchronous Copy. See [Choose Copy Method](#choose-copy-method) for details on how to choose the copy method.
171+
123172
# Best Practice
124173

125174
### Increase .NET HTTP connections limit
@@ -200,6 +249,66 @@ The following matrix explains how the DirectoryOptions.Recursive and DirectoryOp
200249

201250
- Default recursive option: false
202251

252+
### Choose Copy Method
253+
DMLib supports three copy methods:
254+
- Synchronous Copy
255+
DMLib downloads data from source to memory, and uploads the data from memory to destination.
256+
257+
- Service Side Asynchronous Copy
258+
DMLib sends request to Azure Storage Server to start the copying, and monitors its status until the copying is completed.
259+
260+
- Service Side Synchronous Copy
261+
DMLib leverages [Put Block From URL](https://docs.microsoft.com/en-us/rest/api/storageservices/put-block-from-url), [Append Block From URL](https://docs.microsoft.com/en-us/rest/api/storageservices/append-block-from-url), [Put Page From URL](https://docs.microsoft.com/en-us/rest/api/storageservices/put-page-from-url) to copy Azure Storage Blobs.
262+
263+
Following is suggested copy method for different scenarios:
264+
- From performance aspect: <br>
265+
Based on Azure Storage Server's [SLA for Storage Accounts](https://azure.microsoft.com/en-us/support/legal/sla/storage/v1_5/), following are suggestions when copying performance is most important to you:
266+
- To copy between blobs or files inner storage account, Service Side Asynchronous Copy would be suggested.
267+
- To copy Blobs, Service Side Synchronous Copy would be suggested.
268+
- To copy Files or copy between Blobs and Files, Synchronous Copy would be suggested. To achieve best copying performance, Synchronous Copy would need a powerful machine in Azure.
269+
- From cost aspect, Service Side Asynchronous Copy would cost least.
270+
- From data flow approach, Synchronous Copy would be well controlled. With Synchronous Copy, the data will go through the network configured by you.
271+
- From supported directions, Synchronous Copy and Service Side Asynchronous Copy support more directions than Service Side Synchronous Copy. See details in below table
272+
273+
Following table shows supported directions with different copy method.
274+
<table>
275+
<tr>
276+
<td></td>
277+
<th scope="col">Append Blob</th>
278+
<th scope="col">Block Blob</th>
279+
<th scope="col">Page Blob</th>
280+
<th scope="col">Azure File</th>
281+
</tr>
282+
<tr>
283+
<th scope="row">Append Blob</th>
284+
<td>Synchronous Copy <br> Service Side Asynchronous Copy <br> Service Side Synchronous Copy</td>
285+
<td>N/A</td>
286+
<td>N/A</td>
287+
<td>Synchronous Copy <br> Service Side Asynchronous Copy</td>
288+
</tr>
289+
<tr>
290+
<th scope="row">Block Blob</th>
291+
<td>N/A</td>
292+
<td>Synchronous Copy <br> Service Side Asynchronous Copy <br> Service Side Synchronous Copy</td>
293+
<td>N/A</td>
294+
<td>Synchronous Copy <br> Service Side Asynchronous Copy</td>
295+
</tr>
296+
<tr>
297+
<th scope="row">Page Blob</th>
298+
<td>N/A</td>
299+
<td>N/A</td>
300+
<td>Synchronous Copy <br> Service Side Asynchronous Copy <br> Service Side Synchronous Copy</td>
301+
<td>Synchronous Copy <br> Service Side Asynchronous Copy</td>
302+
</tr>
303+
<tr>
304+
<th scope="row">File</th>
305+
<td>Synchronous Copy <br> Service Side Asynchronous Copy</td>
306+
<td>Synchronous Copy <br> Service Side Asynchronous Copy</td>
307+
<td>Synchronous Copy <br> Service Side Asynchronous Copy</td>
308+
<td>Synchronous Copy <br> Service Side Asynchronous Copy</td>
309+
</tr>
310+
</table>
311+
203312
# Need Help?
204313
Be sure to check out the Microsoft Azure [Developer Forums on MSDN](http://go.microsoft.com/fwlink/?LinkId=234489) if you have trouble with the provided code or use StackOverflow.
205314

changelog.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2019.08.08 Version 1.0.0
2+
* Blob Service on both .Net Framework and .Net Core
3+
- Added a copy method to leverage Service Side Synchronous Copy when copying blobs.
4+
- Changed default block size in uploading block blob from 8MB to 4MB.
5+
16
2019.07.05 Version 0.12.0
27
* All Services on both .Net Framework and .Net Core
38
- Upgraded Microsoft.Azure.Storage.Blob from 10.0.1 to 10.0.3

lib/Constants.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,14 @@ public static class Constants
2020
public const int MaxBlockSize = 100 * 1024 * 1024;
2121

2222
/// <summary>
23-
/// Default block size, 4MB.
23+
/// Default block size when transferring block blob, 8MB.
2424
/// </summary>
25-
public const int DefaultBlockSize = 4 * 1024 * 1024;
25+
public const int DefaultBlockBlobBlockSize = 8 * 1024 * 1024;
26+
27+
/// <summary>
28+
/// Default size for a chunk transferring, 4MB.
29+
/// </summary>
30+
public const int DefaultTransferChunkSize = 4 * 1024 * 1024;
2631

2732
/// <summary>
2833
/// Default memory chunk size of memory pool, 4MB.

lib/CopyMethod.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//------------------------------------------------------------------------------
2+
// <copyright file="CopyMethod.cs" company="Microsoft">
3+
// Copyright (c) Microsoft Corporation
4+
// </copyright>
5+
//------------------------------------------------------------------------------
6+
7+
8+
namespace Microsoft.Azure.Storage.DataMovement
9+
{
10+
/// <summary>
11+
/// Enum to indicate how the copying operation is handled in DataMovement Library.
12+
/// </summary>
13+
public enum CopyMethod
14+
{
15+
/// <summary>
16+
/// To download data from source to memory, and upload the data from memory to destination.
17+
/// </summary>
18+
SyncCopy,
19+
20+
/// <summary>
21+
/// To send a start copy request to azure storage to let it do the copying,
22+
/// and monitor the copying progress until the copy completed.
23+
/// </summary>
24+
ServiceSideAsyncCopy,
25+
26+
/// <summary>
27+
/// To copy content of each chunk with with Put Block From URL, Append Block From URL or Put Page From URL.
28+
/// See <c>https://docs.microsoft.com/en-us/rest/api/storageservices/put-block-from-url</c> for Put Block From URL,
29+
/// <c>https://docs.microsoft.com/en-us/rest/api/storageservices/append-block-from-url</c> for Append Block From URL,
30+
/// <c>https://docs.microsoft.com/en-us/rest/api/storageservices/put-page-from-url</c> for Put Page From URL for details.
31+
/// </summary>
32+
ServiceSideSyncCopy
33+
}
34+
}

lib/DataMovement.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
</Compile>
8686
<Compile Include="AssemblyInfo.cs" />
8787
<Compile Include="ChunkedMemoryStream.cs" />
88+
<Compile Include="CopyMethod.cs" />
8889
<Compile Include="DirectoryListingScheduler.cs" />
8990
<Compile Include="Extensions\StorageCopyState.cs" />
9091
<Compile Include="FileNativeMethods.cs" />
@@ -115,6 +116,10 @@
115116
<Compile Include="TransferControllers\AsyncCopyControllers\FileAsyncCopyController.cs" />
116117
<Compile Include="TransferControllers\AsyncCopyControllers\AsyncCopyController.cs" />
117118
<Compile Include="TransferControllers\DummyTransferController.cs" />
119+
<Compile Include="TransferControllers\ServerSideSyncCopyControllers\AppendBlobServiceSideSyncCopyController.cs" />
120+
<Compile Include="TransferControllers\ServerSideSyncCopyControllers\BlockBlobServiceSideSyncCopyController.cs" />
121+
<Compile Include="TransferControllers\ServerSideSyncCopyControllers\PageBlobServiceSideSyncCopyController.cs" />
122+
<Compile Include="TransferControllers\ServerSideSyncCopyControllers\ServiceSideSyncCopyController.cs" />
118123
<Compile Include="TransferControllers\TransferReaders\CloudFileReader.cs" />
119124
<Compile Include="TransferControllers\TransferReaders\PageBlobReader.cs" />
120125
<Compile Include="TransferControllers\TransferReaders\RangeBasedReader.cs" />

lib/Resources.Designer.cs

Lines changed: 28 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/Resources.resx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,9 @@ MD5 in property: {2}</value>
269269
<data name="RestartableInfoCorruptedException" xml:space="preserve">
270270
<value>Failed to read restartable info from file.</value>
271271
</data>
272+
<data name="ServiceSideSyncCopyNotSupportException" xml:space="preserve">
273+
<value>Service side synchronous copying is only supported when destination is Azure Blob Storage.</value>
274+
</data>
272275
<data name="SmallMemoryCacheSizeLimitationException" xml:space="preserve">
273276
<value>MaximumCacheSize cannot be less than {0}.</value>
274277
<comment>{0} is minimum memory cache size limitation</comment>
@@ -336,6 +339,12 @@ MD5 in property: {2}</value>
336339
<data name="AzureFile" xml:space="preserve">
337340
<value>AzureFile</value>
338341
</data>
342+
<data name="ServiceSideSyncCopyFromFileNotSupportedException" xml:space="preserve">
343+
<value>Copying from Azure File Storage with service side synchronous copying is not supported.</value>
344+
</data>
345+
<data name="ServiceSideSyncCopyToFileNotSupportedException" xml:space="preserve">
346+
<value>Copying to Azure File Storage with service side synchronous copying is not supported.</value>
347+
</data>
339348
<data name="SyncCopyFromUriToAzureBlobNotSupportedException" xml:space="preserve">
340349
<value>Copying from uri to Azure Blob Storage synchronously is not supported.</value>
341350
</data>

lib/TransferConfigurations.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public class TransferConfigurations
4444
public TransferConfigurations()
4545
{
4646
// setup default values.
47-
this.blockSize = Constants.DefaultBlockSize;
47+
this.blockSize = Constants.DefaultTransferChunkSize;
4848
this.parallelOperations = Environment.ProcessorCount * 8;
4949
this.MemoryChunkSize = Constants.DefaultMemoryChunkSize;
5050

@@ -107,7 +107,7 @@ public int BlockSize
107107
throw new ArgumentOutOfRangeException("value", value, errorMessage);
108108
}
109109

110-
if (value % Constants.DefaultBlockSize != 0)
110+
if (value % Constants.DefaultTransferChunkSize != 0)
111111
{
112112
throw new ArgumentException(Resources.BlockSizeMustBeMultipleOf4MB, "value");
113113
}
@@ -140,12 +140,12 @@ internal long MaximumCacheSize
140140

141141
set
142142
{
143-
if (value < Constants.DefaultBlockSize)
143+
if (value < Constants.DefaultTransferChunkSize)
144144
{
145145
throw new ArgumentException(string.Format(
146146
CultureInfo.CurrentCulture,
147147
Resources.SmallMemoryCacheSizeLimitationException,
148-
Utils.BytesToHumanReadableSize(Constants.DefaultBlockSize)));
148+
Utils.BytesToHumanReadableSize(Constants.DefaultTransferChunkSize)));
149149
}
150150

151151
if (0 == this.memStatus.AvailablePhysicalMemory)

lib/TransferControllers/AsyncCopyControllers/AsyncCopyController.cs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -166,21 +166,6 @@ protected abstract Uri DestUri
166166
get;
167167
}
168168

169-
public static AsyncCopyController CreateAsyncCopyController(TransferScheduler transferScheduler, TransferJob transferJob, CancellationToken cancellationToken)
170-
{
171-
if (transferJob.Destination.Type == TransferLocationType.AzureFile)
172-
{
173-
return new FileAsyncCopyController(transferScheduler, transferJob, cancellationToken);
174-
}
175-
176-
if (transferJob.Destination.Type == TransferLocationType.AzureBlob)
177-
{
178-
return new BlobAsyncCopyController(transferScheduler, transferJob, cancellationToken);
179-
}
180-
181-
throw new InvalidOperationException(Resources.CanOnlyCopyToFileOrBlobException);
182-
}
183-
184169
/// <summary>
185170
/// Do work in the controller.
186171
/// A controller controls the whole transfer from source to destination,

0 commit comments

Comments
 (0)