dbms: Server: queries with several replicas: development [#METR-14410]

This commit is contained in:
Alexey Arno 2015-01-15 18:05:03 +03:00
parent ec2c7389a5
commit cfbc15c0b4
4 changed files with 46 additions and 15 deletions

View File

@ -44,6 +44,10 @@ namespace DB
std::string dumpAddresses() const;
size_t size() const;
void sendExternalTablesData(std::vector<ExternalTablesData> & data);
private:
using ConnectionHash = std::unordered_map<int, ConnectionInfo>;

View File

@ -274,6 +274,7 @@ namespace ErrorCodes
INCOMPATIBLE_TYPE_OF_JOIN,
NO_AVAILABLE_REPLICA,
UNEXPECTED_REPLICA,
MISMATCH_REPLICAS_DATA_SOURCES,
POCO_EXCEPTION = 1000,
STD_EXCEPTION,

View File

@ -121,6 +121,13 @@ public:
protected:
/// Отправить на удаленные сервера все временные таблицы
void sendExternalTables()
{
size_t count = use_many_replicas ? replicas_connections->size() : 1;
std::vector<ExternalTablesData> instances;
instances.reserve(count);
for (size_t i = 0; i < count; ++i)
{
ExternalTablesData res;
for (const auto & table : external_tables)
@ -134,13 +141,13 @@ protected:
else
res.push_back(std::make_pair(input[0], table.first));
}
if (use_many_replicas)
{
/// XXX Отправить res по всем соединениям.
//replicas_connections->sendExternalTablesData(res);
instances.push_back(std::move(res));
}
if (use_many_replicas)
replicas_connections->sendExternalTablesData(instances);
else
connection->sendExternalTablesData(res);
connection->sendExternalTablesData(instances[0]);
}
Block readImpl() override

View File

@ -236,4 +236,23 @@ namespace DB
return os.str();
}
size_t ReplicasConnections::size() const
{
return connection_hash.size();
}
void ReplicasConnections::sendExternalTablesData(std::vector<ExternalTablesData> & data)
{
if (data.size() != connection_hash.size())
throw Exception("Mismatch between replicas and data sources", ErrorCodes::MISMATCH_REPLICAS_DATA_SOURCES);
auto it = data.begin();
for (auto & e : connection_hash)
{
Connection * connection = e.second.connection;
connection->sendExternalTablesData(*it);
++it;
}
}
}