Terminate if S3 buffer is not finalized

This commit is contained in:
alesapin 2022-05-02 22:14:18 +02:00
parent 9be17ef50c
commit 98e3b16560
2 changed files with 12 additions and 1 deletions

View File

@ -152,6 +152,13 @@ void WriteBufferFromS3::allocateBuffer()
WriteBufferFromS3::~WriteBufferFromS3()
{
#ifndef NDEBUG
if (!is_finalized.load(std::memory_order_relaxed))
{
LOG_ERROR(log, "WriteBufferFromS3 is not finalized in destructor. It's a bug");
std::terminate();
}
#else
try
{
finalize();
@ -160,6 +167,7 @@ WriteBufferFromS3::~WriteBufferFromS3()
{
tryLogCurrentException(__PRETTY_FUNCTION__);
}
#endif
}
bool WriteBufferFromS3::cacheEnabled() const
@ -193,6 +201,8 @@ void WriteBufferFromS3::finalizeImpl()
if (!multipart_upload_id.empty())
completeMultipartUpload();
is_finalized.store(true, std::memory_order_relaxed);
}
void WriteBufferFromS3::createMultipartUpload()

View File

@ -47,7 +47,7 @@ class WriteBufferFromFile;
class WriteBufferFromS3 final : public BufferWithOwnMemory<WriteBuffer>
{
public:
explicit WriteBufferFromS3(
WriteBufferFromS3(
std::shared_ptr<Aws::S3::S3Client> client_ptr_,
const String & bucket_,
const String & key_,
@ -105,6 +105,7 @@ private:
std::vector<String> part_tags;
bool is_prefinalized = false;
std::atomic<bool> is_finalized = false;
/// Following fields are for background uploads in thread pool (if specified).
/// We use std::function to avoid dependency of Interpreters