提交 d504c545 编写于 作者: V Vitaliy Lyudvichenko 提交者: alexey-milovidov

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

上级 99c360b6
......@@ -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);
......
......@@ -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);
};
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册