Skip to content

Commit

Permalink
default chunk size for concurrent upload is nullable (#2162)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jinming-Hu authored Apr 28, 2021
1 parent ff10813 commit 0cc4f0a
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 4 deletions.
1 change: 1 addition & 0 deletions sdk/storage/azure-storage-blobs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Breaking Changes

- Renamed `HasMorePages()` in paged response to `HasPage()`.
- Default chunk size for concurrent upload was changed to nullable.

## 12.0.0-beta.10 (2021-04-16)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ namespace Azure { namespace Storage { namespace Blobs {
* @brief The maximum number of bytes in a single request. This value cannot be larger than
* 4000 MiB.
*/
int64_t ChunkSize = 4 * 1024 * 1024;
Azure::Nullable<int64_t> ChunkSize;

/**
* @brief The maximum number of threads that may be used in a parallel transfer.
Expand Down
38 changes: 36 additions & 2 deletions sdk/storage/azure-storage-blobs/src/block_blob_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,26 @@ namespace Azure { namespace Storage { namespace Blobs {
const UploadBlockBlobFromOptions& options,
const Azure::Core::Context& context) const
{
constexpr int64_t DefaultStageBlockSize = 4 * 1024 * 1024ULL;
constexpr int64_t MaxStageBlockSize = 4000 * 1024 * 1024ULL;
constexpr int64_t MaxBlockNumber = 50000;
constexpr int64_t BlockGrainSize = 1 * 1024 * 1024;

int64_t chunkSize = std::min(MaxStageBlockSize, options.TransferOptions.ChunkSize);
int64_t chunkSize;
if (options.TransferOptions.ChunkSize.HasValue())
{
chunkSize = options.TransferOptions.ChunkSize.Value();
}
else
{
int64_t minChunkSize = (bufferSize + MaxBlockNumber - 1) / MaxBlockNumber;
minChunkSize = (minChunkSize + BlockGrainSize - 1) / BlockGrainSize * BlockGrainSize;
chunkSize = std::max(DefaultStageBlockSize, minChunkSize);
}
if (chunkSize > MaxStageBlockSize)
{
throw Azure::Core::RequestFailedException("Block size is too big");
}

if (bufferSize <= static_cast<std::size_t>(options.TransferOptions.SingleUploadThreshold))
{
Expand Down Expand Up @@ -172,7 +189,10 @@ namespace Azure { namespace Storage { namespace Blobs {
const UploadBlockBlobFromOptions& options,
const Azure::Core::Context& context) const
{
constexpr int64_t DefaultStageBlockSize = 4 * 1024 * 1024ULL;
constexpr int64_t MaxStageBlockSize = 4000 * 1024 * 1024ULL;
constexpr int64_t MaxBlockNumber = 50000;
constexpr int64_t BlockGrainSize = 1 * 1024 * 1024;

{
Azure::Core::IO::FileBodyStream contentStream(fileName);
Expand Down Expand Up @@ -209,7 +229,21 @@ namespace Azure { namespace Storage { namespace Blobs {
}
};

int64_t chunkSize = std::min(MaxStageBlockSize, options.TransferOptions.ChunkSize);
int64_t chunkSize;
if (options.TransferOptions.ChunkSize.HasValue())
{
chunkSize = options.TransferOptions.ChunkSize.Value();
}
else
{
int64_t minChunkSize = (fileReader.GetFileSize() + MaxBlockNumber - 1) / MaxBlockNumber;
minChunkSize = (minChunkSize + BlockGrainSize - 1) / BlockGrainSize * BlockGrainSize;
chunkSize = std::max(DefaultStageBlockSize, minChunkSize);
}
if (chunkSize > MaxStageBlockSize)
{
throw Azure::Core::RequestFailedException("Block size is too big");
}

_internal::ConcurrentTransfer(
0,
Expand Down
1 change: 1 addition & 0 deletions sdk/storage/azure-storage-files-datalake/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Breaking Changes

- Renamed `HasMorePages()` in paged response to `HasPage()`.
- Default chunk size for concurrent upload was changed to nullable.

## 12.0.0-beta.10 (2021-04-16)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
* @brief The maximum number of bytes in a single request. This value cannot be larger than
* 4000 MiB.
*/
int64_t ChunkSize = 4 * 1024 * 1024;
Azure::Nullable<int64_t> ChunkSize;

/**
* @brief The maximum number of threads that may be used in a parallel transfer.
Expand Down

0 comments on commit 0cc4f0a

Please sign in to comment.