2021-01-23 15:20:15 +00:00
|
|
|
#pragma once
|
2021-02-26 09:48:57 +00:00
|
|
|
|
|
|
|
#include <Disks/DiskType.h>
|
|
|
|
|
2021-01-23 15:20:15 +00:00
|
|
|
#include <memory>
|
|
|
|
#include <vector>
|
2022-10-25 22:14:06 +00:00
|
|
|
#include <optional>
|
2021-10-02 07:13:14 +00:00
|
|
|
#include <base/types.h>
|
2021-01-23 15:20:15 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
class IStoragePolicy;
|
|
|
|
using StoragePolicyPtr = std::shared_ptr<const IStoragePolicy>;
|
|
|
|
class IVolume;
|
|
|
|
using VolumePtr = std::shared_ptr<IVolume>;
|
|
|
|
using Volumes = std::vector<VolumePtr>;
|
|
|
|
class IDisk;
|
|
|
|
using DiskPtr = std::shared_ptr<IDisk>;
|
|
|
|
using Disks = std::vector<DiskPtr>;
|
|
|
|
class IReservation;
|
2021-09-16 21:19:58 +00:00
|
|
|
using ReservationSharedPtr = std::shared_ptr<IReservation>;
|
2021-01-23 15:20:15 +00:00
|
|
|
using ReservationPtr = std::unique_ptr<IReservation>;
|
|
|
|
using Reservations = std::vector<ReservationPtr>;
|
|
|
|
|
|
|
|
using String = std::string;
|
|
|
|
|
|
|
|
class IStoragePolicy
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~IStoragePolicy() = default;
|
|
|
|
virtual const String & getName() const = 0;
|
|
|
|
virtual const Volumes & getVolumes() const = 0;
|
|
|
|
/// Returns number [0., 1.] -- fraction of free space on disk
|
|
|
|
/// which should be kept with help of background moves
|
|
|
|
virtual double getMoveFactor() const = 0;
|
|
|
|
virtual bool isDefaultPolicy() const = 0;
|
|
|
|
/// Returns disks ordered by volumes priority
|
|
|
|
virtual Disks getDisks() const = 0;
|
|
|
|
/// Returns any disk
|
|
|
|
/// Used when it's not important, for example for
|
|
|
|
/// mutations files
|
|
|
|
virtual DiskPtr getAnyDisk() const = 0;
|
2022-02-10 16:18:01 +00:00
|
|
|
virtual DiskPtr tryGetDiskByName(const String & disk_name) const = 0;
|
|
|
|
DiskPtr getDiskByName(const String & disk_name) const;
|
2021-01-23 15:20:15 +00:00
|
|
|
/// Get free space from most free disk
|
|
|
|
virtual UInt64 getMaxUnreservedFreeSpace() const = 0;
|
|
|
|
/// Reserves space on any volume with index > min_volume_index or returns nullptr
|
|
|
|
virtual ReservationPtr reserve(UInt64 bytes, size_t min_volume_index) const = 0;
|
|
|
|
/// Returns valid reservation or nullptr
|
|
|
|
virtual ReservationPtr reserve(UInt64 bytes) const = 0;
|
|
|
|
/// Reserves space on any volume or throws
|
|
|
|
virtual ReservationPtr reserveAndCheck(UInt64 bytes) const = 0;
|
|
|
|
/// Reserves 0 bytes on disk with max available space
|
|
|
|
/// Do not use this function when it is possible to predict size.
|
|
|
|
virtual ReservationPtr makeEmptyReservationOnLargestDisk() const = 0;
|
|
|
|
/// Get volume by index.
|
|
|
|
virtual VolumePtr getVolume(size_t index) const = 0;
|
2022-02-10 16:18:01 +00:00
|
|
|
virtual VolumePtr tryGetVolumeByName(const String & volume_name) const = 0;
|
|
|
|
VolumePtr getVolumeByName(const String & volume_name) const;
|
2021-01-23 15:20:15 +00:00
|
|
|
/// Checks if storage policy can be replaced by another one.
|
|
|
|
virtual void checkCompatibleWith(const StoragePolicyPtr & new_storage_policy) const = 0;
|
2022-10-25 22:14:06 +00:00
|
|
|
/// Finds a volume index, which contains disk
|
|
|
|
virtual std::optional<size_t> tryGetVolumeIndexByDiskName(const String & disk_name) const = 0;
|
|
|
|
size_t getVolumeIndexByDiskName(const String & disk_name) const;
|
|
|
|
/// Finds a volume which contains a specified disk.
|
|
|
|
VolumePtr tryGetVolumeByDiskName(const String & disk_name) const;
|
|
|
|
VolumePtr getVolumeByDiskName(const String & disk_name) const;
|
2021-01-23 15:20:15 +00:00
|
|
|
/// Check if we have any volume with stopped merges
|
|
|
|
virtual bool hasAnyVolumeWithDisabledMerges() const = 0;
|
|
|
|
virtual bool containsVolume(const String & volume_name) const = 0;
|
2021-02-05 17:13:44 +00:00
|
|
|
/// Returns disks by type ordered by volumes priority
|
2021-01-23 15:20:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|