2014-08-01 13:19:27 +00:00
|
|
|
#pragma once
|
|
|
|
|
2015-09-29 00:53:10 +00:00
|
|
|
#include <string>
|
2015-09-29 19:19:54 +00:00
|
|
|
#include <common/logger_useful.h>
|
2014-08-04 06:36:24 +00:00
|
|
|
#include <Poco/File.h>
|
2014-08-15 14:34:45 +00:00
|
|
|
|
2014-08-04 08:37:46 +00:00
|
|
|
|
2014-08-04 06:36:24 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
2014-08-01 13:19:27 +00:00
|
|
|
|
2017-05-07 20:25:26 +00:00
|
|
|
/// stores the sizes of all columns, and can check whether the columns are corrupted
|
2014-08-01 13:19:27 +00:00
|
|
|
class FileChecker
|
|
|
|
{
|
2015-09-29 00:53:10 +00:00
|
|
|
private:
|
2017-05-07 20:25:26 +00:00
|
|
|
/// File name -> size.
|
2017-04-01 07:20:54 +00:00
|
|
|
using Map = std::map<std::string, size_t>;
|
2015-09-29 00:53:10 +00:00
|
|
|
|
2014-08-01 13:19:27 +00:00
|
|
|
public:
|
2017-04-01 07:20:54 +00:00
|
|
|
using Files = std::vector<Poco::File>;
|
2014-08-04 06:36:24 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
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);
|
2014-08-01 13:19:27 +00:00
|
|
|
|
2017-05-07 20:25:26 +00:00
|
|
|
/// Check the files whose parameters are specified in sizes.json
|
2017-04-01 07:20:54 +00:00
|
|
|
bool check() const;
|
2014-08-01 13:19:27 +00:00
|
|
|
|
|
|
|
private:
|
2017-04-01 07:20:54 +00:00
|
|
|
void initialize();
|
|
|
|
void updateImpl(const Poco::File & file);
|
|
|
|
void save() const;
|
|
|
|
void load(Map & map) const;
|
2015-09-29 00:53:10 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
std::string files_info_path;
|
|
|
|
std::string tmp_files_info_path;
|
2014-08-01 13:19:27 +00:00
|
|
|
|
2017-05-07 20:25:26 +00:00
|
|
|
/// The data from the file is read lazily.
|
2017-04-01 07:20:54 +00:00
|
|
|
Map map;
|
|
|
|
bool initialized = false;
|
2014-08-01 13:19:27 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
Logger * log = &Logger::get("FileChecker");
|
2014-08-01 13:19:27 +00:00
|
|
|
};
|
2015-09-29 14:09:01 +00:00
|
|
|
|
2014-08-04 06:36:24 +00:00
|
|
|
}
|