api: storage_service: remove_node: validate host_id
The node to be removed must be identified by its host_id. Validate that at the api layer and pass the parsed host_id down to storage_service::removenode. Signed-off-by: Benny Halevy <bhalevy@scylladb.com>
This commit is contained in:
@@ -1432,4 +1432,33 @@ future<> shared_token_metadata::mutate_token_metadata(seastar::noncopyable_funct
|
||||
set(make_token_metadata_ptr(std::move(tm)));
|
||||
}
|
||||
|
||||
host_id_or_endpoint::host_id_or_endpoint(const sstring& s, param_type restrict) {
|
||||
switch (restrict) {
|
||||
case param_type::host_id:
|
||||
try {
|
||||
id = host_id(utils::UUID(s));
|
||||
} catch (const marshal_exception& e) {
|
||||
throw std::invalid_argument(format("Invalid host_id {}: {}", s, e.what()));
|
||||
}
|
||||
break;
|
||||
case param_type::endpoint:
|
||||
try {
|
||||
endpoint = gms::inet_address(s);
|
||||
} catch (std::invalid_argument& e) {
|
||||
throw std::invalid_argument(format("Invalid inet_address {}: {}", s, e.what()));
|
||||
}
|
||||
break;
|
||||
case param_type::auto_detect:
|
||||
try {
|
||||
id = host_id(utils::UUID(s));
|
||||
} catch (const marshal_exception& e) {
|
||||
try {
|
||||
endpoint = gms::inet_address(s);
|
||||
} catch (std::invalid_argument& e) {
|
||||
throw std::invalid_argument(format("Invalid host_id or inet_address {}", s));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace locator
|
||||
|
||||
@@ -133,6 +133,27 @@ private:
|
||||
bool _sort_by_proximity = true;
|
||||
};
|
||||
|
||||
struct host_id_or_endpoint {
|
||||
host_id id;
|
||||
gms::inet_address endpoint;
|
||||
|
||||
enum class param_type {
|
||||
host_id,
|
||||
endpoint,
|
||||
auto_detect
|
||||
};
|
||||
|
||||
host_id_or_endpoint(const sstring& s, param_type restrict = param_type::auto_detect);
|
||||
|
||||
bool has_host_id() const noexcept {
|
||||
return bool(id);
|
||||
}
|
||||
|
||||
bool has_endpoint() const noexcept {
|
||||
return endpoint != gms::inet_address();
|
||||
}
|
||||
};
|
||||
|
||||
using dc_rack_fn = seastar::noncopyable_function<endpoint_dc_rack(inet_address)>;
|
||||
class token_metadata_impl;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user