-
Notifications
You must be signed in to change notification settings - Fork 1.1k
checksums for upload path #3625
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
base: main
Are you sure you want to change the base?
Changes from 3 commits
0922fab
7fec292
8677b55
90ae39b
78cc8c7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,9 @@ | |
| #include <aws/core/platform/FileSystem.h> | ||
| #include <aws/core/utils/HashingUtils.h> | ||
| #include <aws/core/utils/logging/LogMacros.h> | ||
| #include <aws/core/utils/crypto/Hash.h> | ||
| #include <aws/core/utils/crypto/CRC32.h> | ||
| #include <aws/core/utils/crypto/CRC64.h> | ||
| #include <aws/core/utils/memory/AWSMemory.h> | ||
| #include <aws/core/utils/memory/stl/AWSStreamFwd.h> | ||
| #include <aws/core/utils/memory/stl/AWSStringStream.h> | ||
|
|
@@ -399,6 +402,15 @@ namespace Aws | |
| bool isRetry = !handle->GetMultiPartId().empty(); | ||
| uint64_t sentBytes = 0; | ||
|
|
||
| std::shared_ptr<Aws::Utils::Crypto::Hash> fullObjectHashCalculator; | ||
| if (handle->GetChecksum().empty() && !isRetry) { | ||
| if (m_transferConfig.checksumAlgorithm == S3::Model::ChecksumAlgorithm::CRC32C) { | ||
|
||
| fullObjectHashCalculator = Aws::MakeShared<Aws::Utils::Crypto::CRC32C>("TransferManager"); | ||
| } else{ | ||
| fullObjectHashCalculator = Aws::MakeShared<Aws::Utils::Crypto::CRC64>("TransferManager"); | ||
| } | ||
| } | ||
|
|
||
| if (!isRetry) { | ||
| Aws::S3::Model::CreateMultipartUploadRequest createMultipartRequest = m_transferConfig.createMultipartUploadTemplate; | ||
| createMultipartRequest.SetChecksumAlgorithm(m_transferConfig.checksumAlgorithm); | ||
|
|
@@ -466,6 +478,10 @@ namespace Aws | |
| streamToPut->seekg((partsIter->first - 1) * m_transferConfig.bufferSize); | ||
| streamToPut->read(reinterpret_cast<char*>(buffer), lengthToWrite); | ||
|
|
||
| if (fullObjectHashCalculator) { | ||
| fullObjectHashCalculator->Update(buffer, static_cast<size_t>(lengthToWrite)); | ||
| } | ||
|
|
||
| auto streamBuf = Aws::New<Aws::Utils::Stream::PreallocatedStreamBuf>(CLASS_TAG, buffer, static_cast<size_t>(lengthToWrite)); | ||
| auto preallocatedStreamReader = Aws::MakeShared<Aws::IOStream>(CLASS_TAG, streamBuf); | ||
|
|
||
|
|
@@ -525,6 +541,13 @@ namespace Aws | |
| handle->UpdateStatus(DetermineIfFailedOrCanceled(*handle)); | ||
| TriggerTransferStatusUpdatedCallback(handle); | ||
| } | ||
| else if (fullObjectHashCalculator && handle->GetChecksum().empty()) { | ||
| // Finalize checksum calculation and set on handle | ||
| auto hashResult = fullObjectHashCalculator->GetHash(); | ||
| if (hashResult.IsSuccess()) { | ||
| handle->SetChecksum(Aws::Utils::HashingUtils::Base64Encode(hashResult.GetResult())); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| void TransferManager::DoSinglePartUpload(const std::shared_ptr<TransferHandle>& handle) | ||
|
|
@@ -1508,4 +1531,4 @@ namespace Aws | |
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ | |
| #include <aws/s3/S3Client.h> | ||
| #include <aws/s3/model/DeleteObjectsRequest.h> | ||
| #include <aws/s3/model/AbortMultipartUploadRequest.h> | ||
| #include <aws/s3/model/CompleteMultipartUploadRequest.h> | ||
| #include <aws/s3/model/ListObjectsRequest.h> | ||
| #include <aws/s3/model/ListMultipartUploadsRequest.h> | ||
| #include <aws/s3/model/GetObjectRequest.h> | ||
|
|
@@ -160,6 +161,21 @@ class MockS3Client : public S3Client | |
| return S3Client::ListObjectsV2(request); | ||
| } | ||
|
|
||
| // Override to verify checksum is being sent | ||
| Model::CompleteMultipartUploadOutcome CompleteMultipartUpload(const Model::CompleteMultipartUploadRequest& request) const override | ||
| { | ||
| std::cout << "=== CompleteMultipartUpload Request ===" << std::endl; | ||
|
||
| std::cout << "Available ChecksumAlgorithm enum values:" << std::endl; | ||
| std::cout << "ChecksumType: " << (int)request.GetChecksumType() << std::endl; | ||
| std::cout << "ChecksumCRC32: " << request.GetChecksumCRC32() << std::endl; | ||
| std::cout << "ChecksumCRC32C: " << request.GetChecksumCRC32C() << std::endl; | ||
| std::cout << "ChecksumCRC64NVME: " << request.GetChecksumCRC64NVME() << std::endl; | ||
| std::cout << "ChecksumSHA1: " << request.GetChecksumSHA1() << std::endl; | ||
| std::cout << "ChecksumSHA256: " << request.GetChecksumSHA256() << std::endl; | ||
| std::cout << "=======================================" << std::endl; | ||
| return S3Client::CompleteMultipartUpload(request); | ||
| } | ||
|
|
||
| // m_executor in Base class is private, we need our own one. | ||
| std::shared_ptr<Aws::Utils::Threading::Executor> executor; | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: you can use a immdiately invoked function expression to avoid branching assignment like this i.e.
you may have to add a few more parameters, but thats the idea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated the initiation if fullObjectHashCalculator