db/config, utils: allow using UUID as a config option
We change the `recovery_leader` option to UUID in the following commit.
This commit is contained in:
28
db/config.cc
28
db/config.cc
@@ -86,6 +86,12 @@ object_storage_endpoints_to_json(const std::vector<db::object_storage_endpoint_p
|
||||
return value_to_json(m);
|
||||
}
|
||||
|
||||
static
|
||||
json::json_return_type
|
||||
uuid_to_json(const db::config::UUID& uuid) {
|
||||
return value_to_json(format("{}", uuid));
|
||||
}
|
||||
|
||||
// Convert a value that can be printed with fmt::format, or a vector of
|
||||
// such values, to JSON. An example is enum_option<T>, because enum_option<T>
|
||||
// has a specialization for fmt::formatter.
|
||||
@@ -294,6 +300,12 @@ const config_type& config_type_for<std::vector<db::object_storage_endpoint_param
|
||||
return ct;
|
||||
}
|
||||
|
||||
template <>
|
||||
const config_type& config_type_for<db::config::UUID>() {
|
||||
static config_type ct("UUID", uuid_to_json);
|
||||
return ct;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace YAML {
|
||||
@@ -491,6 +503,22 @@ struct convert<db::object_storage_endpoint_param> {
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct convert<utils::UUID> {
|
||||
static bool decode(const Node& node, utils::UUID& uuid) {
|
||||
std::string uuid_string;
|
||||
if (!convert<std::string>::decode(node, uuid_string)) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
std::istringstream(uuid_string) >> uuid;
|
||||
} catch (boost::program_options::invalid_option_value&) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#if defined(DEBUG)
|
||||
|
||||
@@ -207,6 +207,7 @@ public:
|
||||
using seed_provider_type = db::seed_provider_type;
|
||||
using hinted_handoff_enabled_type = db::hints::host_filter;
|
||||
using error_injection_at_startup = db::error_injection_at_startup;
|
||||
using UUID = utils::UUID;
|
||||
|
||||
/*
|
||||
* All values and documentation taken from
|
||||
|
||||
@@ -68,6 +68,8 @@ public:
|
||||
|
||||
friend std::ostream& operator<<(std::ostream& out, const UUID& uuid);
|
||||
|
||||
friend std::istream& operator>>(std::istream& in, UUID& uuid);
|
||||
|
||||
bool operator==(const UUID& v) const noexcept = default;
|
||||
|
||||
// Please note that this comparator does not preserve timeuuid
|
||||
|
||||
@@ -38,6 +38,13 @@ std::ostream& operator<<(std::ostream& out, const UUID& uuid) {
|
||||
return out;
|
||||
}
|
||||
|
||||
std::istream& operator>>(std::istream& in, UUID& uuid) {
|
||||
sstring uuid_string;
|
||||
in >> uuid_string;
|
||||
uuid = UUID(uuid_string);
|
||||
return in;
|
||||
}
|
||||
|
||||
UUID::UUID(std::string_view uuid) {
|
||||
sstring uuid_string(uuid.begin(), uuid.end());
|
||||
boost::erase_all(uuid_string, "-");
|
||||
|
||||
Reference in New Issue
Block a user