2014-08-01 13:19:27 +00:00
|
|
|
#pragma once
|
|
|
|
|
2019-07-03 13:17:19 +00:00
|
|
|
#include <Storages/CheckResults.h>
|
2024-01-23 17:04:50 +00:00
|
|
|
#include <Common/Logger.h>
|
2023-04-08 04:47:21 +00:00
|
|
|
#include <map>
|
|
|
|
#include <base/types.h>
|
2024-01-12 22:48:55 +00:00
|
|
|
#include <memory>
|
2023-08-14 09:58:08 +00:00
|
|
|
#include <mutex>
|
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:
|
2024-02-29 14:56:33 +00:00
|
|
|
explicit 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-14 09:58:08 +00:00
|
|
|
/// See comment in IStorage::checkDataNext
|
|
|
|
struct DataValidationTasks;
|
|
|
|
using DataValidationTasksPtr = std::unique_ptr<DataValidationTasks>;
|
|
|
|
DataValidationTasksPtr getDataValidationTasks();
|
2023-10-23 10:12:30 +00:00
|
|
|
std::optional<CheckResult> checkNextEntry(DataValidationTasksPtr & check_data_tasks) 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;
|
|
|
|
|
2023-08-14 09:58:08 +00:00
|
|
|
struct DataValidationTasks
|
|
|
|
{
|
2024-02-29 14:56:33 +00:00
|
|
|
explicit DataValidationTasks(const std::map<String, size_t> & map_)
|
2023-08-14 09:58:08 +00:00
|
|
|
: map(map_), it(map.begin())
|
|
|
|
{}
|
|
|
|
|
|
|
|
bool next(String & out_name, size_t & out_size)
|
|
|
|
{
|
|
|
|
std::lock_guard lock(mutex);
|
|
|
|
if (it == map.end())
|
|
|
|
return true;
|
|
|
|
out_name = it->first;
|
|
|
|
out_size = it->second;
|
|
|
|
++it;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t size() const
|
|
|
|
{
|
|
|
|
std::lock_guard lock(mutex);
|
|
|
|
return std::distance(it, map.end());
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::map<String, size_t> & map;
|
|
|
|
|
|
|
|
mutable std::mutex mutex;
|
|
|
|
using Iterator = std::map<String, size_t>::const_iterator;
|
|
|
|
Iterator it;
|
|
|
|
};
|
|
|
|
|
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;
|
2024-01-23 17:04:50 +00:00
|
|
|
const LoggerPtr 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
|
|
|
}
|