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
Show all changes
25 commits
Select commit Hold shift + click to select a range
3585b24
MultiDiskReservation, VolumeRAID1 and createVolumeFromConfig
NanoBjorn May 24, 2020
db56820
Style fixes and added UNKNOWN_RAID_TYPE exception to createVolumeFrom…
NanoBjorn May 24, 2020
96c7cc8
Small clang-10 warning fixes + ya.make
NanoBjorn May 25, 2020
7f5b6fb
Generic volume is coming...
NanoBjorn May 28, 2020
adef249
Small fix of VolumeRAID1Ptr
NanoBjorn May 27, 2020
2c39584
Braces style fix
NanoBjorn May 28, 2020
e4699e2
removed default clause in switch for VolumeType enum
NanoBjorn Jun 1, 2020
f4080ed
removed unused error code
NanoBjorn Jun 1, 2020
99d5255
Small fixes for tests
NanoBjorn Jun 23, 2020
aac9795
Fixed integration test_tmp_policy
NanoBjorn Jul 8, 2020
ee07c74
Fixed integration test_multiple_disks
NanoBjorn Jul 8, 2020
8039d45
Minor fix in `StorageDistributed`.
excitoon Jul 22, 2020
ee21fde
Review fixes.
excitoon Jul 22, 2020
f5af645
Test fix (removed redundant code).
excitoon Jul 23, 2020
1b3f5c9
Real fix of test.
excitoon Jul 23, 2020
a9e0a5d
Test fix.
excitoon Jul 26, 2020
6d22069
Review fixes.
excitoon Jul 27, 2020
83556a5
Minor thing.
excitoon Jul 27, 2020
98fca0a
Empty commit to re-run checks.
excitoon Jul 27, 2020
faedb04
Minor fixes.
excitoon Jul 28, 2020
bcc926f
Returned `max_data_part_size` to `system.storage_policies`.
excitoon Jul 30, 2020
724b7be
Merge branch 'volumes-related-refactorings' of https://github.com/exc…
alesapin Jul 30, 2020
d3ea1d9
Tiny fixes and avoid dynamic casts
alesapin Jul 30, 2020
1c8aa4b
Fix get disk interface
alesapin Jul 30, 2020
df0dcf4
Fix error codes
alesapin Jul 30, 2020
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 @@ -497,6 +497,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
63 changes: 62 additions & 1 deletion src/Disks/IVolume.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,32 @@ 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(
String name_, const Poco::Util::AbstractConfiguration & config, const String & config_prefix, DiskSelectorPtr disk_selector)
String name_,
const Poco::Util::AbstractConfiguration & config,
const String & config_prefix,
DiskSelectorPtr disk_selector)
: name(std::move(name_))
{
Poco::Util::AbstractConfiguration::Keys keys;
Expand All @@ -40,4 +62,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;
}


}
33 changes: 31 additions & 2 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 All @@ -33,7 +36,10 @@ using Volumes = std::vector<VolumePtr>;
class IVolume : public Space
{
public:
IVolume(String name_, Disks disks_): disks(std::move(disks_)), name(name_)
IVolume(String name_, Disks disks_, size_t max_data_part_size_ = 0)
: disks(std::move(disks_))
, name(name_)
, max_data_part_size(max_data_part_size_)
{
}

Expand All @@ -53,12 +59,35 @@ class IVolume : public Space
/// Return biggest unreserved space across all disks
UInt64 getMaxUnreservedFreeSpace() const;

DiskPtr getDisk(size_t i = 0) const { return disks[i]; }
DiskPtr getDisk() const { return getDisk(0); }
virtual DiskPtr getDisk(size_t i) const { return disks[i]; }
const Disks & getDisks() const { return disks; }

protected:
Disks disks;
const String name;

public:
/// Max size of reservation, zero means unlimited size
UInt64 max_data_part_size = 0;
};

/// Reservation for multiple disks at once. Can be used in RAID1 implementation.
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>;

}
8 changes: 4 additions & 4 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 @@ -204,15 +204,15 @@ void StoragePolicy::checkCompatibleWith(const StoragePolicyPtr & new_storage_pol
for (const auto & volume : getVolumes())
{
if (new_volume_names.count(volume->getName()) == 0)
throw Exception("New storage policy shall contain volumes of old one", ErrorCodes::LOGICAL_ERROR);
throw Exception("New storage policy shall contain volumes of old one", ErrorCodes::BAD_ARGUMENTS);

std::unordered_set<String> new_disk_names;
for (const auto & disk : new_storage_policy->getVolumeByName(volume->getName())->getDisks())
new_disk_names.insert(disk->getName());

for (const auto & disk : volume->getDisks())
if (new_disk_names.count(disk->getName()) == 0)
throw Exception("New storage policy shall contain disks of old one", ErrorCodes::LOGICAL_ERROR);
throw Exception("New storage policy shall contain disks of old one", ErrorCodes::BAD_ARGUMENTS);
}
}

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
9 changes: 5 additions & 4 deletions src/Disks/VolumeJBOD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ VolumeJBOD::VolumeJBOD(
String name_,
const Poco::Util::AbstractConfiguration & config,
const String & config_prefix,
DiskSelectorPtr disk_selector
) : IVolume(name_, config, config_prefix, disk_selector)
DiskSelectorPtr disk_selector)
: IVolume(name_, config, config_prefix, disk_selector)
{
Poco::Logger * logger = &Poco::Logger::get("StorageConfiguration");

Expand Down Expand Up @@ -55,7 +55,7 @@ VolumeJBOD::VolumeJBOD(
LOG_WARNING(logger, "Volume {} max_data_part_size is too low ({} < {})", backQuote(name), ReadableSize(max_data_part_size), ReadableSize(MIN_PART_SIZE));
}

DiskPtr VolumeJBOD::getNextDisk()
DiskPtr VolumeJBOD::getDisk(size_t /* index */) const
{
size_t start_from = last_used.fetch_add(1u, std::memory_order_relaxed);
size_t index = start_from % disks.size();
Expand All @@ -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
8 changes: 3 additions & 5 deletions src/Disks/VolumeJBOD.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class VolumeJBOD : public IVolume
{
public:
VolumeJBOD(String name_, Disks disks_, UInt64 max_data_part_size_)
: IVolume(name_, disks_), max_data_part_size(max_data_part_size_)
: IVolume(name_, disks_, max_data_part_size_)
{
}

Expand All @@ -27,19 +27,17 @@ class VolumeJBOD : public IVolume

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

/// Next disk (round-robin)
/// Always returns next disk (round-robin), ignores argument.
///
/// - Used with policy for temporary data
/// - Ignores all limitations
/// - Shares last access with reserve()
DiskPtr getNextDisk();
DiskPtr getDisk(size_t index) const override;

/// 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;
};
Expand Down
29 changes: 29 additions & 0 deletions src/Disks/VolumeRAID1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#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);
}

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

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

namespace DB
{

/// Volume which reserserves space on each underlying disk.
///
/// NOTE: Just interface implementation, doesn't used in codebase,
/// also not available for user.
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>;

}
Loading