diff --git a/src/Common/StatusFile.cpp b/src/Common/StatusFile.cpp index 56eb1d4d0cb..ba7595ae6d7 100644 --- a/src/Common/StatusFile.cpp +++ b/src/Common/StatusFile.cpp @@ -86,6 +86,8 @@ StatusFile::StatusFile(std::string path_, FillFunction fill_) /// Write information about current server instance to the file. WriteBufferFromFileDescriptor out(fd, 1024); fill(out); + /// Finalize here to avoid throwing exceptions in destructor. + out.finalize(); } catch (...) { diff --git a/src/Interpreters/Cache/WriteBufferToFileSegment.cpp b/src/Interpreters/Cache/WriteBufferToFileSegment.cpp index 2ac38aeeca7..a593ebfdab2 100644 --- a/src/Interpreters/Cache/WriteBufferToFileSegment.cpp +++ b/src/Interpreters/Cache/WriteBufferToFileSegment.cpp @@ -110,14 +110,11 @@ void WriteBufferToFileSegment::nextImpl() std::unique_ptr WriteBufferToFileSegment::getReadBufferImpl() { + /** Finalize here and we don't need to finalize in the destructor, + * because in case destructor called without `getReadBufferImpl` called, data won't be read. + */ finalize(); return std::make_unique(file_segment->getPath()); } -WriteBufferToFileSegment::~WriteBufferToFileSegment() -{ - /// To be sure that file exists before destructor of segment_holder is called - WriteBufferFromFileDecorator::finalize(); -} - } diff --git a/src/Interpreters/Cache/WriteBufferToFileSegment.h b/src/Interpreters/Cache/WriteBufferToFileSegment.h index 822488ceb48..c4b0491f8c0 100644 --- a/src/Interpreters/Cache/WriteBufferToFileSegment.h +++ b/src/Interpreters/Cache/WriteBufferToFileSegment.h @@ -16,7 +16,6 @@ public: explicit WriteBufferToFileSegment(FileSegmentsHolderPtr segment_holder); void nextImpl() override; - ~WriteBufferToFileSegment() override; private: