Skip to content

Commit 6cba2da

Browse files
Merge pull request #10834 from ClickHouse/fix-msan-failure-cache-dictionary
Fix MSan failure in cache dictionary
2 parents 0e2d423 + d38e6b6 commit 6cba2da

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

src/Dictionaries/CacheDictionary.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,7 @@ void CacheDictionary::updateThreadFunction()
777777

778778
UpdateUnitPtr current_unit_ptr;
779779

780-
while (!update_request.empty() && update_queue.tryPop(current_unit_ptr))
780+
while (update_request.size() < current_queue_size + 1 && update_queue.tryPop(current_unit_ptr))
781781
update_request.emplace_back(std::move(current_unit_ptr));
782782

783783
BunchUpdateUnit bunch_update_unit(update_request);
@@ -817,7 +817,7 @@ void CacheDictionary::waitForCurrentUpdateFinish(UpdateUnitPtr & update_unit_ptr
817817
bool result = is_update_finished.wait_for(
818818
update_lock,
819819
std::chrono::milliseconds(timeout_for_wait),
820-
[&] {return update_unit_ptr->is_done || update_unit_ptr->current_exception; });
820+
[&] { return update_unit_ptr->is_done || update_unit_ptr->current_exception; });
821821

822822
if (!result)
823823
{
@@ -936,7 +936,6 @@ void CacheDictionary::update(BunchUpdateUnit & bunch_update_unit) const
936936
else
937937
cell.setExpiresAt(std::chrono::time_point<std::chrono::system_clock>::max());
938938

939-
940939
bunch_update_unit.informCallersAboutPresentId(id, cell_idx);
941940
/// mark corresponding id as found
942941
remaining_ids[id] = 1;
@@ -962,7 +961,8 @@ void CacheDictionary::update(BunchUpdateUnit & bunch_update_unit) const
962961
}
963962
}
964963

965-
size_t not_found_num = 0, found_num = 0;
964+
size_t not_found_num = 0;
965+
size_t found_num = 0;
966966

967967
/// Check which ids have not been found and require setting null_value
968968
for (const auto & id_found_pair : remaining_ids)

src/Dictionaries/CacheDictionary.inc.h

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,16 @@ template <typename AttributeType, typename OutputType, typename DefaultGetter>
3838
void CacheDictionary::getItemsNumberImpl(
3939
Attribute & attribute, const PaddedPODArray<Key> & ids, ResultArrayType<OutputType> & out, DefaultGetter && get_default) const
4040
{
41+
/// First fill everything with default values
42+
const auto rows = ext::size(ids);
43+
for (const auto row : ext::range(0, rows))
44+
out[row] = get_default(row);
45+
4146
/// Mapping: <id> -> { all indices `i` of `ids` such that `ids[i]` = <id> }
4247
std::unordered_map<Key, std::vector<size_t>> cache_expired_ids;
4348
std::unordered_map<Key, std::vector<size_t>> cache_not_found_ids;
4449

4550
auto & attribute_array = std::get<ContainerPtrType<AttributeType>>(attribute.arrays);
46-
const auto rows = ext::size(ids);
4751

4852
size_t cache_hit = 0;
4953

@@ -67,7 +71,8 @@ void CacheDictionary::getItemsNumberImpl(
6771
{
6872
const auto & cell_idx = find_result.cell_idx;
6973
const auto & cell = cells[cell_idx];
70-
out[row] = cell.isDefault() ? get_default(row) : static_cast<OutputType>(attribute_array[cell_idx]);
74+
if (!cell.isDefault())
75+
out[row] = static_cast<OutputType>(attribute_array[cell_idx]);
7176
};
7277

7378
if (!find_result.valid)
@@ -154,14 +159,7 @@ void CacheDictionary::getItemsNumberImpl(
154159
out[row] = static_cast<OutputType>(attribute_value);
155160
};
156161

157-
auto on_id_not_found = [&] (const auto id, const auto)
158-
{
159-
for (const size_t row : cache_not_found_ids[id])
160-
out[row] = get_default(row);
161-
162-
for (const size_t row : cache_expired_ids[id])
163-
out[row] = get_default(row);
164-
};
162+
auto on_id_not_found = [&] (auto, auto) {};
165163

166164
/// Request new values
167165
auto update_unit_ptr = std::make_shared<UpdateUnit>(required_ids, on_cell_updated, on_id_not_found);

0 commit comments

Comments
 (0)