Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion programs/copier/ClusterCopierApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void ClusterCopierApp::mainImpl()

context->setConfig(loaded_config.configuration);
context->setApplicationType(Context::ApplicationType::LOCAL);
context->setPath(process_path);
context->setPath(process_path + "/");

registerFunctions();
registerAggregateFunctions();
Expand Down
3 changes: 3 additions & 0 deletions src/Common/ErrorCodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,9 @@ namespace ErrorCodes
extern const int CANNOT_CONNECT_RABBITMQ = 530;
extern const int CANNOT_FSTAT = 531;
extern const int LDAP_ERROR = 532;
extern const int INCONSISTENT_RESERVATIONS = 533;
extern const int NO_RESERVATIONS_PROVIDED = 534;
extern const int UNKNOWN_RAID_TYPE = 535;

extern const int KEEPER_EXCEPTION = 999;
extern const int POCO_EXCEPTION = 1000;
Expand Down
1 change: 1 addition & 0 deletions src/Disks/IDisk.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ using DiskDirectoryIteratorPtr = std::unique_ptr<IDiskDirectoryIterator>;

class IReservation;
using ReservationPtr = std::unique_ptr<IReservation>;
using Reservations = std::vector<ReservationPtr>;

class ReadBufferFromFileBase;
class WriteBufferFromFileBase;
Expand Down
58 changes: 58 additions & 0 deletions src/Disks/IVolume.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,25 @@ namespace DB
namespace ErrorCodes
{
extern const int EXCESSIVE_ELEMENT_IN_CONFIG;
extern const int INCONSISTENT_RESERVATIONS;
extern const int NO_RESERVATIONS_PROVIDED;
extern const int UNKNOWN_VOLUME_TYPE;
}

String volumeTypeToString(VolumeType type)
{
switch (type)
{
case VolumeType::JBOD:
return "JBOD";
case VolumeType::RAID1:
return "RAID1";
case VolumeType::SINGLE_DISK:
return "SINGLE_DISK";
case VolumeType::UNKNOWN:
return "UNKNOWN";
}
throw Exception("Unknown volume type, please add it to DB::volumeTypeToString", ErrorCodes::UNKNOWN_VOLUME_TYPE);
}

IVolume::IVolume(
Expand Down Expand Up @@ -40,4 +59,43 @@ UInt64 IVolume::getMaxUnreservedFreeSpace() const
return res;
}

MultiDiskReservation::MultiDiskReservation(Reservations & reservations_, UInt64 size_)
: reservations(std::move(reservations_))
, size(size_)
{
if (reservations.empty())
{
throw Exception("At least one reservation must be provided to MultiDiskReservation", ErrorCodes::NO_RESERVATIONS_PROVIDED);
}

for (auto & reservation : reservations)
{
if (reservation->getSize() != size_)
{
throw Exception("Reservations must have same size", ErrorCodes::INCONSISTENT_RESERVATIONS);
}
}
}

Disks MultiDiskReservation::getDisks() const
{
Disks res;
res.reserve(reservations.size());
for (const auto & reservation : reservations)
{
res.push_back(reservation->getDisk());
}
return res;
}

void MultiDiskReservation::update(UInt64 new_size)
{
for (auto & reservation : reservations)
{
reservation->update(new_size);
}
size = new_size;
}


}
20 changes: 20 additions & 0 deletions src/Disks/IVolume.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ namespace DB
enum class VolumeType
{
JBOD,
RAID1,
SINGLE_DISK,
UNKNOWN
};

String volumeTypeToString(VolumeType t);

class IVolume;
using VolumePtr = std::shared_ptr<IVolume>;
using Volumes = std::vector<VolumePtr>;
Expand Down Expand Up @@ -61,4 +64,21 @@ class IVolume : public Space
const String name;
};

class MultiDiskReservation : public IReservation
{
public:
MultiDiskReservation(Reservations & reservations, UInt64 size);

UInt64 getSize() const override { return size; }

DiskPtr getDisk(size_t i) const override { return reservations[i]->getDisk(); }

Disks getDisks() const override;

void update(UInt64 new_size) override;
private:
Reservations reservations;
UInt64 size;
};

}
1 change: 1 addition & 0 deletions src/Disks/SingleDiskVolume.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ class SingleDiskVolume : public IVolume
};

