Skip to content

Commit ae73d3d

Browse files
authored
[Storage] [DataMovement] Removed unnecessary synchronization primitives (#47020)
* initial commit * changes wording of comment
1 parent f9995e7 commit ae73d3d

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,12 @@ public CommitChunkHandler(
9292
SingleReader = true,
9393
});
9494
_cancellationToken = cancellationToken;
95-
_processStageChunkEvents = Task.Run(() => NotifyOfPendingStageChunkEvents());
9695

9796
// Set bytes transferred to block size because we transferred the initial block
9897
_bytesTransferred = blockSize;
9998

99+
_processStageChunkEvents = Task.Run(() => NotifyOfPendingStageChunkEvents());
100+
100101
_blockSize = blockSize;
101102
_transferOrder = transferOrder;
102103
if (_transferOrder == DataTransferOrder.Sequential)
@@ -155,7 +156,10 @@ private async Task NotifyOfPendingStageChunkEvents()
155156
// Read one event argument at a time.
156157
StageChunkEventArgs args = await _stageChunkChannel.Reader.ReadAsync(_cancellationToken).ConfigureAwait(false);
157158

158-
Interlocked.Add(ref _bytesTransferred, args.BytesTransferred);
159+
// don't need to use Interlocked.Add() as we are reading one event at a time
160+
// and _bytesTransferred is not being read/updated from any other thread
161+
_bytesTransferred += args.BytesTransferred;
162+
159163
// Report the incremental bytes transferred
160164
_reportProgressInBytes(args.BytesTransferred);
161165

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ public DownloadChunkHandler(
107107
ClientDiagnostics clientDiagnostics,
108108
CancellationToken cancellationToken)
109109
{
110+
// Set bytes transferred to the length of bytes we got back from the initial
111+
// download request
112+
_bytesTransferred = currentTransferred;
113+
_currentRangeIndex = 0;
114+
110115
// Create channel of finished Stage Chunk Args to update the bytesTransferred
111116
// and for ending tasks like commit block.
112117
// The size of the channel should never exceed 50k (limit on blocks in a block blob).
@@ -143,10 +148,6 @@ public DownloadChunkHandler(
143148
_queueCompleteFileDownload = behaviors.QueueCompleteFileDownload
144149
?? throw Errors.ArgumentNull(nameof(behaviors.QueueCompleteFileDownload));
145150

146-
// Set bytes transferred to the length of bytes we got back from the initial
147-
// download request
148-
_bytesTransferred = currentTransferred;
149-
_currentRangeIndex = 0;
150151
_rangesCount = ranges.Count;
151152
// Set size of the list of null streams
152153
_rangesCompleted = new ConcurrentDictionary<long, string>();
@@ -338,8 +339,9 @@ private async Task InvokeFailedEvent(Exception ex)
338339
/// <param name="bytesDownloaded"></param>
339340
private void UpdateBytesAndRange(long bytesDownloaded)
340341
{
341-
Interlocked.Add(ref _bytesTransferred, bytesDownloaded);
342-
Interlocked.Increment(ref _currentRangeIndex);
342+
// don't need to use Interlocked since this is the only thread reading and updating these values
343+
_bytesTransferred += bytesDownloaded;
344+
_currentRangeIndex++;
343345
_reportProgressInBytes(bytesDownloaded);
344346
}
345347
}

0 commit comments

Comments
 (0)