2014-02-11 13:30:42 +00:00
|
|
|
#pragma once
|
|
|
|
|
2015-04-16 06:12:35 +00:00
|
|
|
#include <memory>
|
|
|
|
|
2014-02-11 13:30:42 +00:00
|
|
|
#include <DB/Common/LRUCache.h>
|
|
|
|
#include <DB/Common/ProfileEvents.h>
|
2014-02-16 21:14:41 +00:00
|
|
|
#include <DB/Common/SipHash.h>
|
|
|
|
#include <DB/Interpreters/AggregationCommon.h>
|
2015-08-16 07:01:41 +00:00
|
|
|
#include <DB/DataStreams/MarkInCompressedFile.h>
|
2014-02-11 13:30:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2015-08-16 07:01:41 +00:00
|
|
|
namespace DB
|
2014-02-11 13:30:42 +00:00
|
|
|
{
|
|
|
|
|
2015-04-13 15:02:39 +00:00
|
|
|
/// Оценка количества байтов, занимаемых засечками в кеше.
|
2014-02-11 13:30:42 +00:00
|
|
|
struct MarksWeightFunction
|
|
|
|
{
|
|
|
|
size_t operator()(const MarksInCompressedFile & marks) const
|
|
|
|
{
|
|
|
|
/// Можно еще добавить порядка 100 байт на накладные расходы вектора и кеша.
|
|
|
|
return marks.size() * sizeof(MarkInCompressedFile);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/** Кэш засечек в столбце из StorageMergeTree.
|
|
|
|
*/
|
2015-05-07 12:28:09 +00:00
|
|
|
class MarkCache : public LRUCache<UInt128, MarksInCompressedFile, UInt128TrivialHash, MarksWeightFunction>
|
2014-02-11 13:30:42 +00:00
|
|
|
{
|
|
|
|
private:
|
2016-05-28 10:35:44 +00:00
|
|
|
using Base = LRUCache<UInt128, MarksInCompressedFile, UInt128TrivialHash, MarksWeightFunction>;
|
2014-02-11 13:30:42 +00:00
|
|
|
|
|
|
|
public:
|
2015-05-07 10:31:50 +00:00
|
|
|
MarkCache(size_t max_size_in_bytes, const Delay & expiration_delay)
|
|
|
|
: Base(max_size_in_bytes, expiration_delay) {}
|
2014-02-11 13:30:42 +00:00
|
|
|
|
|
|
|
/// Посчитать ключ от пути к файлу и смещения.
|
|
|
|
static UInt128 hash(const String & path_to_file)
|
|
|
|
{
|
|
|
|
UInt128 key;
|
|
|
|
|
|
|
|
SipHash hash;
|
|
|
|
hash.update(path_to_file.data(), path_to_file.size() + 1);
|
|
|
|
hash.get128(key.first, key.second);
|
|
|
|
|
|
|
|
return key;
|
|
|
|
}
|
|
|
|
|
|
|
|
MappedPtr get(const Key & key)
|
|
|
|
{
|
|
|
|
MappedPtr res = Base::get(key);
|
|
|
|
|
|
|
|
if (res)
|
|
|
|
ProfileEvents::increment(ProfileEvents::MarkCacheHits);
|
|
|
|
else
|
|
|
|
ProfileEvents::increment(ProfileEvents::MarkCacheMisses);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-05-28 10:35:44 +00:00
|
|
|
using MarkCachePtr = std::shared_ptr<MarkCache>;
|
2014-02-11 13:30:42 +00:00
|
|
|
|
|
|
|
}
|