ClickHouse/dbms/IO/WriteBufferFromS3.h

65 lines
1.4 KiB
C++
Raw Normal View History

2019-05-31 10:58:43 +00:00
#pragma once
2019-12-06 14:37:21 +00:00
#include <Common/config.h>
#if USE_AWS_S3
2020-01-28 13:05:37 +00:00
# include <memory>
# include <vector>
# include <Core/Types.h>
# include <IO/BufferWithOwnMemory.h>
# include <IO/HTTPCommon.h>
# include <IO/WriteBuffer.h>
# include <IO/WriteBufferFromString.h>
2019-05-31 10:58:43 +00:00
2019-12-11 14:21:48 +00:00
namespace Aws::S3
{
2020-01-28 13:05:37 +00:00
class S3Client;
2019-12-11 14:21:48 +00:00
}
2019-05-31 10:58:43 +00:00
namespace DB
{
2019-06-01 21:18:20 +00:00
/* Perform S3 HTTP PUT request.
2019-05-31 10:58:43 +00:00
*/
2019-06-17 00:06:14 +00:00
class WriteBufferFromS3 : public BufferWithOwnMemory<WriteBuffer>
2019-05-31 10:58:43 +00:00
{
private:
2019-12-03 16:23:24 +00:00
String bucket;
String key;
std::shared_ptr<Aws::S3::S3Client> client_ptr;
2019-06-21 05:24:01 +00:00
size_t minimum_upload_part_size;
std::unique_ptr<WriteBufferFromOwnString> temporary_buffer;
2019-06-17 00:42:47 +00:00
size_t last_part_size;
2019-09-22 22:06:22 +00:00
/// Upload in S3 is made in parts.
/// We initiate upload, then upload each part and get ETag as a response, and then finish upload with listing all our parts.
2019-06-17 07:16:43 +00:00
String upload_id;
2019-06-17 00:42:47 +00:00
std::vector<String> part_tags;
2019-05-31 10:58:43 +00:00
2019-12-03 16:23:24 +00:00
Logger * log = &Logger::get("WriteBufferFromS3");
2019-05-31 10:58:43 +00:00
public:
2020-01-28 13:05:37 +00:00
explicit WriteBufferFromS3(
std::shared_ptr<Aws::S3::S3Client> client_ptr_,
const String & bucket_,
const String & key_,
size_t minimum_upload_part_size_,
size_t buffer_size_ = DBMS_DEFAULT_BUFFER_SIZE);
2019-05-31 10:58:43 +00:00
2019-06-17 00:06:14 +00:00
void nextImpl() override;
2019-05-31 10:58:43 +00:00
/// Receives response from the server after sending all data.
2019-11-19 17:11:13 +00:00
void finalize() override;
2019-06-17 00:06:14 +00:00
2019-06-17 17:32:57 +00:00
~WriteBufferFromS3() override;
2019-06-17 00:42:47 +00:00
private:
void initiate();
void writePart(const String & data);
void complete();
2019-05-31 10:58:43 +00:00
};
}
2019-12-06 14:37:21 +00:00
#endif