2020-05-04 20:15:38 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <Disks/IVolume.h>
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements something similar to JBOD (https://en.wikipedia.org/wiki/Non-RAID_drive_architectures#JBOD).
|
|
|
|
* When MergeTree engine wants to write part — it requests VolumeJBOD to reserve space on the next available
|
|
|
|
* disk and then writes new part to that disk.
|
|
|
|
*/
|
2020-05-04 20:20:51 +00:00
|
|
|
class VolumeJBOD : public IVolume
|
|
|
|
{
|
2020-05-04 20:15:38 +00:00
|
|
|
public:
|
|
|
|
VolumeJBOD(String name_, Disks disks_, UInt64 max_data_part_size_)
|
|
|
|
: IVolume(name_, disks_), max_data_part_size(max_data_part_size_)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
VolumeJBOD(
|
|
|
|
String name_,
|
|
|
|
const Poco::Util::AbstractConfiguration & config,
|
|
|
|
const String & config_prefix,
|
|
|
|
DiskSelectorPtr disk_selector
|
|
|
|
);
|
|
|
|
|
|
|
|
/// Next disk (round-robin)
|
|
|
|
///
|
|
|
|
/// - Used with policy for temporary data
|
|
|
|
/// - Ignores all limitations
|
|
|
|
/// - Shares last access with reserve()
|
|
|
|
DiskPtr getNextDisk();
|
|
|
|
|
|
|
|
/// Uses Round-robin to choose disk for reservation.
|
|
|
|
/// Returns valid reservation or nullptr if there is no space left on any disk.
|
|
|
|
ReservationPtr reserve(UInt64 bytes) override;
|
|
|
|
|
|
|
|
/// Max size of reservation
|
|
|
|
UInt64 max_data_part_size = 0;
|
|
|
|
private:
|
|
|
|
mutable std::atomic<size_t> last_used = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
using VolumeJBODPtr = std::shared_ptr<VolumeJBOD>;
|
|
|
|
using VolumesJBOD = std::vector<VolumeJBODPtr>;
|
|
|
|
|
|
|
|
}
|