2021-08-18 22:19:14 +00:00
|
|
|
#pragma once
|
|
|
|
|
2023-05-01 12:23:59 +00:00
|
|
|
#include <Backups/BackupEntryWithChecksumCalculation.h>
|
2022-06-14 22:35:55 +00:00
|
|
|
#include <base/defines.h>
|
2021-08-18 22:19:14 +00:00
|
|
|
#include <mutex>
|
|
|
|
|
2023-05-03 11:51:36 +00:00
|
|
|
|
2021-08-18 22:19:14 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
class IDisk;
|
|
|
|
using DiskPtr = std::shared_ptr<IDisk>;
|
|
|
|
|
|
|
|
/// Represents a file prepared to be included in a backup, assuming that until this backup entry is destroyed the file won't be changed.
|
2023-05-01 12:23:59 +00:00
|
|
|
class BackupEntryFromImmutableFile : public BackupEntryWithChecksumCalculation<IBackupEntry>
|
2021-08-18 22:19:14 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/// The constructor is allowed to not set `file_size_` or `checksum_`, in that case it will be calculated from the data.
|
|
|
|
BackupEntryFromImmutableFile(
|
|
|
|
const DiskPtr & disk_,
|
|
|
|
const String & file_path_,
|
2023-05-03 23:27:16 +00:00
|
|
|
bool copy_encrypted_ = false,
|
2021-08-18 22:19:14 +00:00
|
|
|
const std::optional<UInt64> & file_size_ = {},
|
2023-04-23 10:25:46 +00:00
|
|
|
const std::optional<UInt128> & checksum_ = {});
|
2021-08-18 22:19:14 +00:00
|
|
|
|
|
|
|
~BackupEntryFromImmutableFile() override;
|
|
|
|
|
2023-05-03 11:51:36 +00:00
|
|
|
std::unique_ptr<SeekableReadBuffer> getReadBuffer(const ReadSettings & read_settings) const override;
|
2023-05-01 12:23:59 +00:00
|
|
|
|
|
|
|
UInt64 getSize() const override;
|
2023-07-20 07:46:22 +00:00
|
|
|
UInt128 getChecksum(const ReadSettings & read_settings) const override;
|
|
|
|
std::optional<UInt128> getPartialChecksum(size_t prefix_length, const ReadSettings & read_settings) const override;
|
2021-08-18 22:19:14 +00:00
|
|
|
|
2023-04-25 17:44:03 +00:00
|
|
|
DataSourceDescription getDataSourceDescription() const override { return data_source_description; }
|
2023-05-03 23:27:16 +00:00
|
|
|
bool isEncryptedByDisk() const override { return copy_encrypted; }
|
2022-08-19 14:58:30 +00:00
|
|
|
|
2023-04-25 17:44:03 +00:00
|
|
|
bool isFromFile() const override { return true; }
|
|
|
|
bool isFromImmutableFile() const override { return true; }
|
|
|
|
DiskPtr getDisk() const override { return disk; }
|
|
|
|
String getFilePath() const override { return file_path; }
|
2021-08-18 22:19:14 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
const DiskPtr disk;
|
|
|
|
const String file_path;
|
2023-04-25 17:44:03 +00:00
|
|
|
const DataSourceDescription data_source_description;
|
2023-05-03 23:27:16 +00:00
|
|
|
const bool copy_encrypted;
|
2023-05-01 12:23:59 +00:00
|
|
|
mutable std::optional<UInt64> file_size;
|
2023-05-27 12:35:37 +00:00
|
|
|
mutable std::optional<UInt128> checksum;
|
2023-05-01 12:23:59 +00:00
|
|
|
mutable bool file_size_adjusted = false;
|
|
|
|
mutable bool checksum_adjusted = false;
|
|
|
|
mutable std::mutex size_and_checksum_mutex;
|
2021-08-18 22:19:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|