#pragma once #include #if USE_AWS_S3 #include #include #include #include #include #include #include namespace Aws::S3 { class S3Client; } namespace DB { /* Perform S3 HTTP PUT request. */ class WriteBufferFromS3 : public BufferWithOwnMemory { private: String bucket; String key; std::shared_ptr client_ptr; size_t minimum_upload_part_size; std::unique_ptr temporary_buffer; size_t last_part_size; /// 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. String upload_id; std::vector part_tags; Logger * log = &Logger::get("WriteBufferFromS3"); protected: // Total size of all uploaded parts. size_t total_size = 0; public: explicit WriteBufferFromS3(std::shared_ptr client_ptr_, const String & bucket_, const String & key_, size_t minimum_upload_part_size_, size_t buffer_size_ = DBMS_DEFAULT_BUFFER_SIZE); void nextImpl() override; /// Receives response from the server after sending all data. void finalize() override; ~WriteBufferFromS3() override; private: void initiate(); void writePart(const String & data); void complete(); }; } #endif