mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-26 09:32:01 +00:00
CachedCompressedReadBuffer fix cache usage
This commit is contained in:
parent
21ea7bf9ab
commit
608d37deed
@ -33,33 +33,27 @@ bool CachedCompressedReadBuffer::nextImpl()
|
||||
|
||||
/// Let's check for the presence of a decompressed block in the cache, grab the ownership of this block, if it exists.
|
||||
UInt128 key = cache->hash(path, file_pos);
|
||||
owned_cell = cache->get(key);
|
||||
|
||||
if (!owned_cell)
|
||||
owned_cell = cache->getOrSet(key, [&]()
|
||||
{
|
||||
/// If not, read it from the file.
|
||||
initInput();
|
||||
file_in->seek(file_pos, SEEK_SET);
|
||||
|
||||
owned_cell = std::make_shared<UncompressedCacheCell>();
|
||||
auto cell = std::make_shared<UncompressedCacheCell>();
|
||||
|
||||
size_t size_decompressed;
|
||||
size_t size_compressed_without_checksum;
|
||||
owned_cell->compressed_size = readCompressedData(size_decompressed, size_compressed_without_checksum, false);
|
||||
cell->compressed_size = readCompressedData(size_decompressed, size_compressed_without_checksum, false);
|
||||
|
||||
if (owned_cell->compressed_size)
|
||||
if (cell->compressed_size)
|
||||
{
|
||||
owned_cell->additional_bytes = codec->getAdditionalSizeAtTheEndOfBuffer();
|
||||
owned_cell->data.resize(size_decompressed + owned_cell->additional_bytes);
|
||||
decompressTo(owned_cell->data.data(), size_decompressed, size_compressed_without_checksum);
|
||||
|
||||
}
|
||||
|
||||
/// Put data into cache.
|
||||
/// NOTE: Even if we don't read anything (compressed_size == 0)
|
||||
/// because we can reuse this information and don't reopen file in future
|
||||
cache->set(key, owned_cell);
|
||||
}
|
||||
return cell;
|
||||
});
|
||||
|
||||
if (owned_cell->data.size() == 0)
|
||||
return false;
|
||||
|
@ -58,16 +58,16 @@ public:
|
||||
return key;
|
||||
}
|
||||
|
||||
MappedPtr get(const Key & key)
|
||||
template <typename LoadFunc>
|
||||
MappedPtr getOrSet(const Key & key, LoadFunc && load)
|
||||
{
|
||||
MappedPtr res = Base::get(key);
|
||||
|
||||
if (res)
|
||||
ProfileEvents::increment(ProfileEvents::UncompressedCacheHits);
|
||||
else
|
||||
auto result = Base::getOrSet(key, load);
|
||||
if (result.second)
|
||||
ProfileEvents::increment(ProfileEvents::UncompressedCacheMisses);
|
||||
else
|
||||
ProfileEvents::increment(ProfileEvents::UncompressedCacheHits);
|
||||
|
||||
return res;
|
||||
return result.first;
|
||||
}
|
||||
|
||||
private:
|
||||
|
Loading…
Reference in New Issue
Block a user