using VolumeSingleDiskPtr = std::shared_ptr<SingleDiskVolume>;
using VolumesSingleDiskPtr = std::vector<VolumeSingleDiskPtr>;

}
4 changes: 2 additions & 2 deletions src/Disks/StoragePolicy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ StoragePolicy::StoragePolicy(
}


StoragePolicy::StoragePolicy(String name_, VolumesJBOD volumes_, double move_factor_)
StoragePolicy::StoragePolicy(String name_, Volumes volumes_, double move_factor_)
: volumes(std::move(volumes_)), name(std::move(name_)), move_factor(move_factor_)
{
if (volumes.empty())
Expand Down Expand Up @@ -257,7 +257,7 @@ StoragePolicySelector::StoragePolicySelector(
{
auto default_volume = std::make_shared<VolumeJBOD>(default_volume_name, std::vector<DiskPtr>{disks->get(default_disk_name)}, 0);

auto default_policy = std::make_shared<StoragePolicy>(default_storage_policy_name, VolumesJBOD{default_volume}, 0.0);
auto default_policy = std::make_shared<StoragePolicy>(default_storage_policy_name, Volumes{default_volume}, 0.0);
policies.emplace(default_storage_policy_name, default_policy);
}
}
Expand Down
11 changes: 6 additions & 5 deletions src/Disks/StoragePolicy.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <Disks/IDisk.h>
#include <Disks/IVolume.h>
#include <Disks/VolumeJBOD.h>
#include <Disks/VolumeRAID1.h>
#include <Disks/SingleDiskVolume.h>
#include <IO/WriteHelpers.h>
#include <Common/CurrentMetrics.h>
Expand Down Expand Up @@ -33,7 +34,7 @@ class StoragePolicy
public:
StoragePolicy(String name_, const Poco::Util::AbstractConfiguration & config, const String & config_prefix, DiskSelectorPtr disks);

StoragePolicy(String name_, VolumesJBOD volumes_, double move_factor_);
StoragePolicy(String name_, Volumes volumes_, double move_factor_);

bool isDefaultPolicy() const;

Expand Down Expand Up @@ -65,16 +66,16 @@ class StoragePolicy
/// Do not use this function when it is possible to predict size.
ReservationPtr makeEmptyReservationOnLargestDisk() const;

const VolumesJBOD & getVolumes() const { return volumes; }
const Volumes & getVolumes() const { return volumes; }

/// Returns number [0., 1.] -- fraction of free space on disk
/// which should be kept with help of background moves
double getMoveFactor() const { return move_factor; }

/// Get volume by index from storage_policy
VolumeJBODPtr getVolume(size_t i) const { return (i < volumes_names.size() ? volumes[i] : VolumeJBODPtr()); }
VolumePtr getVolume(size_t i) const { return (i < volumes_names.size() ? volumes[i] : VolumePtr()); }

VolumeJBODPtr getVolumeByName(const String & volume_name) const
VolumePtr getVolumeByName(const String & volume_name) const
{
auto it = volumes_names.find(volume_name);
if (it == volumes_names.end())
Expand All @@ -86,7 +87,7 @@ class StoragePolicy
void checkCompatibleWith(const StoragePolicyPtr & new_storage_policy) const;

private:
VolumesJBOD volumes;
Volumes volumes;
const String name;
std::map<String, size_t> volumes_names;

Expand Down
3 changes: 2 additions & 1 deletion src/Disks/VolumeJBOD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ DiskPtr VolumeJBOD::getNextDisk()

ReservationPtr VolumeJBOD::reserve(UInt64 bytes)
{
/// This volume can not store files which size greater than max_data_part_size
/// This volume can not store data which size is greater than `max_data_part_size`
/// to ensure that parts of size greater than that go to another volume(s).

if (max_data_part_size != 0 && bytes > max_data_part_size)
return {};
Expand Down
1 change: 1 addition & 0 deletions src/Disks/VolumeJBOD.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class VolumeJBOD : public IVolume
/// - Used with policy for temporary data
/// - Ignores all limitations
/// - Shares last access with reserve()
// TODO: Remove getNextDisk, move it's behaviour to VolumeJBOD::getDisk(), if it was called without argument.
DiskPtr getNextDisk();

/// Uses Round-robin to choose disk for reservation.
Expand Down
28 changes: 28 additions & 0 deletions src/Disks/VolumeRAID1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "VolumeRAID1.h"

#include <Common/StringUtils/StringUtils.h>
#include <Common/quoteString.h>

namespace DB
{

ReservationPtr VolumeRAID1::reserve(UInt64 bytes)
{
/// This volume can not store data which size is greater than `max_data_part_size`
/// to ensure that parts of size greater than that go to another volume(s).

if (max_data_part_size != 0 && bytes > max_data_part_size)
return {};

Reservations res(disks.size());
for (size_t i = 0; i < disks.size(); ++i)
{
res[i] = disks[i]->reserve(bytes);

if (!res[i])
return {};
}
return std::make_unique<MultiDiskReservation>(res, bytes);
}

}
33 changes: 33 additions & 0 deletions src/Disks/VolumeRAID1.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#pragma once

#include <Disks/createVolume.h>
#include <Disks/VolumeJBOD.h>

namespace DB
{

class VolumeRAID1 : public VolumeJBOD
{
public:
VolumeRAID1(String name_, Disks disks_, UInt64 max_data_part_size_)
: VolumeJBOD(name_, disks_, max_data_part_size_)
{
}

VolumeRAID1(
String name_,
const Poco::Util::AbstractConfiguration & config,
const String & config_prefix,
DiskSelectorPtr disk_selector
) : VolumeJBOD(name_, config, config_prefix, disk_selector)
{
}

VolumeType getType() const override { return VolumeType::RAID1; }

ReservationPtr reserve(UInt64 bytes) override;
};

using VolumeRAID1Ptr = std::shared_ptr<VolumeRAID1>;

}
38 changes: 37 additions & 1 deletion src/Disks/createVolume.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,53 @@
#include "createVolume.h"

#include <Disks/SingleDiskVolume.h>
#include <Disks/VolumeJBOD.h>
#include <Disks/VolumeRAID1.h>

#include <boost/algorithm/string.hpp>

namespace DB
{

namespace ErrorCodes
{
extern const int UNKNOWN_RAID_TYPE;
}

VolumePtr createVolumeFromReservation(const ReservationPtr & reservation, VolumePtr other_volume)
{
if (other_volume->getType() == VolumeType::JBOD || other_volume->getType() == VolumeType::SINGLE_DISK)
{
/// Since reservation on JBOD choices one of disks and makes reservation there, volume
/// Since reservation on JBOD chooses one of disks and makes reservation there, volume
/// for such type of reservation will be with one disk.
return std::make_shared<SingleDiskVolume>(other_volume->getName(), reservation->getDisk());
}
if (other_volume->getType() == VolumeType::RAID1)
{
auto volume = std::dynamic_pointer_cast<VolumeRAID1>(other_volume);
return std::make_shared<VolumeRAID1>(volume->getName(), reservation->getDisks(), volume->max_data_part_size);
}
return nullptr;
}

VolumePtr createVolumeFromConfig(
String name,
const Poco::Util::AbstractConfiguration & config,
const String & config_prefix,
DiskSelectorPtr disk_selector
)
{
auto has_raid_type = config.has(config_prefix + ".raid_type");
if (!has_raid_type)
{
return std::make_shared<VolumeJBOD>(name, config, config_prefix, disk_selector);
}
String raid_type = config.getString(config_prefix + ".raid_type");
if (raid_type == "JBOD")
{
return std::make_shared<VolumeJBOD>(name, config, config_prefix, disk_selector);
}
throw Exception("Unknown raid type '" + raid_type + "'", ErrorCodes::UNKNOWN_RAID_TYPE);
}

}
8 changes: 6 additions & 2 deletions src/Disks/createVolume.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
#pragma once

#include <Disks/IVolume.h>
#include <Disks/VolumeJBOD.h>
#include <Disks/SingleDiskVolume.h>

namespace DB
{

VolumePtr createVolumeFromReservation(const ReservationPtr & reservation, VolumePtr other_volume);
VolumePtr createVolumeFromConfig(
String name_,
const Poco::Util::AbstractConfiguration & config,
const String & config_prefix,
DiskSelectorPtr disk_selector
);

}
1 change: 1 addition & 0 deletions src/Disks/ya.make
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ SRCS(
SingleDiskVolume.cpp
StoragePolicy.cpp
VolumeJBOD.cpp
VolumeRAID1.cpp
)

END()
Loading