Skip to content

Commit 42e9956

Browse files
committed
upload/download changes
1 parent 933ad44 commit 42e9956

11 files changed

Lines changed: 260 additions & 102 deletions

File tree

src/aws-cpp-sdk-s3-transfer/include/aws/s3-transfer/DownloadDataReceiver.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ namespace Transfer {
1212

1313
/**
1414
* Callback interface for zero-copy downloads. The transfer manager delivers each part of the
15-
* object to OnDataReceived as it arrives, in object order. Keep a copy of the buffer to retain
16-
* the bytes past this call.
15+
* object to OnDataReceived as it arrives, in object order. The buffer is move-only; move it out
16+
* (e.g. auto held = std::move(buffer)) to retain the bytes past this call.
1717
*/
1818
class AWS_S3_TRANSFER_API DownloadDataReceiver {
1919
public:

src/aws-cpp-sdk-s3-transfer/include/aws/s3-transfer/S3DownloadBuffer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ class AWS_S3_TRANSFER_API S3DownloadBuffer final {
2424
explicit S3DownloadBuffer(std::shared_ptr<Aws::Crt::S3::S3BufferTicket> ticket,
2525
Aws::Crt::ByteCursor bytes, uint64_t rangeStart) noexcept;
2626

27-
S3DownloadBuffer(const S3DownloadBuffer&) = default;
28-
S3DownloadBuffer& operator=(const S3DownloadBuffer&) = default;
27+
S3DownloadBuffer(const S3DownloadBuffer&) = delete;
28+
S3DownloadBuffer& operator=(const S3DownloadBuffer&) = delete;
2929
S3DownloadBuffer(S3DownloadBuffer&& other) noexcept;
3030
S3DownloadBuffer& operator=(S3DownloadBuffer&& other) noexcept;
3131
~S3DownloadBuffer() = default;

src/aws-cpp-sdk-s3-transfer/include/aws/s3-transfer/S3TransferManager.h

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
#include <aws/s3-transfer/UploadHandle.h>
1111
#include <aws/s3-transfer/DownloadHandle.h>
1212
#include <aws/core/auth/AWSCredentialsProvider.h>
13-
#include <aws/core/utils/memory/AWSMemory.h>
13+
#include <aws/core/client/AWSError.h>
1414
#include <aws/s3/S3EndpointProvider.h>
15+
#include <aws/s3/S3Errors.h>
1516
#include <memory>
1617

1718
namespace Aws {
@@ -22,7 +23,10 @@ class S3TransferManagerImpl;
2223

2324
/**
2425
* Customers construct an instance directly. The manager owns the underlying CRT client; it is
25-
* neither copyable nor movable.
26+
* neither copyable nor movable. If construction cannot produce a usable manager (e.g. the CRT
27+
* S3 client fails to build), the instance enters an error state: IsInitialized() returns false
28+
* and Upload()/Download() fail immediately via the returned handle with the specific init
29+
* error. Customers can check IsInitialized() up-front, or rely on the per-call failure path.
2630
*/
2731
class AWS_S3_TRANSFER_API S3TransferManager final {
2832
public:
@@ -31,20 +35,23 @@ class AWS_S3_TRANSFER_API S3TransferManager final {
3135
* config. If config is not specified, it will be initialized to default values.
3236
*/
3337
S3TransferManager(const S3TransferManagerConfiguration& config = S3TransferManagerConfiguration(),
34-
std::shared_ptr<Aws::S3::Endpoint::S3EndpointProviderBase> endpointProvider = nullptr);
38+
std::shared_ptr<Aws::S3::Endpoint::S3EndpointProviderBase> endpointProvider =
39+
Aws::MakeShared<Aws::S3::Endpoint::S3EndpointProvider>("S3TransferManager"));
3540

3641
/**
3742
* Initializes the transfer manager with the supplied static credentials and an optional config.
3843
*/
3944
S3TransferManager(const Aws::Auth::AWSCredentials& credentials,
40-
std::shared_ptr<Aws::S3::Endpoint::S3EndpointProviderBase> endpointProvider = nullptr,
45+
std::shared_ptr<Aws::S3::Endpoint::S3EndpointProviderBase> endpointProvider =
46+
Aws::MakeShared<Aws::S3::Endpoint::S3EndpointProvider>("S3TransferManager"),
4147
const S3TransferManagerConfiguration& config = S3TransferManagerConfiguration());
4248

4349
/**
4450
* Initializes the transfer manager with the supplied credentials provider and an optional config.
4551
*/
4652
S3TransferManager(const std::shared_ptr<Aws::Auth::AWSCredentialsProvider>& credentialsProvider,
47-
std::shared_ptr<Aws::S3::Endpoint::S3EndpointProviderBase> endpointProvider = nullptr,
53+
std::shared_ptr<Aws::S3::Endpoint::S3EndpointProviderBase> endpointProvider =
54+
Aws::MakeShared<Aws::S3::Endpoint::S3EndpointProvider>("S3TransferManager"),
4855
const S3TransferManagerConfiguration& config = S3TransferManagerConfiguration());
4956

5057
~S3TransferManager();
@@ -54,6 +61,18 @@ class AWS_S3_TRANSFER_API S3TransferManager final {
5461
S3TransferManager(S3TransferManager&&) noexcept = delete;
5562
S3TransferManager& operator=(S3TransferManager&&) noexcept = delete;
5663

64+
/**
65+
* True if construction succeeded. If false, Upload()/Download() will fail immediately via
66+
* the returned handle with the error reported by GetInitializationError().
67+
*/
68+
bool IsInitialized() const;
69+
70+
/**
71+
* The specific error captured during construction. Only meaningful when IsInitialized() is
72+
* false; on a successfully-initialized manager the returned error is default-constructed.
73+
*/
74+
const Aws::Client::AWSError<Aws::S3::S3Errors>& GetInitializationError() const;
75+
5776
/**
5877
* Begin uploading the object described by request. Returns immediately with a handle that can be
5978
* used to wait for completion or to cancel the in-flight transfer.
@@ -73,6 +92,3 @@ class AWS_S3_TRANSFER_API S3TransferManager final {
7392
} // namespace Transfer
7493
} // namespace S3
7594
} // namespace Aws
76-
77-
78-

src/aws-cpp-sdk-s3-transfer/include/aws/s3-transfer/S3TransferManagerConfiguration.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55

66
#pragma once
77

8-
#include <aws/core/client/GenericClientConfiguration.h>
98
#include <aws/s3-transfer/S3Transfer_EXPORTS.h>
9+
#include <aws/s3/S3ClientConfiguration.h>
1010
#include <aws/crt/Optional.h>
1111
#include <aws/crt/io/TlsOptions.h>
12+
#include <aws/crt/s3/S3.h>
1213
#include <cstdint>
14+
#include <memory>
1315

1416
namespace Aws {
1517
namespace S3 {
@@ -18,8 +20,8 @@ namespace Transfer {
1820
constexpr uint64_t DEFAULT_PART_SIZE_BYTES = 8ULL * 1024 * 1024;
1921
constexpr uint64_t DEFAULT_MULTIPART_UPLOAD_THRESHOLD_BYTES = 16ULL * 1024 * 1024;
2022

21-
struct AWS_S3_TRANSFER_API S3TransferManagerConfiguration final : public Aws::Client::GenericClientConfiguration {
22-
using BaseClientConfigClass = Aws::Client::GenericClientConfiguration;
23+
struct AWS_S3_TRANSFER_API S3TransferManagerConfiguration final : public Aws::S3::S3ClientConfiguration {
24+
using BaseClientConfigClass = Aws::S3::S3ClientConfiguration;
2325

2426
explicit S3TransferManagerConfiguration(const Aws::Client::ClientConfigurationInitValues& configuration = {});
2527
explicit S3TransferManagerConfiguration(const char* profileName, bool shouldDisableIMDS = false);
@@ -33,6 +35,8 @@ struct AWS_S3_TRANSFER_API S3TransferManagerConfiguration final : public Aws::Cl
3335
double throughputTargetGbps = 0.0;
3436
Aws::Crt::Optional<Aws::Crt::Io::TlsConnectionOptions> tlsConnectionOptions;
3537

38+
std::shared_ptr<Aws::Crt::S3::S3Client> crtClient;
39+
3640
private:
3741
void LoadS3TransferManagerSpecificConfig(const Aws::String& profileName);
3842
};

src/aws-cpp-sdk-s3-transfer/include/aws/s3-transfer/internal/S3TransferManagerImpl.h

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,17 @@
88
#include <aws/s3-transfer/S3Transfer_EXPORTS.h>
99
#include <aws/s3-transfer/S3TransferManagerConfiguration.h>
1010
#include <aws/core/auth/AWSCredentialsProvider.h>
11+
#include <aws/core/auth/AWSCredentialsProviderChain.h>
12+
#include <aws/core/client/AWSError.h>
13+
#include <aws/core/client/UserAgent.h>
1114
#include <aws/core/utils/memory/AWSMemory.h>
1215
#include <aws/core/utils/memory/stl/AWSString.h>
1316
#include <aws/s3/S3EndpointProvider.h>
17+
#include <aws/s3/S3Errors.h>
1418
#include <aws/crt/s3/S3.h>
1519
#include <aws/crt/auth/Credentials.h>
1620
#include <aws/core/utils/threading/Executor.h>
21+
#include <atomic>
1722
#include <cstdint>
1823
#include <memory>
1924

@@ -27,11 +32,12 @@ constexpr size_t DEFAULT_EXECUTOR_POOL_SIZE = 8;
2732
class AWS_CORE_LOCAL S3TransferManagerImpl final {
2833
public:
2934
// Sole real constructor; the public overloads adapt their credentials shape into the
30-
// AWSCredentialsProvider taken here. A null endpointProvider means "use the default
31-
// S3EndpointProvider", matching generated-client behavior.
32-
S3TransferManagerImpl(const std::shared_ptr<Aws::Auth::AWSCredentialsProvider>& credentialsProvider,
33-
const std::shared_ptr<Aws::S3::Endpoint::S3EndpointProviderBase>& endpointProvider,
34-
const S3TransferManagerConfiguration& config);
35+
// AWSCredentialsProvider taken here.
36+
S3TransferManagerImpl(const S3TransferManagerConfiguration& config,
37+
const std::shared_ptr<Aws::Auth::AWSCredentialsProvider>& credentialsProvider =
38+
Aws::MakeShared<Aws::Auth::DefaultAWSCredentialsProviderChain>("S3TransferManagerImpl"),
39+
const std::shared_ptr<Aws::S3::Endpoint::S3EndpointProviderBase>& endpointProvider =
40+
Aws::MakeShared<Aws::S3::Endpoint::S3EndpointProvider>("S3TransferManagerImpl"));
3541
~S3TransferManagerImpl();
3642

3743
S3TransferManagerImpl(const S3TransferManagerImpl&) = delete;
@@ -41,19 +47,29 @@ class AWS_CORE_LOCAL S3TransferManagerImpl final {
4147

4248
Aws::Crt::S3::S3Client& GetCrtClient() const { return *m_crtClient; }
4349
Aws::S3::Endpoint::S3EndpointProviderBase& GetEndpointProvider() const { return *m_endpointProvider; }
44-
const Aws::String& GetRegion() const { return m_region; }
50+
const S3TransferManagerConfiguration& GetConfig() const { return m_config; }
4551
const std::shared_ptr<Aws::Crt::Auth::ICredentialsProvider>& GetCredentialsProvider() const {
4652
return m_credentialsProvider;
4753
}
48-
bool IsValid() const { return m_crtClient != nullptr && static_cast<bool>(*m_crtClient); }
54+
bool IsCustomerSuppliedCrtClient() const { return m_customerSuppliedCrtClient; }
55+
// Ctor sets to false on any construction failure and stashes the specific reason in
56+
// m_initError. S3TransferManager::Create() inspects this to gate object handoff — a customer
57+
// never receives a borked S3TransferManager.
58+
bool IsInitialized() const { return m_isInitialized.load(); }
59+
const Aws::Client::AWSError<Aws::S3::S3Errors>& GetInitializationError() const { return m_initError; }
4960
Aws::Utils::Threading::Executor& GetExecutor() const { return *m_executor; }
61+
const Aws::String& GetUserAgentString() const { return m_userAgent; }
5062

5163
private:
52-
Aws::String m_region;
64+
S3TransferManagerConfiguration m_config;
5365
std::shared_ptr<Aws::Crt::Auth::ICredentialsProvider> m_credentialsProvider;
5466
std::shared_ptr<Aws::S3::Endpoint::S3EndpointProviderBase> m_endpointProvider;
55-
Aws::UniquePtr<Aws::Crt::S3::S3Client> m_crtClient;
67+
std::shared_ptr<Aws::Crt::S3::S3Client> m_crtClient;
5668
std::shared_ptr<Aws::Utils::Threading::Executor> m_executor;
69+
std::atomic<bool> m_isInitialized{true};
70+
Aws::Client::AWSError<Aws::S3::S3Errors> m_initError;
71+
bool m_customerSuppliedCrtClient = false;
72+
Aws::String m_userAgent;
5773
};
5874

5975
} // namespace Transfer

src/aws-cpp-sdk-s3-transfer/include/aws/s3-transfer/internal/TransferState.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ struct AWS_CORE_LOCAL TransferStateBase {
6161
}
6262

6363
private:
64-
mutable std::mutex m_metaRequestLock;
64+
std::mutex m_metaRequestLock;
6565
std::shared_ptr<Aws::Crt::S3::S3MetaRequest> m_metaRequest;
6666
};
6767

src/aws-cpp-sdk-s3-transfer/source/s3-transfer/S3TransferManager.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,29 @@ S3TransferManager::~S3TransferManager() = default;
1919
S3TransferManager::S3TransferManager(const S3TransferManagerConfiguration& config,
2020
std::shared_ptr<Aws::S3::Endpoint::S3EndpointProviderBase> endpointProvider)
2121
: m_impl(Aws::MakeUnique<S3TransferManagerImpl>(
22-
S3_TRANSFER_MANAGER_ALLOCATION_TAG,
22+
S3_TRANSFER_MANAGER_ALLOCATION_TAG, config,
2323
Aws::MakeShared<Aws::Auth::DefaultAWSCredentialsProviderChain>(S3_TRANSFER_MANAGER_ALLOCATION_TAG),
24-
endpointProvider, config)) {}
24+
endpointProvider)) {}
2525

2626
S3TransferManager::S3TransferManager(const Aws::Auth::AWSCredentials& credentials,
2727
std::shared_ptr<Aws::S3::Endpoint::S3EndpointProviderBase> endpointProvider,
2828
const S3TransferManagerConfiguration& config)
2929
: m_impl(Aws::MakeUnique<S3TransferManagerImpl>(
30-
S3_TRANSFER_MANAGER_ALLOCATION_TAG,
30+
S3_TRANSFER_MANAGER_ALLOCATION_TAG, config,
3131
Aws::MakeShared<Aws::Auth::SimpleAWSCredentialsProvider>(S3_TRANSFER_MANAGER_ALLOCATION_TAG, credentials),
32-
endpointProvider, config)) {}
32+
endpointProvider)) {}
3333

3434
S3TransferManager::S3TransferManager(const std::shared_ptr<Aws::Auth::AWSCredentialsProvider>& credentialsProvider,
3535
std::shared_ptr<Aws::S3::Endpoint::S3EndpointProviderBase> endpointProvider,
3636
const S3TransferManagerConfiguration& config)
37-
: m_impl(Aws::MakeUnique<S3TransferManagerImpl>(S3_TRANSFER_MANAGER_ALLOCATION_TAG, credentialsProvider,
38-
endpointProvider, config)) {}
37+
: m_impl(Aws::MakeUnique<S3TransferManagerImpl>(
38+
S3_TRANSFER_MANAGER_ALLOCATION_TAG, config, credentialsProvider, endpointProvider)) {}
39+
40+
bool S3TransferManager::IsInitialized() const { return m_impl->IsInitialized(); }
41+
42+
const Aws::Client::AWSError<Aws::S3::S3Errors>& S3TransferManager::GetInitializationError() const {
43+
return m_impl->GetInitializationError();
44+
}
3945

4046
UploadHandle S3TransferManager::Upload(const UploadRequest& request) {
4147
return Internal::CrtOperations::DispatchUpload(*m_impl, request);

0 commit comments

Comments
 (0)