ClickHouse/dbms/src/Common/FileChecker.h

47 lines
1.1 KiB
C++
Raw Normal View History

#pragma once
#include <string>
2015-09-29 19:19:54 +00:00
#include <common/logger_useful.h>
#include <Poco/File.h>
2019-07-03 13:17:19 +00:00
#include <Storages/CheckResults.h>
namespace DB
{
2017-05-07 20:25:26 +00:00
/// stores the sizes of all columns, and can check whether the columns are corrupted
class FileChecker
{
private:
2017-05-07 20:25:26 +00:00
/// File name -> size.
using Map = std::map<std::string, size_t>;
public:
using Files = std::vector<Poco::File>;
FileChecker(const std::string & file_info_path_);
void setPath(const std::string & file_info_path_);
void update(const Poco::File & file);
void update(const Files::const_iterator & begin, const Files::const_iterator & end);
2017-05-07 20:25:26 +00:00
/// Check the files whose parameters are specified in sizes.json
2019-07-03 13:17:19 +00:00
CheckResults check() const;
private:
void initialize();
void updateImpl(const Poco::File & file);
void save() const;
2018-08-26 02:08:35 +00:00
static void load(Map & local_map, const std::string & path);
std::string files_info_path;
std::string tmp_files_info_path;
2017-05-07 20:25:26 +00:00
/// The data from the file is read lazily.
Map map;
bool initialized = false;
Logger * log = &Logger::get("FileChecker");
};
}