From be68461fc6f53a5eb896c37a8aed4b33b496fd00 Mon Sep 17 00:00:00 2001 From: Andrey Mironov Date: Mon, 22 Jun 2015 18:45:30 +0300 Subject: [PATCH] dbms: correctly determine mark to end of previous block [#MTRSADMIN-1093] --- .../MergeTree/MergeTreePartChecker.cpp | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/dbms/src/Storages/MergeTree/MergeTreePartChecker.cpp b/dbms/src/Storages/MergeTree/MergeTreePartChecker.cpp index c8e8a84f3fe..3bd49d17231 100644 --- a/dbms/src/Storages/MergeTree/MergeTreePartChecker.cpp +++ b/dbms/src/Storages/MergeTree/MergeTreePartChecker.cpp @@ -11,6 +11,7 @@ #include #include #include +#include namespace DB @@ -115,6 +116,12 @@ struct Stream readIntBinary(mrk_mark.offset_in_compressed_file, mrk_hashing_buf); readIntBinary(mrk_mark.offset_in_decompressed_block, mrk_hashing_buf); + /// На всякий случай, сохраним смещение в файле и размер предыдущего блока. + SCOPE_EXIT( + prev_offset_in_compressed_file = mrk_mark.offset_in_compressed_file; + prev_buffer_size = uncompressed_hashing_buf.buffer().size(); + ); + bool has_alternative_mark = false; MarkInCompressedFile alternative_data_mark; MarkInCompressedFile data_mark; @@ -138,6 +145,18 @@ struct Stream if (uncompressed_hashing_buf.eof()) return; } + else if (uncompressed_hashing_buf.offset() == 0) + { + /// Восстановим засечку на конец предыдущего блока по сохраненным данным + has_alternative_mark = true; + alternative_data_mark.offset_in_compressed_file = prev_offset_in_compressed_file; + alternative_data_mark.offset_in_decompressed_block = prev_buffer_size; + + if (mrk_mark == alternative_data_mark) + return; + } + + std::cout << "mrk_mark " << mrk_mark.offset_in_compressed_file << ' ' << mrk_mark.offset_in_decompressed_block << std::endl; data_mark.offset_in_compressed_file = compressed_hashing_buf.count() - uncompressing_buf.getSizeCompressed(); data_mark.offset_in_decompressed_block = uncompressed_hashing_buf.offset(); @@ -161,6 +180,10 @@ struct Stream checksums.files[name + ".mrk"] = MergeTreeData::DataPart::Checksums::Checksum( mrk_hashing_buf.count(), mrk_hashing_buf.getHash()); } + +private: + size_t prev_offset_in_compressed_file{}; + size_t prev_buffer_size{}; }; /// Возвращает количество строк. Добавляет в checksums чексуммы всех файлов столбца.