This commit is contained in:
Alexander Tokmakov 2023-06-20 17:47:25 +02:00
parent 4949dd0546
commit 60a0843f58
9 changed files with 38 additions and 8 deletions

View File

@ -24,7 +24,7 @@ protected:
/// Make local disk. /// Make local disk.
temp_dir = std::make_unique<Poco::TemporaryFile>(); temp_dir = std::make_unique<Poco::TemporaryFile>();
temp_dir->createDirectories(); temp_dir->createDirectories();
local_disk = std::make_shared<DiskLocal>("local_disk", temp_dir->path() + "/", 0); local_disk = std::make_shared<DiskLocal>("local_disk", temp_dir->path() + "/");
/// Make encrypted disk. /// Make encrypted disk.
auto settings = std::make_unique<DiskEncryptedSettings>(); auto settings = std::make_unique<DiskEncryptedSettings>();
@ -38,7 +38,7 @@ protected:
settings->current_key = key; settings->current_key = key;
settings->current_key_fingerprint = fingerprint; settings->current_key_fingerprint = fingerprint;
encrypted_disk = std::make_shared<DiskEncrypted>("encrypted_disk", std::move(settings), true); encrypted_disk = std::make_shared<DiskEncrypted>("encrypted_disk", std::move(settings));
} }
void TearDown() override void TearDown() override

View File

