fix race + assert

This commit is contained in:
Nikita Mikhaylov 2020-01-28 16:09:30 +03:00
parent c0975b4031
commit 8cd434fb15

View File

@ -342,18 +342,19 @@ void CacheDictionary::prepareAnswer(
PresentIdHandler && on_cell_updated, PresentIdHandler && on_cell_updated,
AbsentIdHandler && on_id_not_found) const AbsentIdHandler && on_id_not_found) const
{ {
const ProfilingScopedWriteRWLock write_lock{rw_lock, ProfileEvents::DictCacheLockWriteNs};
/// Prepare answer /// Prepare answer
const auto now = std::chrono::system_clock::now(); const auto now = std::chrono::system_clock::now();
for (const auto & id : update_unit_ptr->requested_ids) for (const auto & id : update_unit_ptr->requested_ids)
{ {
const auto find_result = findCellIdx(id, now); const auto find_result = findCellIdx(id, now);
assert(find_result.valid);
const auto & cell_idx = find_result.cell_idx; const auto & cell_idx = find_result.cell_idx;
auto & cell = cells[cell_idx]; auto & cell = cells[cell_idx];
const auto was_id_updated = update_unit_ptr->found_ids_mask_ptr->at(id); const auto was_id_updated = update_unit_ptr->found_ids_mask_ptr->at(id);
const ProfilingScopedWriteRWLock write_lock{rw_lock, ProfileEvents::DictCacheLockWriteNs};
if (was_id_updated) if (was_id_updated)
{ {
on_cell_updated(id, find_result.cell_idx); on_cell_updated(id, find_result.cell_idx);