1#pragma once
2
3#include <string>
4#include <common/logger_useful.h>
5#include <Poco/File.h>
6#include <Storages/CheckResults.h>
7
8
9namespace DB
10{
11
12/// stores the sizes of all columns, and can check whether the columns are corrupted
13class FileChecker
14{
15private:
16 /// File name -> size.
17 using Map = std::map<std::string, size_t>;
18
19public:
20 using Files = std::vector<Poco::File>;
21
22 FileChecker(const std::string & file_info_path_);
23 void setPath(const std::string & file_info_path_);
24 void update(const Poco::File & file);
25 void update(const Files::const_iterator & begin, const Files::const_iterator & end);
26
27 /// Check the files whose parameters are specified in sizes.json
28 CheckResults check() const;
29
30private:
31 void initialize();
32 void updateImpl(const Poco::File & file);
33 void save() const;
34 static void load(Map & local_map, const std::string & path);
35
36 std::string files_info_path;
37 std::string tmp_files_info_path;
38
39 /// The data from the file is read lazily.
40 Map map;
41 bool initialized = false;
42
43 Logger * log = &Logger::get("FileChecker");
44};
45
46}
47