@ -303,6 +303,18 @@ DiskEncrypted::DiskEncrypted(const String & name_, std::unique_ptr<const DiskEnc
delegate->createDirectories(disk_path); delegate->createDirectories(disk_path);
} }
DiskEncrypted::DiskEncrypted(const String & name_, std::unique_ptr<const DiskEncryptedSettings> settings_)
: IDisk(name_)
, delegate(settings_->wrapped_disk)
, encrypted_name(name_)
, disk_path(settings_->disk_path)
, disk_absolute_path(settings_->wrapped_disk->getPath() + settings_->disk_path)
, current_settings(std::move(settings_))
, use_fake_transaction(true)
{
delegate->createDirectories(disk_path);
}
ReservationPtr DiskEncrypted::reserve(UInt64 bytes) ReservationPtr DiskEncrypted::reserve(UInt64 bytes)
{ {
auto reservation = delegate->reserve(bytes); auto reservation = delegate->reserve(bytes);

View File

@ -24,6 +24,7 @@ public:
DiskEncrypted(const String & name_, const Poco::Util::AbstractConfiguration & config_, const String & config_prefix_, const DisksMap & map_); DiskEncrypted(const String & name_, const Poco::Util::AbstractConfiguration & config_, const String & config_prefix_, const DisksMap & map_);
DiskEncrypted(const String & name_, std::unique_ptr<const DiskEncryptedSettings> settings_, DiskEncrypted(const String & name_, std::unique_ptr<const DiskEncryptedSettings> settings_,
const Poco::Util::AbstractConfiguration & config_, const String & config_prefix_); const Poco::Util::AbstractConfiguration & config_, const String & config_prefix_);
DiskEncrypted(const String & name_, std::unique_ptr<const DiskEncryptedSettings> settings_);
const String & getName() const override { return encrypted_name; } const String & getName() const override { return encrypted_name; }
const String & getPath() const override { return disk_absolute_path; } const String & getPath() const override { return disk_absolute_path; }

View File

@ -420,7 +420,7 @@ bool inline isSameDiskType(const IDisk & one, const IDisk & another)
void DiskLocal::copyDirectoryContent(const String & from_dir, const std::shared_ptr<IDisk> & to_disk, const String & to_dir) void DiskLocal::copyDirectoryContent(const String & from_dir, const std::shared_ptr<IDisk> & to_disk, const String & to_dir)
{ {
if (isSameDiskType(*this, *to_disk)) if (isSameDiskType(*this, *to_disk))
fs::copy(from_dir, to_dir, fs::copy_options::recursive | fs::copy_options::overwrite_existing); /// Use more optimal way. fs::copy(fs::path(disk_path) / from_dir, fs::path(to_disk->getPath()) / to_dir, fs::copy_options::recursive | fs::copy_options::overwrite_existing); /// Use more optimal way.
else else
IDisk::copyDirectoryContent(from_dir, to_disk, to_dir); IDisk::copyDirectoryContent(from_dir, to_disk, to_dir);
} }
@ -467,6 +467,15 @@ DiskLocal::DiskLocal(
disk_checker = std::make_unique<DiskLocalCheckThread>(this, context, local_disk_check_period_ms); disk_checker = std::make_unique<DiskLocalCheckThread>(this, context, local_disk_check_period_ms);
} }
DiskLocal::DiskLocal(const String & name_, const String & path_)
: IDisk(name_)
, disk_path(path_)
, keep_free_space_bytes(0)
, logger(&Poco::Logger::get("DiskLocal"))
, data_source_description(getLocalDataSourceDescription(disk_path))
{
}
DataSourceDescription DiskLocal::getDataSourceDescription() const DataSourceDescription DiskLocal::getDataSourceDescription() const
{ {
return data_source_description; return data_source_description;

View File

@ -29,6 +29,8 @@ public:
const Poco::Util::AbstractConfiguration & config, const Poco::Util::AbstractConfiguration & config,
const String & config_prefix); const String & config_prefix);
DiskLocal(const String & name_, const String & path_);
const String & getPath() const override { return disk_path; } const String & getPath() const override { return disk_path; }
ReservationPtr reserve(UInt64 bytes) override; ReservationPtr reserve(UInt64 bytes) override;

View File

@ -115,12 +115,18 @@ class IDisk : public Space
{ {
public: public:
/// Default constructor. /// Default constructor.
explicit IDisk(const String & name_, const Poco::Util::AbstractConfiguration & config, const String & config_prefix) IDisk(const String & name_, const Poco::Util::AbstractConfiguration & config, const String & config_prefix)
: name(name_) : name(name_)
, copying_thread_pool(CurrentMetrics::IDiskCopierThreads, CurrentMetrics::IDiskCopierThreadsActive, config.getUInt(config_prefix + ".thread_pool_size", 16)) , copying_thread_pool(CurrentMetrics::IDiskCopierThreads, CurrentMetrics::IDiskCopierThreadsActive, config.getUInt(config_prefix + ".thread_pool_size", 16))
{ {
} }
explicit IDisk(const String & name_)
: name(name_)
, copying_thread_pool(CurrentMetrics::IDiskCopierThreads, CurrentMetrics::IDiskCopierThreadsActive, 16)
{
}
/// This is a disk. /// This is a disk.
bool isDisk() const override { return true; } bool isDisk() const override { return true; }

View File

@ -33,7 +33,7 @@ public:
void SetUp() override void SetUp() override
{ {
fs::create_directories(tmp_root); fs::create_directories(tmp_root);
disk = std::make_shared<DB::DiskLocal>("local_disk", tmp_root, 0); disk = std::make_shared<DB::DiskLocal>("local_disk", tmp_root);
} }
void TearDown() override void TearDown() override

View File

@ -10,7 +10,7 @@ namespace fs = std::filesystem;
DB::DiskPtr createDisk() DB::DiskPtr createDisk()
{ {
fs::create_directory("tmp/"); fs::create_directory("tmp/");
return std::make_shared<DB::DiskLocal>("local_disk", "tmp/", 0); return std::make_shared<DB::DiskLocal>("local_disk", "tmp/");
} }
void destroyDisk(DB::DiskPtr & disk) void destroyDisk(DB::DiskPtr & disk)

View File

@ -23,7 +23,7 @@ protected:
/// Make local disk. /// Make local disk.
temp_dir = std::make_unique<Poco::TemporaryFile>(); temp_dir = std::make_unique<Poco::TemporaryFile>();
temp_dir->createDirectories(); temp_dir->createDirectories();
local_disk = std::make_shared<DiskLocal>("local_disk", getDirectory(), 0); local_disk = std::make_shared<DiskLocal>("local_disk", getDirectory());
} }
void TearDown() override void TearDown() override
@ -42,7 +42,7 @@ protected:
settings->current_key = key; settings->current_key = key;
settings->current_key_fingerprint = fingerprint; settings->current_key_fingerprint = fingerprint;
settings->disk_path = path; settings->disk_path = path;
encrypted_disk = std::make_shared<DiskEncrypted>("encrypted_disk", std::move(settings), true); encrypted_disk = std::make_shared<DiskEncrypted>("encrypted_disk", std::move(settings));
} }
String getFileNames() String getFileNames()