diff --git a/src/Common/ErrorCodes.cpp b/src/Common/ErrorCodes.cpp index dbb539ef2b3..9efacdb7b90 100644 --- a/src/Common/ErrorCodes.cpp +++ b/src/Common/ErrorCodes.cpp @@ -494,6 +494,7 @@ namespace ErrorCodes extern const int CANNOT_DETACH_DICTIONARY_AS_TABLE = 520; extern const int ATOMIC_RENAME_FAIL = 521; extern const int INCORRECT_DISK_INDEX = 522; + extern const int UNKNOWN_VOLUME_TYPE = 523; extern const int KEEPER_EXCEPTION = 999; extern const int POCO_EXCEPTION = 1000; diff --git a/src/Disks/IVolume.cpp b/src/Disks/IVolume.cpp index 6a122a3e3b2..4da9aec1ab9 100644 --- a/src/Disks/IVolume.cpp +++ b/src/Disks/IVolume.cpp @@ -10,6 +10,30 @@ namespace DB namespace ErrorCodes { extern const int EXCESSIVE_ELEMENT_IN_CONFIG; + extern const int UNKNOWN_VOLUME_TYPE; +} + +void VolumeType::fromString(const String & str) +{ + if (str == "JBOD") + value = JBOD; + else if (str == "SINGLE_DISK") + value = SINGLE_DISK; + else + throw DB::Exception("Unexpected string for volume type: " + str, ErrorCodes::UNKNOWN_VOLUME_TYPE); +} + +String VolumeType::toString() const +{ + switch (value) + { + case JBOD: + return "JBOD"; + case SINGLE_DISK: + return "SINGLE_DISK"; + default: + return "Unknown"; + } } IVolume::IVolume( diff --git a/src/Disks/IVolume.h b/src/Disks/IVolume.h index 8365102196d..0b1c0a20ad9 100644 --- a/src/Disks/IVolume.h +++ b/src/Disks/IVolume.h @@ -8,11 +8,33 @@ namespace DB { -enum VolumeType +class VolumeType { - JBOD, - SINGLE_DISK, - UNKNOWN +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; }; class IVolume;