2019-05-31 10:58:43 +00:00
|
|
|
#pragma once
|
|
|
|
|
2021-06-11 11:26:33 +00:00
|
|
|
#if !defined(ARCADIA_BUILD)
|
2019-12-06 14:37:21 +00:00
|
|
|
#include <Common/config.h>
|
2021-06-11 11:26:33 +00:00
|
|
|
#endif
|
2019-12-06 14:37:21 +00:00
|
|
|
|
|
|
|
#if USE_AWS_S3
|
|
|
|
|
2020-01-28 13:05:37 +00:00
|
|
|
# include <memory>
|
2019-09-19 10:25:31 +00:00
|
|
|
|
2020-01-28 13:05:37 +00:00
|
|
|
# include <IO/HTTPCommon.h>
|
|
|
|
# include <IO/ReadBuffer.h>
|
|
|
|
# include <aws/s3/model/GetObjectResult.h>
|
|
|
|
# include "SeekableReadBuffer.h"
|
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
|
|
|
|
{
|
2020-01-22 16:17:25 +00:00
|
|
|
/**
|
|
|
|
* Perform S3 HTTP GET request and provide response to read.
|
|
|
|
*/
|
|
|
|
class ReadBufferFromS3 : public SeekableReadBuffer
|
2019-05-31 10:58:43 +00:00
|
|
|
{
|
2019-12-03 16:23:24 +00:00
|
|
|
private:
|
2020-01-22 16:17:25 +00:00
|
|
|
std::shared_ptr<Aws::S3::S3Client> client_ptr;
|
|
|
|
String bucket;
|
|
|
|
String key;
|
2021-05-19 21:42:25 +00:00
|
|
|
UInt64 max_single_read_retries;
|
2020-01-22 16:17:25 +00:00
|
|
|
size_t buffer_size;
|
|
|
|
off_t offset = 0;
|
2019-12-03 16:23:24 +00:00
|
|
|
Aws::S3::Model::GetObjectResult read_result;
|
2020-01-22 16:17:25 +00:00
|
|
|
std::unique_ptr<ReadBuffer> impl;
|
|
|
|
|
2020-05-30 21:57:37 +00:00
|
|
|
Poco::Logger * log = &Poco::Logger::get("ReadBufferFromS3");
|
2019-12-03 16:23:24 +00:00
|
|
|
|
2019-05-31 10:58:43 +00:00
|
|
|
public:
|
2020-01-28 13:05:37 +00:00
|
|
|
explicit ReadBufferFromS3(
|
|
|
|
std::shared_ptr<Aws::S3::S3Client> client_ptr_,
|
2020-01-22 16:17:25 +00:00
|
|
|
const String & bucket_,
|
|
|
|
const String & key_,
|
2021-05-19 21:42:25 +00:00
|
|
|
UInt64 max_single_read_retries_,
|
2021-08-04 06:14:20 +00:00
|
|
|
size_t buffer_size_);
|
2019-05-31 18:14:39 +00:00
|
|
|
|
|
|
|
bool nextImpl() override;
|
2020-01-22 16:17:25 +00:00
|
|
|
|
2020-01-27 18:44:30 +00:00
|
|
|
off_t seek(off_t off, int whence) override;
|
2020-02-14 14:28:33 +00:00
|
|
|
off_t getPosition() override;
|
2020-01-27 18:44:30 +00:00
|
|
|
|
2020-01-22 16:17:25 +00:00
|
|
|
private:
|
|
|
|
std::unique_ptr<ReadBuffer> initialize();
|
2019-05-31 10:58:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
2019-12-06 14:37:21 +00:00
|
|
|
|
2019-12-09 12:36:06 +00:00
|
|
|
#endif
|