From 98e3b1656093d7121f9a47be8e6d18d579dd1227 Mon Sep 17 00:00:00 2001 From: alesapin Date: Mon, 2 May 2022 22:14:18 +0200 Subject: [PATCH] Terminate if S3 buffer is not finalized --- src/IO/WriteBufferFromS3.cpp | 10 ++++++++++ src/IO/WriteBufferFromS3.h | 3 ++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/IO/WriteBufferFromS3.cpp b/src/IO/WriteBufferFromS3.cpp index 52a958ec968..1f86c3c60b3 100644 --- a/src/IO/WriteBufferFromS3.cpp +++ b/src/IO/WriteBufferFromS3.cpp @@ -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() diff --git a/src/IO/WriteBufferFromS3.h b/src/IO/WriteBufferFromS3.h index 19faf0b1488..156b6df43ec 100644 --- a/src/IO/WriteBufferFromS3.h +++ b/src/IO/WriteBufferFromS3.h @@ -47,7 +47,7 @@ class WriteBufferFromFile; class WriteBufferFromS3 final : public BufferWithOwnMemory { public: - explicit WriteBufferFromS3( + WriteBufferFromS3( std::shared_ptr client_ptr_, const String & bucket_, const String & key_, @@ -105,6 +105,7 @@ private: std::vector part_tags; bool is_prefinalized = false; + std::atomic is_finalized = false; /// Following fields are for background uploads in thread pool (if specified). /// We use std::function to avoid dependency of Interpreters