Merge pull request #63346 from ClickHouse/vdimir/fix_write_buffer_file_segment_dtor

Fix finalize WriteBufferToFileSegment and StatusFile
This commit is contained in:
vdimir 2024-05-06 10:57:19 +00:00 committed by GitHub
commit 4b1af861d8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 5 additions and 7 deletions

View File

@ -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 (...)
{

View File

@ -110,14 +110,11 @@ void WriteBufferToFileSegment::nextImpl()
std::unique_ptr<ReadBuffer> 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<ReadBufferFromFile>(file_segment->getPath());
}
WriteBufferToFileSegment::~WriteBufferToFileSegment()
{
/// To be sure that file exists before destructor of segment_holder is called
WriteBufferFromFileDecorator::finalize();
}
}

View File

@ -16,7 +16,6 @@ public:
explicit WriteBufferToFileSegment(FileSegmentsHolderPtr segment_holder);
void nextImpl() override;
~WriteBufferToFileSegment() override;
private: