Resolves #750. Allow to load more than 16 external dictionaries. [#CLICKHOUSE-3]

This commit is contained in:
Vitaliy Lyudvichenko 2017-05-03 21:18:14 +03:00 committed by alexey-milovidov
parent 99c360b6c7
commit d504c5454a
2 changed files with 26 additions and 4 deletions

View File

@ -21,12 +21,13 @@ ODBCDictionarySource::ODBCDictionarySource(const DictionaryStructure & dict_stru
table{config.getString(config_prefix + ".table")},
where{config.getString(config_prefix + ".where", "")},
sample_block{sample_block},
pool{std::make_shared<Poco::Data::SessionPool>(
config.getString(config_prefix + ".connector", "ODBC"),
config.getString(config_prefix + ".connection_string"))},
query_builder{dict_struct, db, table, where, ExternalQueryBuilder::None}, /// NOTE Better to obtain quoting style via ODBC interface.
load_all_query{query_builder.composeLoadAllQuery()}
{
pool = createAndCheckResizePocoSessionPool([&] () { return std::make_shared<Poco::Data::SessionPool>(
config.getString(config_prefix + ".connector", "ODBC"),
config.getString(config_prefix + ".connection_string"));
});
}
/// copy-constructor is provided in order to support cloneability
@ -43,6 +44,21 @@ ODBCDictionarySource::ODBCDictionarySource(const ODBCDictionarySource & other)
{
}
std::shared_ptr<Poco::Data::SessionPool> ODBCDictionarySource::createAndCheckResizePocoSessionPool(PocoSessionPoolConstructor pool_constr)
{
static std::mutex mutex;
Poco::ThreadPool & pool = Poco::ThreadPool::defaultPool();
/// NOTE: The lock don't guarantee that external users of the pool don't change its capacity
std::unique_lock<std::mutex> lock(mutex);
if (pool.available() == 0)
pool.addCapacity(2 * std::max(pool.capacity(), 1));
return pool_constr();
}
BlockInputStreamPtr ODBCDictionarySource::loadAll()
{
LOG_TRACE(log, load_all_query);

View File

@ -59,9 +59,15 @@ private:
const std::string table;
const std::string where;
Block sample_block;
std::shared_ptr<Poco::Data::SessionPool> pool;
std::shared_ptr<Poco::Data::SessionPool> pool = nullptr;
ExternalQueryBuilder query_builder;
const std::string load_all_query;
using PocoSessionPoolConstructor = std::function<std::shared_ptr<Poco::Data::SessionPool>()>;
/// Is used to adjust max size of default Poco thread pool. See issue #750
/// Acquire the lock, resize pool and construct new Session
static std::shared_ptr<Poco::Data::SessionPool> createAndCheckResizePocoSessionPool(PocoSessionPoolConstructor pool_constr);
};