dbms: fix thread-unsafety: retain mysqlxx::Pool::Entry for the whole duration of a query. [#METR-13298]

This commit is contained in:
Andrey Mironov 2015-03-18 15:09:49 +03:00
parent 7f9e9da104
commit 3b3f5b17c4
2 changed files with 9 additions and 4 deletions

View File

@ -16,8 +16,12 @@ namespace DB
class MySQLBlockInputStream final : public IProfilingBlockInputStream
{
public:
MySQLBlockInputStream(mysqlxx::Query query, const Block & sample_block, const std::size_t max_block_size)
: query{std::move(query)}, result{this->query.use()}, sample_block{sample_block}, max_block_size{max_block_size}
MySQLBlockInputStream(const mysqlxx::PoolWithFailover::Entry & entry,
const std::string & query_str,
const Block & sample_block,
const std::size_t max_block_size)
: entry{entry}, query{this->entry->query(query_str)}, result{query.use()},
sample_block{sample_block}, max_block_size{max_block_size}
{
types.reserve(sample_block.columns());
@ -105,6 +109,7 @@ private:
}
}
mysqlxx::PoolWithFailover::Entry entry;
mysqlxx::Query query;
mysqlxx::UseQueryResult result;
Block sample_block;

View File

@ -36,7 +36,7 @@ public:
BlockInputStreamPtr loadAll() override
{
last_modification = getLastModification();
return new MySQLBlockInputStream{pool.Get()->query(load_all_query), sample_block, max_block_size};
return new MySQLBlockInputStream{pool.Get(), load_all_query, sample_block, max_block_size};
}
BlockInputStreamPtr loadIds(const std::vector<std::uint64_t> ids) override
@ -44,7 +44,7 @@ public:
last_modification = getLastModification();
const auto query = composeLoadIdsQuery(ids);
return new MySQLBlockInputStream{pool.Get()->query(query), sample_block, max_block_size};
return new MySQLBlockInputStream{pool.Get(), query, sample_block, max_block_size};
}
bool isModified() const override { return getLastModification() > last_modification; }