2020-05-04 20:15:38 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <Disks/IDisk.h>
|
|
|
|
#include <Disks/DiskSelector.h>
|
|
|
|
|
|
|
|
#include <Poco/Util/AbstractConfiguration.h>
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2020-05-10 06:26:33 +00:00
|
|
|
class VolumeType
|
2020-05-09 21:24:15 +00:00
|
|
|
{
|
2020-05-10 06:26:33 +00:00
|
|
|
public:
|
|
|
|
enum Value
|
|
|
|
{
|
|
|
|
JBOD,
|
|
|
|
SINGLE_DISK,
|
|
|
|
UNKNOWN
|
|
|
|
};
|
|
|
|
VolumeType() : value(UNKNOWN) {}
|
|
|
|
VolumeType(Value value_) : value(value_) {}
|
|
|
|
|
|
|
|
bool operator==(const VolumeType & other) const
|
|
|
|
{
|
|
|
|
return value == other.value;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator!=(const VolumeType & other) const
|
|
|
|
{
|
|
|
|
return !(*this == other);
|
|
|
|
}
|
|
|
|
|
|
|
|
void fromString(const String & str);
|
|
|
|
String toString() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
Value value;
|
2020-05-09 21:24:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class IVolume;
|
|
|
|
using VolumePtr = std::shared_ptr<IVolume>;
|
|
|
|
using Volumes = std::vector<VolumePtr>;
|
|
|
|
|
2020-05-04 20:15:38 +00:00
|
|
|
/**
|
|
|
|
* Disks group by some (user) criteria. For example,
|
|
|
|
* - VolumeJBOD("slow_disks", [d1, d2], 100)
|
|
|
|
* - VolumeJBOD("fast_disks", [d3, d4], 200)
|
|
|
|
*
|
|
|
|
* Here VolumeJBOD is one of implementations of IVolume.
|
|
|
|
*
|
|
|
|
* Different of implementations of this interface implement different reserve behaviour —
|
|
|
|
* VolumeJBOD reserves space on the next disk after the last used, other future implementations
|
|
|
|
* will reserve, for example, equal spaces on all disks.
|
|
|
|
*/
|
2020-05-04 20:20:51 +00:00
|
|
|
class IVolume : public Space
|
|
|
|
{
|
2020-05-04 20:15:38 +00:00
|
|
|
public:
|
2020-05-09 21:24:15 +00:00
|
|
|
IVolume(const String & name_, Disks disks_): disks(std::move(disks_)), name(name_)
|
2020-05-04 20:15:38 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
IVolume(
|
|
|
|
String name_,
|
|
|
|
const Poco::Util::AbstractConfiguration & config,
|
|
|
|
const String & config_prefix,
|
|
|
|
DiskSelectorPtr disk_selector
|
|
|
|
);
|
|
|
|
|
|
|
|
virtual ReservationPtr reserve(UInt64 bytes) override = 0;
|
|
|
|
|
|
|
|
/// Volume name from config
|
|
|
|
const String & getName() const override { return name; }
|
2020-05-09 21:24:15 +00:00
|
|
|
virtual VolumeType getType() const = 0;
|
2020-05-04 20:15:38 +00:00
|
|
|
|
|
|
|
/// Return biggest unreserved space across all disks
|
|
|
|
UInt64 getMaxUnreservedFreeSpace() const;
|
|
|
|
|
2020-05-09 21:24:15 +00:00
|
|
|
DiskPtr getDisk(size_t i = 0) const { return disks[i]; }
|
|
|
|
const Disks & getDisks() const { return disks; }
|
|
|
|
|
2020-05-04 20:15:38 +00:00
|
|
|
protected:
|
2020-05-09 21:24:15 +00:00
|
|
|
Disks disks;
|
2020-05-04 20:15:38 +00:00
|
|
|
const String name;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|