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

This commit is contained in:
Alexey Arno 2015-01-15 21:33:20 +03:00
parent 98e91a1c32
commit c3ccfdfa0d
3 changed files with 18 additions and 10 deletions

View File

@ -1,18 +1,17 @@
#pragma once
#include <DB/Client/Connection.h>
#include <DB/Client/ConnectionPool.h>
namespace DB
{
class IConnectionPool;
/**
* Множество реплик одного шарда.
*/
class ShardReplicas final
{
public:
ShardReplicas(IConnectionPool * pool_, Settings * settings_);
ShardReplicas(std::vector<ConnectionPool::Entry> & entries, Settings * settings_);
~ShardReplicas() = default;

View File

@ -156,8 +156,16 @@ protected:
{
if (use_many_replicas)
{
shard_replicas.reset(new ShardReplicas(pool, &settings));
shard_replicas->sendQuery(query, "", stage, &settings, true);
auto entries = pool->getMany(&settings);
if (entries.size() > 1)
shard_replicas.reset(new ShardReplicas(entries, &settings));
else if (entries.size() == 1)
{
use_many_replicas = false;
connection = &*entries[0];
}
else // XXX Придумать исключение + сообщение
throw Exception("");
}
else
{
@ -167,10 +175,13 @@ protected:
pool_entry = pool->get(send_settings ? &settings : nullptr);
connection = &*pool_entry;
}
connection->sendQuery(query, "", stage, send_settings ? &settings : nullptr, true);
}
if (use_many_replicas)
shard_replicas->sendQuery(query, "", stage, &settings, true);
else
connection->sendQuery(query, "", stage, send_settings ? &settings : nullptr, true);
sendExternalTables();
sent_query = true;
}

View File

@ -1,12 +1,10 @@
#include <DB/Client/ShardReplicas.h>
#include <DB/Client/ConnectionPool.h>
namespace DB
{
ShardReplicas::ShardReplicas(IConnectionPool * pool_, Settings * settings_) :
ShardReplicas::ShardReplicas(std::vector<ConnectionPool::Entry> & entries, Settings * settings_) :
settings(settings_)
{
auto entries = pool_->getMany(settings);
valid_replicas_count = entries.size();
replica_hash.reserve(valid_replicas_count);