2014-08-01 13:19:27 +00:00
|
|
|
#pragma once
|
|
|
|
|
2019-07-03 13:17:19 +00:00
|
|
|
#include <Storages/CheckResults.h>
|
2023-04-08 04:47:21 +00:00
|
|
|
#include <map>
|
|
|
|
#include <base/types.h>
|
2014-08-15 14:34:45 +00:00
|
|
|
|
2023-04-08 04:47:21 +00:00
|
|
|
namespace Poco { class Logger; }
|
2014-08-04 08:37:46 +00:00
|
|
|
|
2014-08-04 06:36:24 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
2022-01-24 17:41:13 +00:00
|
|
|
class IDisk;
|
|
|
|
using DiskPtr = std::shared_ptr<IDisk>;
|
|
|
|
|
2014-08-01 13:19:27 +00:00
|
|
|
|
2021-08-26 22:15:24 +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:
|
2022-01-24 17:41:13 +00:00
|
|
|
FileChecker(const String & file_info_path_);
|
2019-12-12 08:57:25 +00:00
|
|
|
FileChecker(DiskPtr disk_, const String & file_info_path_);
|
2021-10-26 09:48:31 +00:00
|
|
|
|
2019-12-12 08:57:25 +00:00
|
|
|
void setPath(const String & file_info_path_);
|
2021-10-26 09:48:31 +00:00
|
|
|
String getPath() const;
|
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
|
2023-08-10 11:44:16 +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();
|
|
|
|
|
2021-08-26 22:15:24 +00:00
|
|
|
/// Returns stored file size.
|
|
|
|
size_t getFileSize(const String & full_file_path) const;
|
2020-09-24 23:29:16 +00:00
|
|
|
|
2022-05-02 22:01:11 +00:00
|
|
|
/// Returns total size of all files.
|
|
|
|
size_t getTotalSize() const;
|
|
|
|
|
2020-09-24 23:29:16 +00:00
|
|
|
private:
|
2021-01-03 21:07:26 +00:00
|
|
|
void load();
|
2015-09-29 00:53:10 +00:00
|
|
|
|
2022-01-24 17:41:13 +00:00
|
|
|
bool fileReallyExists(const String & path_) const;
|
|
|
|
size_t getRealFileSize(const String & path_) const;
|
|
|
|
|
2021-08-26 22:15:24 +00:00
|
|
|
const DiskPtr disk;
|
2023-04-08 04:47:21 +00:00
|
|
|
const Poco::Logger * log;
|
2014-08-01 13:19:27 +00:00
|
|
|
|
2021-08-26 22:15:24 +00:00
|
|
|
String files_info_path;
|
2021-08-26 22:15:24 +00:00
|
|
|
std::map<String, size_t> map;
|
2014-08-01 13:19:27 +00:00
|
|
|
};
|
2015-09-29 14:09:01 +00:00
|
|
|
|
2014-08-04 06:36:24 +00:00
|
|
|
}
|