2013-09-08 05:53:10 +00:00
|
|
|
#pragma once
|
|
|
|
|
2015-12-13 04:52:13 +00:00
|
|
|
#include <memory>
|
2016-10-25 06:49:24 +00:00
|
|
|
#include <time.h>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <IO/createReadBufferFromFileBase.h>
|
|
|
|
#include <IO/CompressedReadBufferBase.h>
|
|
|
|
#include <IO/UncompressedCache.h>
|
2018-06-19 18:09:09 +00:00
|
|
|
#include <port/clock.h>
|
2013-09-08 05:53:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2016-01-12 02:42:18 +00:00
|
|
|
|
2017-05-28 14:29:40 +00:00
|
|
|
/** A buffer for reading from a compressed file using the cache of decompressed blocks.
|
|
|
|
* The external cache is passed as an argument to the constructor.
|
|
|
|
* Allows you to increase performance in cases where the same blocks are often read.
|
|
|
|
* Disadvantages:
|
|
|
|
* - in case you need to read a lot of data in a row, but of them only a part is cached, you have to do seek-and.
|
2013-09-08 05:53:10 +00:00
|
|
|
*/
|
2014-01-15 14:53:20 +00:00
|
|
|
class CachedCompressedReadBuffer : public CompressedReadBufferBase, public ReadBuffer
|
2013-09-08 05:53:10 +00:00
|
|
|
{
|
|
|
|
private:
|
2017-04-01 07:20:54 +00:00
|
|
|
const std::string path;
|
|
|
|
UncompressedCache * cache;
|
|
|
|
size_t buf_size;
|
|
|
|
size_t estimated_size;
|
|
|
|
size_t aio_threshold;
|
2013-09-08 05:53:10 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
std::unique_ptr<ReadBufferFromFileBase> file_in;
|
|
|
|
size_t file_pos;
|
2013-09-08 05:53:10 +00:00
|
|
|
|
2017-05-28 14:29:40 +00:00
|
|
|
/// A piece of data from the cache, or a piece of read data that we put into the cache.
|
2017-04-01 07:20:54 +00:00
|
|
|
UncompressedCache::MappedPtr owned_cell;
|
2013-09-08 05:53:10 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
void initInput();
|
|
|
|
bool nextImpl() override;
|
2015-12-13 04:52:13 +00:00
|
|
|
|
2017-05-28 14:29:40 +00:00
|
|
|
/// Passed into file_in.
|
2017-04-01 07:20:54 +00:00
|
|
|
ReadBufferFromFileBase::ProfileCallback profile_callback;
|
2018-06-04 19:22:27 +00:00
|
|
|
clockid_t clock_type {};
|
2015-12-13 04:52:13 +00:00
|
|
|
|
2013-09-08 05:53:10 +00:00
|
|
|
public:
|
2017-04-01 07:20:54 +00:00
|
|
|
CachedCompressedReadBuffer(
|
|
|
|
const std::string & path_, UncompressedCache * cache_, size_t estimated_size_, size_t aio_threshold_,
|
|
|
|
size_t buf_size_ = DBMS_DEFAULT_BUFFER_SIZE);
|
2013-12-23 04:16:59 +00:00
|
|
|
|
2015-12-13 04:52:13 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
void seek(size_t offset_in_compressed_file, size_t offset_in_decompressed_block);
|
2015-12-13 04:52:13 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
void setProfileCallback(const ReadBufferFromFileBase::ProfileCallback & profile_callback_, clockid_t clock_type_ = CLOCK_MONOTONIC_COARSE)
|
|
|
|
{
|
|
|
|
profile_callback = profile_callback_;
|
|
|
|
clock_type = clock_type_;
|
|
|
|
}
|
2013-09-08 05:53:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|