check-marks: added another method for check [#CLICKHOUSE-2841].

This commit is contained in:
Alexey Milovidov 2017-02-17 04:32:25 +03:00
parent 2e0374f5e0
commit 5c8a51678c

View File

@ -9,6 +9,7 @@
#include <DB/IO/ReadBufferFromFile.h> #include <DB/IO/ReadBufferFromFile.h>
#include <DB/IO/ReadHelpers.h> #include <DB/IO/ReadHelpers.h>
#include <DB/IO/WriteBufferFromFileDescriptor.h> #include <DB/IO/WriteBufferFromFileDescriptor.h>
#include <DB/IO/CompressedReadBufferFromFile.h>
/** This program checks correctness of .mrk (marks) file for corresponding compressed .bin file. /** This program checks correctness of .mrk (marks) file for corresponding compressed .bin file.
@ -43,27 +44,10 @@ std::pair<UInt32, UInt32> stat(DB::ReadBuffer & in, DB::WriteBuffer & out)
} }
int main(int argc, char ** argv) void checkCompressedHeaders(const std::string & mrk_path, const std::string & bin_path)
{ {
boost::program_options::options_description desc("Allowed options"); DB::ReadBufferFromFile mrk_in(mrk_path);
desc.add_options() DB::ReadBufferFromFile bin_in(bin_path, 4096); /// Small buffer size just to check header of compressed block.
("help,h", "produce help message")
;
boost::program_options::variables_map options;
boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), options);
if (options.count("help") || argc != 3)
{
std::cout << "Usage: " << argv[0] << " file.mrk file.bin" << std::endl;
std::cout << desc << std::endl;
return 1;
}
try
{
DB::ReadBufferFromFile mrk_in(argv[1]);
DB::ReadBufferFromFile bin_in(argv[2], 4096); /// Small buffer size just to check header of compressed block.
DB::WriteBufferFromFileDescriptor out(STDOUT_FILENO); DB::WriteBufferFromFileDescriptor out(STDOUT_FILENO);
@ -83,6 +67,52 @@ int main(int argc, char ** argv)
out << "Block sizes: " << sizes.first << ", " << sizes.second << '\n' << DB::flush; out << "Block sizes: " << sizes.first << ", " << sizes.second << '\n' << DB::flush;
} }
} }
void checkByCompressedReadBuffer(const std::string & mrk_path, const std::string & bin_path)
{
DB::ReadBufferFromFile mrk_in(mrk_path);
DB::CompressedReadBufferFromFile bin_in(bin_path, 0, 0);
DB::WriteBufferFromFileDescriptor out(STDOUT_FILENO);
for (size_t mark_num = 0; !mrk_in.eof(); ++mark_num)
{
UInt64 offset_in_compressed_file = 0;
UInt64 offset_in_decompressed_block = 0;
DB::readBinary(offset_in_compressed_file, mrk_in);
DB::readBinary(offset_in_decompressed_block, mrk_in);
out << "Mark " << mark_num << ", points to " << offset_in_compressed_file << ", " << offset_in_decompressed_block << ".\n" << DB::flush;
bin_in.seek(offset_in_compressed_file, offset_in_decompressed_block);
}
}
int main(int argc, char ** argv)
{
boost::program_options::options_description desc("Allowed options");
desc.add_options()
("help,h", "produce help message")
;
boost::program_options::variables_map options;
boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), options);
if (options.count("help") || argc != 3)
{
std::cout << "Usage: " << argv[0] << " file.mrk file.bin" << std::endl;
std::cout << desc << std::endl;
return 1;
}
try
{
/// checkCompressedHeaders(argv[1], argv[2]);
checkByCompressedReadBuffer(argv[1], argv[2]);
}
catch (const DB::Exception & e) catch (const DB::Exception & e)
{ {
std::cerr << e.what() << ", " << e.message() << std::endl std::cerr << e.what() << ", " << e.message() << std::endl