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-16 20:31:17 +00:00
|
|
|
enum class VolumeType
|
2020-05-09 21:24:15 +00:00
|
|
|
{
|
2020-05-16 20:31:17 +00:00
|
|
|
JBOD,
|
2020-05-24 16:32:58 +00:00
|
|
|
RAID1,
|
2020-05-16 20:31:17 +00:00
|
|
|
SINGLE_DISK,
|
|
|
|
UNKNOWN
|
2020-05-09 21:24:15 +00:00
|
|
|
};
|
|
|
|
|
2020-05-28 05:38:55 +00:00
|
|
|
String volumeTypeToString(VolumeType t);
|
|
|
|
|
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-09-18 15:30:00 +00:00
|
|
|
IVolume(String name_, Disks disks_, size_t max_data_part_size_ = 0, bool perform_ttl_move_on_insert_ = true)
|
2020-07-30 10:04:49 +00:00
|
|
|
: disks(std::move(disks_))
|
|
|
|
, name(name_)
|
|
|
|
, max_data_part_size(max_data_part_size_)
|
2020-09-18 15:30:00 +00:00
|
|
|
, perform_ttl_move_on_insert(perform_ttl_move_on_insert_)
|
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-07-30 11:08:56 +00:00
|
|
|
DiskPtr getDisk() const { return getDisk(0); }
|
|
|
|
virtual DiskPtr getDisk(size_t i) const { return disks[i]; }
|
2020-05-09 21:24:15 +00:00
|
|
|
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;
|
2020-07-30 10:04:49 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
/// Max size of reservation, zero means unlimited size
|
|
|
|
UInt64 max_data_part_size = 0;
|
2020-09-18 15:30:00 +00:00
|
|
|
/// Should a new data part be synchronously moved to a volume according to ttl on insert
|
|
|
|
/// or move this part in background task asynchronously after insert.
|
2020-09-18 17:45:30 +00:00
|
|
|
bool perform_ttl_move_on_insert = true;
|
2020-05-04 20:15:38 +00:00
|
|
|
};
|
|
|
|
|
2020-07-30 10:04:49 +00:00
|
|
|
/// Reservation for multiple disks at once. Can be used in RAID1 implementation.
|
2020-05-24 16:32:58 +00:00
|
|
|
class MultiDiskReservation : public IReservation
|
|
|
|
{
|
|
|
|
public:
|
2020-07-22 22:05:45 +00:00
|
|
|
MultiDiskReservation(Reservations & reservations, UInt64 size);
|
2020-05-24 16:32:58 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2020-05-04 20:15:38 +00:00
|
|
|
}
|