ClickHouse/src/Common/FileChecker.h

48 lines
1.1 KiB
C++
Raw Normal View History

#pragma once
2015-09-29 19:19:54 +00:00
#include <common/logger_useful.h>
2019-07-03 13:17:19 +00:00
#include <Storages/CheckResults.h>
#include <Disks/IDisk.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
{
public:
FileChecker(DiskPtr disk_, const String & file_info_path_);
void setPath(const String & file_info_path_);
void update(const String & full_file_path);
void setEmpty(const String & full_file_path);
void save() const;
2021-01-05 01:49:15 +00:00
bool empty() const { return map.empty(); }
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;
/// Truncate files that have excessive size to the expected size.
/// Throw exception if the file size is less than expected.
/// The purpose of this function is to rollback a group of unfinished writes.
void repair();
/// File name -> size.
using Map = std::map<String, UInt64>;
Map getFileSizes() const;
private:
void load();
DiskPtr disk;
String files_info_path;
Map map;
2020-05-30 21:57:37 +00:00
Poco::Logger * log = &Poco::Logger::get("FileChecker");
};
}