Release the lock earlier

This commit is contained in:
kssenii 2023-02-16 13:49:12 +01:00
parent bf1174d5af
commit b6c3694369
2 changed files with 6 additions and 1 deletions

View File

@ -676,8 +676,9 @@ bool FileCache::tryReserveImpl(
if (is_overflow())
return false;
for (auto & [_, current_locked_key] : locked)
for (auto it = locked.begin(); it != locked.end();)
{
auto & current_locked_key = it->second;
for (const auto & offset_to_delete : current_locked_key->delete_offsets)
{
auto * file_segment_metadata = current_locked_key->getKeyMetadata().getByOffset(offset_to_delete);
@ -685,6 +686,9 @@ bool FileCache::tryReserveImpl(
if (query_context)
query_context->remove(key, offset);
}
/// Do not hold the key lock longer than required.
it = locked.erase(it);
}
if (file_segment_for_reserve)

View File

@ -43,6 +43,7 @@ public:
const bool recache_on_query_limit_exceeded;
};
/// CacheGuard::Lock protects all priority queues.
class LockedQueryContext
{
public: