From 2a5f86b89043557cdcff0250b750e8e00d24c220 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Wed, 30 Mar 2016 22:03:25 +0300 Subject: [PATCH] Using maximum one connection to external source when updating cache dictionary [#METR-19576]. --- dbms/include/DB/Dictionaries/CacheDictionary.h | 6 +++--- dbms/include/DB/Dictionaries/ComplexKeyCacheDictionary.h | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/dbms/include/DB/Dictionaries/CacheDictionary.h b/dbms/include/DB/Dictionaries/CacheDictionary.h index 5f87aca3436..d75d0175a44 100644 --- a/dbms/include/DB/Dictionaries/CacheDictionary.h +++ b/dbms/include/DB/Dictionaries/CacheDictionary.h @@ -577,9 +577,6 @@ private: const std::vector & requested_ids, PresentIdHandler && on_cell_updated, AbsentIdHandler && on_id_not_found) const { - auto stream = source_ptr->loadIds(requested_ids); - stream->readPrefix(); - MapType remaining_ids{requested_ids.size()}; for (const auto id : requested_ids) remaining_ids.insert({ id, 0 }); @@ -591,6 +588,9 @@ private: const Poco::ScopedWriteRWLock write_lock{rw_lock}; + auto stream = source_ptr->loadIds(requested_ids); + stream->readPrefix(); + while (const auto block = stream->read()) { const auto id_column = typeid_cast *>(block.getByPosition(0).column.get()); diff --git a/dbms/include/DB/Dictionaries/ComplexKeyCacheDictionary.h b/dbms/include/DB/Dictionaries/ComplexKeyCacheDictionary.h index 888bd99a0ec..0bcf1551e9d 100644 --- a/dbms/include/DB/Dictionaries/ComplexKeyCacheDictionary.h +++ b/dbms/include/DB/Dictionaries/ComplexKeyCacheDictionary.h @@ -614,9 +614,6 @@ private: const std::vector & in_requested_rows, PresentKeyHandler && on_cell_updated, AbsentKeyHandler && on_key_not_found) const { - auto stream = source_ptr->loadKeys(in_key_columns, in_requested_rows); - stream->readPrefix(); - MapType remaining_keys{in_requested_rows.size()}; for (const auto row : in_requested_rows) remaining_keys.insert({ in_keys[row], false }); @@ -628,6 +625,9 @@ private: const Poco::ScopedWriteRWLock write_lock{rw_lock}; + auto stream = source_ptr->loadKeys(in_key_columns, in_requested_rows); + stream->readPrefix(); + const auto keys_size = dict_struct.key.value().size(); StringRefs keys(keys_size);