Merge pull request #20465 from azat/write-abnormal-server-termination-fixes

Fix abnormal server terminations due to write failures
This commit is contained in:
alexey-milovidov 2021-02-15 00:05:48 +03:00 committed by GitHub
commit bde4da0ff0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 14 additions and 2 deletions

View File

@ -562,6 +562,7 @@ void debugIncreaseOOMScore()
{
DB::WriteBufferFromFile buf("/proc/self/oom_score_adj");
buf.write(new_score.c_str(), new_score.size());
buf.close();
}
catch (const Poco::Exception & e)
{

View File

@ -217,6 +217,7 @@ namespace
/// Write the file.
WriteBufferFromFile out{tmp_file_path.string()};
out.write(file_contents.data(), file_contents.size());
out.close();
/// Rename.
std::filesystem::rename(tmp_file_path, file_path);
@ -274,6 +275,7 @@ namespace
writeStringBinary(name, out);
writeUUIDText(id, out);
}
out.close();
}

View File

@ -50,6 +50,7 @@ struct Test
{
DB::WriteBufferFromFile wb(filename);
wb.write(reinterpret_cast<const char *>(&store), sizeof(store));
wb.close();
}
{

View File

@ -95,8 +95,15 @@ public:
++pos;
}
virtual void sync() {}
virtual void finalize() {}
virtual void sync()
{
next();
}
virtual void finalize()
{
next();
}
private:
/** Write the data in the buffer (from the beginning of the buffer to the current position).

View File

@ -97,6 +97,7 @@ void run(String part_path, String date_column, String dest_path)
Poco::File(new_tmp_part_path_str + "checksums.txt").setWriteable();
WriteBufferFromFile checksums_out(new_tmp_part_path_str + "checksums.txt", 4096);
checksums.write(checksums_out);
checksums.close();
Poco::File(new_tmp_part_path).renameTo(new_part_path.toString());
}