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