2014-08-01 13:19:27 +00:00
|
|
|
#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>
|
2019-12-12 08:57:25 +00:00
|
|
|
#include <Disks/IDisk.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
|
|
|
|
{
|
|
|
|
public:
|
2019-12-12 08:57:25 +00:00
|
|
|
FileChecker(DiskPtr disk_, const String & file_info_path_);
|
|
|
|
void setPath(const String & file_info_path_);
|
2020-07-12 02:31:58 +00:00
|
|
|
|
|
|
|
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(); }
|
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
|
2019-07-03 13:17:19 +00:00
|
|
|
CheckResults check() const;
|
2014-08-01 13:19:27 +00:00
|
|
|
|
2020-07-12 02:31:58 +00:00
|
|
|
/// 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();
|
|
|
|
|
2019-12-12 08:57:25 +00:00
|
|
|
/// File name -> size.
|
|
|
|
using Map = std::map<String, UInt64>;
|
|
|
|
|
2020-09-24 23:29:16 +00:00
|
|
|
Map getFileSizes() const;
|
|
|
|
|
|
|
|
private:
|
2021-01-03 21:07:26 +00:00
|
|
|
void load();
|
2015-09-29 00:53:10 +00:00
|
|
|
|
2019-12-12 08:57:25 +00:00
|
|
|
DiskPtr disk;
|
|
|
|
String files_info_path;
|
2014-08-01 13:19:27 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
Map map;
|
2014-08-01 13:19:27 +00:00
|
|
|
|
2020-05-30 21:57:37 +00:00
|
|
|
Poco::Logger * log = &Poco::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
|
|
|
}
|