2013-09-08 05:53:10 +00:00
|
|
|
#pragma once
|
|
|
|
|
2014-02-11 11:05:02 +00:00
|
|
|
#include <DB/Common/LRUCache.h>
|
2013-09-08 05:53:10 +00:00
|
|
|
#include <DB/Common/SipHash.h>
|
2014-01-03 08:20:13 +00:00
|
|
|
#include <DB/Common/ProfileEvents.h>
|
2013-09-08 05:53:10 +00:00
|
|
|
#include <DB/IO/BufferWithOwnMemory.h>
|
|
|
|
#include <DB/Interpreters/AggregationCommon.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
|
2014-02-11 11:05:02 +00:00
|
|
|
struct UncompressedCacheCell
|
2013-09-08 05:53:10 +00:00
|
|
|
{
|
2014-02-11 11:05:02 +00:00
|
|
|
Memory data;
|
|
|
|
size_t compressed_size;
|
|
|
|
};
|
2013-09-08 05:53:10 +00:00
|
|
|
|
|
|
|
|
2014-02-11 11:05:02 +00:00
|
|
|
/** Кэш разжатых блоков для CachedCompressedReadBuffer. thread-safe.
|
|
|
|
*/
|
|
|
|
class UncompressedCache : public LRUCache<UInt128, UncompressedCacheCell, UInt128TrivialHash>
|
|
|
|
{
|
2013-09-08 05:53:10 +00:00
|
|
|
private:
|
2014-02-11 11:05:02 +00:00
|
|
|
typedef LRUCache<UInt128, UncompressedCacheCell, UInt128TrivialHash> Base;
|
2013-09-08 05:53:10 +00:00
|
|
|
|
|
|
|
public:
|
2014-02-11 11:05:02 +00:00
|
|
|
UncompressedCache(size_t max_size_in_cells)
|
|
|
|
: Base(max_size_in_cells) {}
|
2013-09-08 05:53:10 +00:00
|
|
|
|
|
|
|
/// Посчитать ключ от пути к файлу и смещения.
|
|
|
|
static UInt128 hash(const String & path_to_file, size_t offset)
|
|
|
|
{
|
|
|
|
UInt128 key;
|
|
|
|
|
|
|
|
SipHash hash;
|
|
|
|
hash.update(path_to_file.data(), path_to_file.size() + 1);
|
|
|
|
hash.update(reinterpret_cast<const char *>(&offset), sizeof(offset));
|
|
|
|
hash.get128(key.first, key.second);
|
|
|
|
|
|
|
|
return key;
|
|
|
|
}
|
|
|
|
|
2014-02-11 11:05:02 +00:00
|
|
|
MappedPtr get(const Key & key)
|
2013-09-08 05:53:10 +00:00
|
|
|
{
|
2014-02-11 11:05:02 +00:00
|
|
|
MappedPtr res = Base::get(key);
|
2013-09-08 05:53:10 +00:00
|
|
|
|
2014-02-11 11:05:02 +00:00
|
|
|
if (res)
|
2014-01-03 08:20:13 +00:00
|
|
|
ProfileEvents::increment(ProfileEvents::UncompressedCacheHits);
|
2013-09-08 05:53:10 +00:00
|
|
|
else
|
2014-01-03 08:20:13 +00:00
|
|
|
ProfileEvents::increment(ProfileEvents::UncompressedCacheMisses);
|
2013-09-08 05:53:10 +00:00
|
|
|
|
2014-02-11 11:05:02 +00:00
|
|
|
return res;
|
2013-09-08 05:53:10 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef Poco::SharedPtr<UncompressedCache> UncompressedCachePtr;
|
|
|
|
|
|
|
|
}
|