-
Notifications
You must be signed in to change notification settings - Fork 9k
Expand file tree
/
Copy pathBackupEntryFromAppendOnlyFile.cpp
More file actions
69 lines (58 loc) · 2.34 KB
/
Copy pathBackupEntryFromAppendOnlyFile.cpp
File metadata and controls
69 lines (58 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <memory>
#include <Backups/BackupEntryFromAppendOnlyFile.h>
#include <Interpreters/TemporaryDataOnDisk.h>
#include <Disks/IDisk.h>
#include <IO/LimitSeekableReadBuffer.h>
#include <IO/ReadBufferFromFileBase.h>
#include <IO/SeekableReadBuffer.h>
namespace DB
{
namespace
{
/// For append-only files we must calculate its size on the construction of a backup entry.
UInt64 calculateSize(const DiskPtr & disk, const String & file_path, bool copy_encrypted, std::optional<UInt64> passed_file_size)
{
if (copy_encrypted)
return passed_file_size ? disk->getEncryptedFileSize(*passed_file_size) : disk->getEncryptedFileSize(file_path);
if (passed_file_size)
return *passed_file_size;
return disk->getFileSize(file_path);
}
}
BackupEntryFromAppendOnlyFile::BackupEntryFromAppendOnlyFile(
const DiskPtr & disk_,
const String & file_path_,
bool copy_encrypted_,
const std::optional<UInt64> & file_size_,
bool allow_checksum_from_remote_path_)
: disk(disk_)
, file_path(file_path_)
, data_source_description(disk->getDataSourceDescription())
, copy_encrypted(copy_encrypted_ && data_source_description.is_encrypted)
, size(calculateSize(disk_, file_path_, copy_encrypted, file_size_))
, allow_checksum_from_remote_path(allow_checksum_from_remote_path_)
{
}
BackupEntryFromAppendOnlyFile::BackupEntryFromAppendOnlyFile(TemporaryDataBufferPtr tmp_file_)
: tmp_file(std::move(tmp_file_))
, file_path(tmp_file->describeFilePath())
, size(tmp_file->getStat().compressed_size)
{
}
BackupEntryFromAppendOnlyFile::~BackupEntryFromAppendOnlyFile() = default;
std::unique_ptr<SeekableReadBuffer> BackupEntryFromAppendOnlyFile::getReadBuffer(const ReadSettings & read_settings) const
{
std::unique_ptr<SeekableReadBuffer> buf;
if (tmp_file)
buf = tmp_file->readRaw();
else if (copy_encrypted)
buf = disk->readEncryptedFile(file_path, read_settings.adjustBufferSize(size));
else
buf = disk->readFile(file_path, read_settings.adjustBufferSize(size));
return std::make_unique<LimitSeekableReadBuffer>(std::move(buf), 0, size);
}
std::unique_ptr<SeekableReadBuffer> BackupEntryFromAppendOnlyFile::getReadBufferForEncryptionHeader(const ReadSettings & read_settings) const
{
return disk->readEncryptedFile(file_path, read_settings);
}
}