2017-02-16 21:38:25 +00:00
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
#include <boost/program_options.hpp>
|
2019-03-18 15:54:58 +00:00
|
|
|
#include <boost/algorithm/string/predicate.hpp>
|
2017-02-16 21:38:25 +00:00
|
|
|
|
2018-12-28 18:15:26 +00:00
|
|
|
#include <Compression/CompressedWriteBuffer.h>
|
|
|
|
#include <Compression/CompressedReadBuffer.h>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <IO/WriteHelpers.h>
|
|
|
|
#include <IO/Operators.h>
|
|
|
|
#include <IO/ReadBufferFromFile.h>
|
|
|
|
#include <IO/ReadHelpers.h>
|
2024-10-24 11:57:26 +00:00
|
|
|
#include <IO/ReadSettings.h>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <IO/WriteBufferFromFileDescriptor.h>
|
2022-03-11 08:30:48 +00:00
|
|
|
#include <Disks/IO/createReadBufferFromFileBase.h>
|
2018-12-28 18:15:26 +00:00
|
|
|
#include <Compression/CompressedReadBufferFromFile.h>
|
2017-02-16 21:38:25 +00:00
|
|
|
|
|
|
|
|
2020-12-29 19:37:27 +00:00
|
|
|
/** This program checks correctness of .mrk/.mrk2 (marks) file for corresponding compressed .bin file.
|
2017-02-16 21:38:25 +00:00
|
|
|
*/
|
|
|
|
|
2020-05-09 22:59:34 +00:00
|
|
|
static void checkByCompressedReadBuffer(const std::string & mrk_path, const std::string & bin_path)
|
2017-02-17 01:32:25 +00:00
|
|
|
{
|
|
|
|
DB::ReadBufferFromFile mrk_in(mrk_path);
|
2021-10-18 22:03:45 +00:00
|
|
|
DB::CompressedReadBufferFromFile bin_in(DB::createReadBufferFromFileBase(bin_path, /* settings= */ {}));
|
2017-02-17 01:32:25 +00:00
|
|
|
|
|
|
|
DB::WriteBufferFromFileDescriptor out(STDOUT_FILENO);
|
2024-02-27 15:28:02 +00:00
|
|
|
bool mrk2_format = mrk_path.ends_with(".mrk2");
|
2017-02-17 01:32:25 +00:00
|
|
|
|
|
|
|
for (size_t mark_num = 0; !mrk_in.eof(); ++mark_num)
|
|
|
|
{
|
|
|
|
UInt64 offset_in_compressed_file = 0;
|
|
|
|
UInt64 offset_in_decompressed_block = 0;
|
2019-03-18 15:54:58 +00:00
|
|
|
UInt64 index_granularity_rows = 0;
|
2017-02-17 01:32:25 +00:00
|
|
|
|
|
|
|
DB::readBinary(offset_in_compressed_file, mrk_in);
|
|
|
|
DB::readBinary(offset_in_decompressed_block, mrk_in);
|
|
|
|
|
2019-03-18 15:54:58 +00:00
|
|
|
out << "Mark " << mark_num << ", points to " << offset_in_compressed_file << ", " << offset_in_decompressed_block;
|
|
|
|
|
|
|
|
if (mrk2_format)
|
|
|
|
{
|
|
|
|
DB::readBinary(index_granularity_rows, mrk_in);
|
|
|
|
|
|
|
|
out << ", has rows after " << index_granularity_rows;
|
|
|
|
}
|
|
|
|
|
2017-02-17 01:32:25 +00:00
|
|
|
bin_in.seek(offset_in_compressed_file, offset_in_decompressed_block);
|
2020-12-29 19:31:07 +00:00
|
|
|
out << ", decompressed size " << bin_in.available();
|
|
|
|
|
|
|
|
out << ".\n" << DB::flush;
|
2024-11-12 11:50:57 +00:00
|
|
|
|
|
|
|
out.finalize();
|
2017-02-17 01:32:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-11-26 14:57:42 +00:00
|
|
|
int mainEntryClickHouseCheckMarks(int argc, char ** argv)
|
2017-02-16 21:38:25 +00:00
|
|
|
{
|
|
|
|
boost::program_options::options_description desc("Allowed options");
|
|
|
|
desc.add_options()
|
|
|
|
("help,h", "produce help message")
|
|
|
|
;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2017-02-16 21:38:25 +00:00
|
|
|
boost::program_options::variables_map options;
|
|
|
|
boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), options);
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2017-02-16 21:38:25 +00:00
|
|
|
if (options.count("help") || argc != 3)
|
|
|
|
{
|
2020-12-29 19:37:27 +00:00
|
|
|
std::cout << "Usage: " << argv[0] << " file.mrk[2] file.bin" << std::endl;
|
2017-02-16 21:38:25 +00:00
|
|
|
std::cout << desc << std::endl;
|
|
|
|
return 1;
|
|
|
|
}
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2017-02-16 21:38:25 +00:00
|
|
|
try
|
|
|
|
{
|
2017-02-17 01:32:25 +00:00
|
|
|
checkByCompressedReadBuffer(argv[1], argv[2]);
|
2017-02-16 21:38:25 +00:00
|
|
|
}
|
|
|
|
catch (const DB::Exception & e)
|
|
|
|
{
|
|
|
|
std::cerr << e.what() << ", " << e.message() << std::endl
|
|
|
|
<< std::endl
|
|
|
|
<< "Stack trace:" << std::endl
|
2020-01-02 10:27:40 +00:00
|
|
|
<< e.getStackTraceString()
|
2017-02-16 21:38:25 +00:00
|
|
|
<< std::endl;
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|