2018-12-28 17:26:10 +00:00
|
|
|
#pragma once
|
|
|
|
|
2020-02-14 14:28:33 +00:00
|
|
|
#include "CompressedReadBufferBase.h"
|
2020-02-18 12:24:20 +00:00
|
|
|
#include <IO/ReadBufferFromFileBase.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <memory>
|
2018-12-28 17:26:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2021-03-28 19:24:28 +00:00
|
|
|
class MMappedFileCache;
|
2021-03-28 01:10:30 +00:00
|
|
|
|
2018-12-28 17:26:10 +00:00
|
|
|
|
|
|
|
/// Unlike CompressedReadBuffer, it can do seek.
|
|
|
|
class CompressedReadBufferFromFile : public CompressedReadBufferBase, public BufferWithOwnMemory<ReadBuffer>
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
/** At any time, one of two things is true:
|
|
|
|
* a) size_compressed = 0
|
|
|
|
* b)
|
|
|
|
* - `working_buffer` contains the entire block.
|
|
|
|
* - `file_in` points to the end of this block.
|
|
|
|
* - `size_compressed` contains the compressed size of this block.
|
|
|
|
*/
|
|
|
|
std::unique_ptr<ReadBufferFromFileBase> p_file_in;
|
|
|
|
ReadBufferFromFileBase & file_in;
|
|
|
|
size_t size_compressed = 0;
|
|
|
|
|
|
|
|
bool nextImpl() override;
|
|
|
|
|
|
|
|
public:
|
2020-09-04 12:48:55 +00:00
|
|
|
CompressedReadBufferFromFile(std::unique_ptr<ReadBufferFromFileBase> buf, bool allow_different_codecs_ = false);
|
2020-02-14 14:28:33 +00:00
|
|
|
|
2018-12-28 17:26:10 +00:00
|
|
|
CompressedReadBufferFromFile(
|
2021-07-05 20:02:24 +00:00
|
|
|
const std::string & path, size_t estimated_size, size_t direct_io_threshold, size_t mmap_threshold, MMappedFileCache * mmap_cache,
|
2020-09-04 12:48:55 +00:00
|
|
|
size_t buf_size = DBMS_DEFAULT_BUFFER_SIZE, bool allow_different_codecs_ = false);
|
2018-12-28 17:26:10 +00:00
|
|
|
|
|
|
|
void seek(size_t offset_in_compressed_file, size_t offset_in_decompressed_block);
|
|
|
|
|
|
|
|
size_t readBig(char * to, size_t n) override;
|
|
|
|
|
|
|
|
void setProfileCallback(const ReadBufferFromFileBase::ProfileCallback & profile_callback_, clockid_t clock_type_ = CLOCK_MONOTONIC_COARSE)
|
|
|
|
{
|
|
|
|
file_in.setProfileCallback(profile_callback_, clock_type_);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|