From fa329808e57315c0ab0692220bdc69d185231753 Mon Sep 17 00:00:00 2001 From: Azat Khuzhin Date: Sat, 13 Feb 2021 13:12:55 +0300 Subject: [PATCH 1/2] Call next() from sync()/finalize() in WriteBuffer --- src/IO/WriteBuffer.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/IO/WriteBuffer.h b/src/IO/WriteBuffer.h index d425f813d7b..24529fad8c0 100644 --- a/src/IO/WriteBuffer.h +++ b/src/IO/WriteBuffer.h @@ -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). From 06e8065ee65fabfed101da03eef993913f096450 Mon Sep 17 00:00:00 2001 From: Azat Khuzhin Date: Sat, 13 Feb 2021 13:15:36 +0300 Subject: [PATCH 2/2] Add missing sync of underlying files --- base/daemon/BaseDaemon.cpp | 1 + src/Access/DiskAccessStorage.cpp | 2 ++ src/Common/tests/compact_array.cpp | 1 + utils/convert-month-partitioned-parts/main.cpp | 1 + 4 files changed, 5 insertions(+) diff --git a/base/daemon/BaseDaemon.cpp b/base/daemon/BaseDaemon.cpp index 491ffe6a775..d96af1297e6 100644 --- a/base/daemon/BaseDaemon.cpp +++ b/base/daemon/BaseDaemon.cpp @@ -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) { diff --git a/src/Access/DiskAccessStorage.cpp b/src/Access/DiskAccessStorage.cpp index 426c27ea799..80594f66dfc 100644 --- a/src/Access/DiskAccessStorage.cpp +++ b/src/Access/DiskAccessStorage.cpp @@ -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(); } diff --git a/src/Common/tests/compact_array.cpp b/src/Common/tests/compact_array.cpp index 91fb59d543f..a63859ac712 100644 --- a/src/Common/tests/compact_array.cpp +++ b/src/Common/tests/compact_array.cpp @@ -50,6 +50,7 @@ struct Test { DB::WriteBufferFromFile wb(filename); wb.write(reinterpret_cast(&store), sizeof(store)); + wb.close(); } { diff --git a/utils/convert-month-partitioned-parts/main.cpp b/utils/convert-month-partitioned-parts/main.cpp index bce1e08077c..97eba631f1e 100644 --- a/utils/convert-month-partitioned-parts/main.cpp +++ b/utils/convert-month-partitioned-parts/main.cpp @@ -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()); }