Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Storage] [DataMovement] Removed unnecessary synchronization primitives #47020

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,12 @@ public CommitChunkHandler(
SingleReader = true,
});
_cancellationToken = cancellationToken;
_processStageChunkEvents = Task.Run(() => NotifyOfPendingStageChunkEvents());

// Set bytes transferred to block size because we transferred the initial block
_bytesTransferred = blockSize;
nickliu-msft marked this conversation as resolved.
Show resolved Hide resolved

_processStageChunkEvents = Task.Run(() => NotifyOfPendingStageChunkEvents());

_blockSize = blockSize;
_transferOrder = transferOrder;
if (_transferOrder == DataTransferOrder.Sequential)
Expand Down Expand Up @@ -155,7 +156,10 @@ private async Task NotifyOfPendingStageChunkEvents()
// Read one event argument at a time.
StageChunkEventArgs args = await _stageChunkChannel.Reader.ReadAsync(_cancellationToken).ConfigureAwait(false);

Interlocked.Add(ref _bytesTransferred, args.BytesTransferred);
// don't need to use Interlocked.Add() as we are reading one event at a time
// and _bytesTransferred is not being read/updated from any other thread
_bytesTransferred += args.BytesTransferred;

// Report the incremental bytes transferred
_reportProgressInBytes(args.BytesTransferred);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ public DownloadChunkHandler(
ClientDiagnostics clientDiagnostics,
CancellationToken cancellationToken)
{
// Set bytes transferred to the length of bytes we got back from the initial
// download request
_bytesTransferred = currentTransferred;
_currentRangeIndex = 0;

// Create channel of finished Stage Chunk Args to update the bytesTransferred
// and for ending tasks like commit block.
// The size of the channel should never exceed 50k (limit on blocks in a block blob).
Expand Down Expand Up @@ -143,10 +148,6 @@ public DownloadChunkHandler(
_queueCompleteFileDownload = behaviors.QueueCompleteFileDownload
?? throw Errors.ArgumentNull(nameof(behaviors.QueueCompleteFileDownload));

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