mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-25 00:52:02 +00:00
Miscellaneous #3726
This commit is contained in:
parent
b41fa8e7af
commit
c70e8cc5f0
@ -104,18 +104,17 @@ String Cluster::Address::readableString() const
|
||||
return res;
|
||||
}
|
||||
|
||||
void Cluster::Address::fromString(const String & host_port_string, String & host_name, UInt16 & port)
|
||||
std::pair<String, UInt16> Cluster::Address::fromString(const String & host_port_string)
|
||||
{
|
||||
auto pos = host_port_string.find_last_of(':');
|
||||
if (pos == std::string::npos)
|
||||
throw Exception("Incorrect <host>:<port> format " + host_port_string, ErrorCodes::SYNTAX_ERROR);
|
||||
|
||||
host_name = unescapeForFileName(host_port_string.substr(0, pos));
|
||||
port = parse<UInt16>(host_port_string.substr(pos + 1));
|
||||
return {unescapeForFileName(host_port_string.substr(0, pos)), parse<UInt16>(host_port_string.substr(pos + 1))};
|
||||
}
|
||||
|
||||
|
||||
String Cluster::Address::toStringFull() const
|
||||
String Cluster::Address::toFullString() const
|
||||
{
|
||||
return
|
||||
escapeForFileName(user) +
|
||||
@ -126,7 +125,7 @@ String Cluster::Address::toStringFull() const
|
||||
+ ((secure == Protocol::Secure::Enable) ? "+secure" : "");
|
||||
}
|
||||
|
||||
void Cluster::Address::fromFullString(const String & full_string, Cluster::Address & address)
|
||||
Cluster::Address Cluster::Address::fromFullString(const String & full_string)
|
||||
{
|
||||
const char * address_begin = full_string.data();
|
||||
const char * address_end = address_begin + full_string.size();
|
||||
@ -152,19 +151,14 @@ void Cluster::Address::fromFullString(const String & full_string, Cluster::Addre
|
||||
const char * has_db = strchr(full_string.data(), '#');
|
||||
const char * port_end = has_db ? has_db : address_end;
|
||||
|
||||
Address address;
|
||||
address.secure = secure;
|
||||
address.port = parse<UInt16>(host_end + 1, port_end - (host_end + 1));
|
||||
address.host_name = unescapeForFileName(std::string(user_pw_end + 1, host_end));
|
||||
address.user = unescapeForFileName(std::string(address_begin, has_pw ? colon : user_pw_end));
|
||||
address.password = has_pw ? unescapeForFileName(std::string(colon + 1, user_pw_end)) : std::string();
|
||||
address.default_database = has_db ? unescapeForFileName(std::string(has_db + 1, address_end)) : std::string();
|
||||
}
|
||||
|
||||
bool Cluster::Address::operator==(const Cluster::Address & other) const
|
||||
{
|
||||
return other.host_name == host_name && other.port == port
|
||||
&& other.secure == secure && other.user == user
|
||||
&& other.password == password && other.default_database == default_database;
|
||||
return address;
|
||||
}
|
||||
|
||||
|
||||
@ -303,7 +297,7 @@ Cluster::Cluster(const Poco::Util::AbstractConfiguration & config, const Setting
|
||||
{
|
||||
if (internal_replication)
|
||||
{
|
||||
auto dir_name = replica_addresses.back().toStringFull();
|
||||
auto dir_name = replica_addresses.back().toFullString();
|
||||
if (first)
|
||||
dir_name_for_internal_replication = dir_name;
|
||||
else
|
||||
|
@ -78,12 +78,11 @@ public:
|
||||
|
||||
static String toString(const String & host_name, UInt16 port);
|
||||
|
||||
static void fromString(const String & host_port_string, String & host_name, UInt16 & port);
|
||||
static std::pair<String, UInt16> fromString(const String & host_port_string);
|
||||
|
||||
/// Retrurns escaped user:password@resolved_host_address:resolved_host_port#default_database
|
||||
String toStringFull() const;
|
||||
|
||||
static void fromFullString(const String & address_full_string, Address & address);
|
||||
String toFullString() const;
|
||||
static Address fromFullString(const String & address_full_string);
|
||||
|
||||
/// Returns initially resolved address
|
||||
Poco::Net::SocketAddress getResolvedAddress() const
|
||||
@ -91,7 +90,8 @@ public:
|
||||
return initially_resolved_address;
|
||||
}
|
||||
|
||||
bool operator==(const Address & other) const;
|
||||
auto tuple() const { return std::tie(host_name, port, secure, user, password, default_database); }
|
||||
bool operator==(const Address & other) const { return tuple() == other.tuple(); }
|
||||
|
||||
private:
|
||||
Poco::Net::SocketAddress initially_resolved_address;
|
||||
|
@ -70,7 +70,7 @@ struct HostID
|
||||
static HostID fromString(const String & host_port_str)
|
||||
{
|
||||
HostID res;
|
||||
Cluster::Address::fromString(host_port_str, res.host_name, res.port);
|
||||
std::tie(res.host_name, res.port) = Cluster::Address::fromString(host_port_str);
|
||||
return res;
|
||||
}
|
||||
|
||||
@ -1076,9 +1076,7 @@ public:
|
||||
status.tryDeserializeText(status_data);
|
||||
}
|
||||
|
||||
String host;
|
||||
UInt16 port;
|
||||
Cluster::Address::fromString(host_id, host, port);
|
||||
auto [host, port] = Cluster::Address::fromString(host_id);
|
||||
|
||||
if (status.code != 0 && first_exception == nullptr)
|
||||
first_exception = std::make_unique<Exception>("There was an error on [" + host + ":" + toString(port) + "]: " + status.message, status.code);
|
||||
|
@ -48,8 +48,7 @@ namespace
|
||||
|
||||
for (auto it = boost::make_split_iterator(name, boost::first_finder(",")); it != decltype(it){}; ++it)
|
||||
{
|
||||
Cluster::Address address;
|
||||
Cluster::Address::fromFullString(boost::copy_range<std::string>(*it), address);
|
||||
Cluster::Address address = Cluster::Address::fromFullString(boost::copy_range<std::string>(*it));
|
||||
pools.emplace_back(factory(address));
|
||||
}
|
||||
|
||||
|
@ -494,7 +494,7 @@ void DistributedBlockOutputStream::writeAsyncImpl(const Block & block, const siz
|
||||
std::vector<std::string> dir_names;
|
||||
for (const auto & address : cluster->getShardsAddresses()[shard_id])
|
||||
if (!address.is_local)
|
||||
dir_names.push_back(address.toStringFull());
|
||||
dir_names.push_back(address.toFullString());
|
||||
|
||||
if (!dir_names.empty())
|
||||
writeToShard(block, dir_names);
|
||||
|
Loading…
Reference in New Issue
Block a user