Skip to content

Conversation

@GarrettBeatty
Copy link
Contributor

@GarrettBeatty GarrettBeatty commented Dec 12, 2025

Refactor multi part download manager so that instead of spreading the download across two functions DiscoverDownloadStrategyAsync + StartDownloadsAsync, it now just uses one StartDownloadsAsync. The reason i made this change was because before it was hard to trace the flow of the http concurrency when its split across two functions. This consolidates the logic into one function.

Motivation and Context

#3806

Testing

  1. updated unit tests to use new logic
  2. All integration tests pass (as expected, because this is an internal change).
  3. Dry run, in progress 3c1f4a92-57d5-44a6-bb70-2c90948712f5

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project
  • My change requires a change to the documentation
  • I have updated the documentation accordingly
  • I have read the README document
  • I have added tests to cover my changes
  • All new and existing tests passed

License

  • I confirm that this pull request can be released under the Apache 2 license

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request refactors the S3 multipart download functionality by consolidating the two-step download API (DiscoverDownloadStrategyAsync + StartDownloadsAsync) into a single unified method (StartDownloadAsync). This change eliminates resource leakage issues by managing HTTP slots and buffer capacity internally throughout the entire download lifecycle, rather than holding resources between separate method calls.

Key Changes

  • API Consolidation: Combined DiscoverDownloadStrategyAsync and StartDownloadsAsync into a single StartDownloadAsync method that atomically performs discovery, processes Part 1, and starts background downloads for remaining parts
  • Naming Update: Renamed DownloadDiscoveryResult to DownloadResult to reflect the unified operation that includes both discovery and initial download
  • Test Updates: Updated all unit tests to use the new unified API, removing tests specific to the old two-method pattern and ensuring coverage of the new behavior

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 11 comments.

Show a summary per file
File Description
sdk/src/Services/S3/Custom/Transfer/Internal/IDownloadManager.cs Updated interface to replace two methods with single StartDownloadAsync method; renamed DownloadDiscoveryResult to DownloadResult
sdk/src/Services/S3/Custom/Transfer/Internal/MultipartDownloadManager.cs Refactored public API to StartDownloadAsync and created private helper methods PerformDiscoveryAsync and PerformDownloadsAsync for internal orchestration
sdk/src/Services/S3/Custom/Transfer/Internal/IPartDataHandler.cs Updated PrepareAsync signature to accept DownloadResult instead of DownloadDiscoveryResult
sdk/src/Services/S3/Custom/Transfer/Internal/FilePartDataHandler.cs Updated PrepareAsync implementation to use DownloadResult
sdk/src/Services/S3/Custom/Transfer/Internal/BufferedPartDataHandler.cs Updated PrepareAsync implementation to use DownloadResult
sdk/src/Services/S3/Custom/Transfer/Internal/BufferedMultipartStream.cs Simplified initialization to call single StartDownloadAsync method instead of two separate calls
sdk/src/Services/S3/Custom/Transfer/Internal/_async/MultipartDownloadCommand.async.cs Updated to use unified StartDownloadAsync method with simplified logging
sdk/test/Services/S3/UnitTests/Custom/MultipartDownloadManagerTests.cs Comprehensive test updates to use new API; removed obsolete tests; added inappropriate Microsoft.VisualBasic import
sdk/test/Services/S3/UnitTests/Custom/FilePartDataHandlerTests.cs Updated all test instances to use DownloadResult with minor spacing issues
sdk/test/Services/S3/UnitTests/Custom/FilePartDataHandlerConcurrencyTests.cs Updated to use DownloadResult
sdk/test/Services/S3/UnitTests/Custom/BufferedMultipartStreamTests.cs Updated tests to mock unified API; reorganized test with incorrect region placement

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated no new comments.

}

[TestMethod]
public async Task StartDownloadsAsync_SinglePart_DoesNotThrowOnCancellation()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not applicable anymore (it should throw cancellation), since everything happens in start download now

@GarrettBeatty GarrettBeatty force-pushed the gcbeatty/refactor2 branch 2 times, most recently from 4a70062 to b8d9f14 Compare December 12, 2025 20:34
#region InitializeAsync Tests - Single Part

[TestMethod]
public async Task InitializeAsync_SinglePart_UsesSinglePartHandler()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this isnt deleted, the order just got switched around by accident



[TestMethod]
public async Task InitializeAsync_SinglePart_CallsStartDownloads()
Copy link
Contributor Author

@GarrettBeatty GarrettBeatty Dec 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is still here just moved around

#region InitializeAsync Tests - Multipart

[TestMethod]
public async Task InitializeAsync_Multipart_UsesMultipartHandler()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this wasnt deleted it was just moved around

}

[TestMethod]
public async Task Discovery_HttpRequestAfterCapacityFails_ReleasesHttpSemaphore()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test is still here just moved around

update tests

add back tests

copilot comments

add more tests

add back test

add back test

move tests

add test back
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant