mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-10 09:32:06 +00:00
LRUCache fix exception unsafe element insertion
This commit is contained in:
parent
f1223e7548
commit
31b7734407
@ -271,17 +271,24 @@ private:
|
|||||||
|
|
||||||
void setImpl(const Key & key, const MappedPtr & mapped, [[maybe_unused]] std::lock_guard<std::mutex> & cache_lock)
|
void setImpl(const Key & key, const MappedPtr & mapped, [[maybe_unused]] std::lock_guard<std::mutex> & cache_lock)
|
||||||
{
|
{
|
||||||
auto res = cells.emplace(std::piecewise_construct,
|
auto [it, inserted] = cells.emplace(std::piecewise_construct,
|
||||||
std::forward_as_tuple(key),
|
std::forward_as_tuple(key),
|
||||||
std::forward_as_tuple());
|
std::forward_as_tuple());
|
||||||
|
|
||||||
Cell & cell = res.first->second;
|
Cell & cell = it->second;
|
||||||
bool inserted = res.second;
|
|
||||||
|
|
||||||
if (inserted)
|
if (inserted)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
cell.queue_iterator = queue.insert(queue.end(), key);
|
cell.queue_iterator = queue.insert(queue.end(), key);
|
||||||
}
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
cells.erase(it);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
current_size -= cell.size;
|
current_size -= cell.size;
|
||||||
|
Loading…
Reference in New Issue
Block a user