Skip to content

Commit d2d1fc7

Browse files
[Storage][DataMovement] Refactor download transfers (#47231)
1 parent 48e089c commit d2d1fc7

13 files changed

+170
-673
lines changed

sdk/storage/Azure.Storage.Common/src/Shared/ContentRange.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@ public static HttpRange ToHttpRange(ContentRange contentRange)
153153
{
154154
// Because constructing HttpRange is the start value, and the length of the range
155155
// increment 1 on the end value, since the end value is the end index (not the length).
156-
return new HttpRange(contentRange.Start.Value, contentRange.End.Value + 1);
156+
long length = contentRange.End.Value - contentRange.Start.Value + 1;
157+
return new HttpRange(contentRange.Start.Value, length);
157158
}
158159
return default;
159160
}

sdk/storage/Azure.Storage.DataMovement.Blobs/perf-tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Tests:
1515
Arguments: &sizes
1616
- --size 1024 --count 5000 --duration 60 --concurrency 64
1717
- --size 10485760 --count 500 --duration 90 --concurrency 64
18+
- --size 52428800 --count 200 --duration 120 --concurrency 64
1819
- --size 1073741824 --count 5 --duration 120 --concurrency 64
1920

2021
- Test: upload

sdk/storage/Azure.Storage.DataMovement/api/Azure.Storage.DataMovement.net6.0.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ public partial class StorageResourceWriteToOffsetOptions
220220
{
221221
public StorageResourceWriteToOffsetOptions() { }
222222
public string BlockId { get { throw null; } set { } }
223+
public bool Initial { get { throw null; } set { } }
223224
public long? Position { get { throw null; } set { } }
224225
public Azure.Storage.DataMovement.StorageResourceItemProperties SourceProperties { get { throw null; } set { } }
225226
}

sdk/storage/Azure.Storage.DataMovement/api/Azure.Storage.DataMovement.net8.0.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ public partial class StorageResourceWriteToOffsetOptions
220220
{
221221
public StorageResourceWriteToOffsetOptions() { }
222222
public string BlockId { get { throw null; } set { } }
223+
public bool Initial { get { throw null; } set { } }
223224
public long? Position { get { throw null; } set { } }
224225
public Azure.Storage.DataMovement.StorageResourceItemProperties SourceProperties { get { throw null; } set { } }
225226
}

sdk/storage/Azure.Storage.DataMovement/api/Azure.Storage.DataMovement.netstandard2.0.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ public partial class StorageResourceWriteToOffsetOptions
220220
{
221221
public StorageResourceWriteToOffsetOptions() { }
222222
public string BlockId { get { throw null; } set { } }
223+
public bool Initial { get { throw null; } set { } }
223224
public long? Position { get { throw null; } set { } }
224225
public Azure.Storage.DataMovement.StorageResourceItemProperties SourceProperties { get { throw null; } set { } }
225226
}

sdk/storage/Azure.Storage.DataMovement/src/DownloadChunkHandler.cs

Lines changed: 28 additions & 218 deletions
Large diffs are not rendered by default.

sdk/storage/Azure.Storage.DataMovement/src/DownloadRangeEventArgs.cs

Lines changed: 0 additions & 75 deletions
This file was deleted.

sdk/storage/Azure.Storage.DataMovement/src/LocalFileStorageResource.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,17 +126,17 @@ protected internal override async Task CopyFromStreamAsync(
126126
CancellationHelper.ThrowIfCancellationRequested(cancellationToken);
127127

128128
long position = options?.Position != default ? options.Position.Value : 0;
129-
if (position == 0)
129+
if (options?.Initial == true)
130130
{
131131
Create(overwrite);
132132
}
133133
if (streamLength > 0)
134134
{
135135
// Appends incoming stream to the local file resource
136136
using (FileStream fileStream = new FileStream(
137-
_uri.LocalPath,
138-
FileMode.OpenOrCreate,
139-
FileAccess.Write))
137+
_uri.LocalPath,
138+
FileMode.Open,
139+
FileAccess.Write))
140140
{
141141
if (position > 0)
142142
{
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using System.IO;
5+
6+
namespace Azure.Storage.DataMovement
7+
{
8+
internal class QueueDownloadChunkArgs
9+
{
10+
public long Offset { get; }
11+
public long Length { get; }
12+
public Stream Content { get; }
13+
14+
public QueueDownloadChunkArgs(
15+
long offset,
16+
long length,
17+
Stream content)
18+
{
19+
Offset = offset;
20+
Length = length;
21+
Content = content;
22+
}
23+
}
24+
}

sdk/storage/Azure.Storage.DataMovement/src/StorageResourceWriteToOffsetOptions.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ public class StorageResourceWriteToOffsetOptions
2424
/// </summary>
2525
public long? Position { get; set; }
2626

27+
/// <summary>
28+
/// Optional. Specifies whether this write is for the initial chunk.
29+
/// </summary>
30+
public bool Initial { get; set; }
31+
2732
/// <summary>
2833
/// Optional. Specifies the source properties to set in the destination.
2934
/// </summary>

0 commit comments

Comments
 (0)